1 //===----- EditedSource.h - Collection of source edits ----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_CLANG_EDIT_EDITEDSOURCE_H
11 #define LLVM_CLANG_EDIT_EDITEDSOURCE_H
13 #include "clang/Edit/FileOffset.h"
14 #include "llvm/ADT/DenseMap.h"
15 #include "llvm/ADT/StringRef.h"
16 #include "llvm/Support/Allocator.h"
21 class PPConditionalDirectiveRecord;
28 const SourceManager &SourceMgr;
29 const LangOptions &LangOpts;
30 const PPConditionalDirectiveRecord *PPRec;
36 FileEdit() : RemoveLen(0) {}
39 typedef std::map<FileOffset, FileEdit> FileEditsTy;
40 FileEditsTy FileEdits;
42 llvm::DenseMap<unsigned, SourceLocation> ExpansionToArgMap;
44 llvm::BumpPtrAllocator StrAlloc;
47 EditedSource(const SourceManager &SM, const LangOptions &LangOpts,
48 const PPConditionalDirectiveRecord *PPRec = 0)
49 : SourceMgr(SM), LangOpts(LangOpts), PPRec(PPRec),
50 StrAlloc(/*size=*/512) { }
52 const SourceManager &getSourceManager() const { return SourceMgr; }
53 const LangOptions &getLangOpts() const { return LangOpts; }
54 const PPConditionalDirectiveRecord *getPPCondDirectiveRecord() const {
58 bool canInsertInOffset(SourceLocation OrigLoc, FileOffset Offs);
60 bool commit(const Commit &commit);
62 void applyRewrites(EditsReceiver &receiver);
65 StringRef copyString(StringRef str) {
66 char *buf = StrAlloc.Allocate<char>(str.size());
67 std::memcpy(buf, str.data(), str.size());
68 return StringRef(buf, str.size());
70 StringRef copyString(const Twine &twine);
73 bool commitInsert(SourceLocation OrigLoc, FileOffset Offs, StringRef text,
74 bool beforePreviousInsertions);
75 bool commitInsertFromRange(SourceLocation OrigLoc, FileOffset Offs,
76 FileOffset InsertFromRangeOffs, unsigned Len,
77 bool beforePreviousInsertions);
78 void commitRemove(SourceLocation OrigLoc, FileOffset BeginOffs, unsigned Len);
80 StringRef getSourceText(FileOffset BeginOffs, FileOffset EndOffs,
82 FileEditsTy::iterator getActionForOffset(FileOffset Offs);
87 } // end namespace clang