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/Basic/IdentifierTable.h"
14 #include "clang/Edit/FileOffset.h"
15 #include "llvm/ADT/DenseMap.h"
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/ADT/TinyPtrVector.h"
18 #include "llvm/Support/Allocator.h"
23 class PPConditionalDirectiveRecord;
30 const SourceManager &SourceMgr;
31 const LangOptions &LangOpts;
32 const PPConditionalDirectiveRecord *PPRec;
38 FileEdit() : RemoveLen(0) {}
41 typedef std::map<FileOffset, FileEdit> FileEditsTy;
42 FileEditsTy FileEdits;
44 llvm::DenseMap<unsigned, llvm::TinyPtrVector<IdentifierInfo*>>
46 SmallVector<std::pair<SourceLocation, IdentifierInfo*>, 2>
47 CurrCommitMacroArgExps;
49 IdentifierTable IdentTable;
50 llvm::BumpPtrAllocator StrAlloc;
53 EditedSource(const SourceManager &SM, const LangOptions &LangOpts,
54 const PPConditionalDirectiveRecord *PPRec = nullptr)
55 : SourceMgr(SM), LangOpts(LangOpts), PPRec(PPRec), IdentTable(LangOpts),
58 const SourceManager &getSourceManager() const { return SourceMgr; }
59 const LangOptions &getLangOpts() const { return LangOpts; }
60 const PPConditionalDirectiveRecord *getPPCondDirectiveRecord() const {
64 bool canInsertInOffset(SourceLocation OrigLoc, FileOffset Offs);
66 bool commit(const Commit &commit);
68 void applyRewrites(EditsReceiver &receiver, bool adjustRemovals = true);
71 StringRef copyString(StringRef str) { return str.copy(StrAlloc); }
72 StringRef copyString(const Twine &twine);
75 bool commitInsert(SourceLocation OrigLoc, FileOffset Offs, StringRef text,
76 bool beforePreviousInsertions);
77 bool commitInsertFromRange(SourceLocation OrigLoc, FileOffset Offs,
78 FileOffset InsertFromRangeOffs, unsigned Len,
79 bool beforePreviousInsertions);
80 void commitRemove(SourceLocation OrigLoc, FileOffset BeginOffs, unsigned Len);
82 StringRef getSourceText(FileOffset BeginOffs, FileOffset EndOffs,
84 FileEditsTy::iterator getActionForOffset(FileOffset Offs);
85 void deconstructMacroArgLoc(SourceLocation Loc,
86 SourceLocation &ExpansionLoc,
89 void startingCommit();
90 void finishedCommit();
95 } // end namespace clang