blob: f95b79785fafe2d10e1e6c3f7c92cde84a884efa [file] [log] [blame]
//===----- EditedSource.h - Collection of source edits ----------*- C++ -*-===//
// The LLVM Compiler Infrastructure
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
#include "clang/Edit/FileOffset.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Allocator.h"
#include <map>
namespace clang {
class LangOptions;
class PPConditionalDirectiveRecord;
namespace edit {
class Commit;
class EditsReceiver;
class EditedSource {
const SourceManager &SourceMgr;
const LangOptions &LangOpts;
const PPConditionalDirectiveRecord *PPRec;
const bool ForceCommitInSystemHeader;
struct FileEdit {
StringRef Text;
unsigned RemoveLen;
FileEdit() : RemoveLen(0) {}
typedef std::map<FileOffset, FileEdit> FileEditsTy;
FileEditsTy FileEdits;
llvm::DenseMap<unsigned, SourceLocation> ExpansionToArgMap;
llvm::BumpPtrAllocator StrAlloc;
EditedSource(const SourceManager &SM, const LangOptions &LangOpts,
const PPConditionalDirectiveRecord *PPRec = 0,
const bool FCommitInSystemHeader = true)
: SourceMgr(SM), LangOpts(LangOpts), PPRec(PPRec),
StrAlloc() { }
const SourceManager &getSourceManager() const { return SourceMgr; }
const LangOptions &getLangOpts() const { return LangOpts; }
const PPConditionalDirectiveRecord *getPPCondDirectiveRecord() const {
return PPRec;
bool getForceCommitInSystemHeader() const {
return ForceCommitInSystemHeader;
bool canInsertInOffset(SourceLocation OrigLoc, FileOffset Offs);
bool commit(const Commit &commit);
void applyRewrites(EditsReceiver &receiver);
void clearRewrites();
StringRef copyString(StringRef str) {
char *buf = StrAlloc.Allocate<char>(str.size());
std::memcpy(buf,, str.size());
return StringRef(buf, str.size());
StringRef copyString(const Twine &twine);
bool commitInsert(SourceLocation OrigLoc, FileOffset Offs, StringRef text,
bool beforePreviousInsertions);
bool commitInsertFromRange(SourceLocation OrigLoc, FileOffset Offs,
FileOffset InsertFromRangeOffs, unsigned Len,
bool beforePreviousInsertions);
void commitRemove(SourceLocation OrigLoc, FileOffset BeginOffs, unsigned Len);
StringRef getSourceText(FileOffset BeginOffs, FileOffset EndOffs,
bool &Invalid);
FileEditsTy::iterator getActionForOffset(FileOffset Offs);
} // end namespace clang