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 // Location of argument use inside the macro body
45 typedef std::pair<IdentifierInfo*, SourceLocation> MacroArgUse;
46 llvm::DenseMap<unsigned, SmallVector<MacroArgUse, 2>>
48 SmallVector<std::pair<SourceLocation, MacroArgUse>, 2>
49 CurrCommitMacroArgExps;
51 IdentifierTable IdentTable;
52 llvm::BumpPtrAllocator StrAlloc;
55 EditedSource(const SourceManager &SM, const LangOptions &LangOpts,
56 const PPConditionalDirectiveRecord *PPRec = nullptr)
57 : SourceMgr(SM), LangOpts(LangOpts), PPRec(PPRec), IdentTable(LangOpts),
60 const SourceManager &getSourceManager() const { return SourceMgr; }
61 const LangOptions &getLangOpts() const { return LangOpts; }
62 const PPConditionalDirectiveRecord *getPPCondDirectiveRecord() const {
66 bool canInsertInOffset(SourceLocation OrigLoc, FileOffset Offs);
68 bool commit(const Commit &commit);
70 void applyRewrites(EditsReceiver &receiver, bool adjustRemovals = true);
73 StringRef copyString(StringRef str) { return str.copy(StrAlloc); }
74 StringRef copyString(const Twine &twine);
77 bool commitInsert(SourceLocation OrigLoc, FileOffset Offs, StringRef text,
78 bool beforePreviousInsertions);
79 bool commitInsertFromRange(SourceLocation OrigLoc, FileOffset Offs,
80 FileOffset InsertFromRangeOffs, unsigned Len,
81 bool beforePreviousInsertions);
82 void commitRemove(SourceLocation OrigLoc, FileOffset BeginOffs, unsigned Len);
84 StringRef getSourceText(FileOffset BeginOffs, FileOffset EndOffs,
86 FileEditsTy::iterator getActionForOffset(FileOffset Offs);
87 void deconstructMacroArgLoc(SourceLocation Loc,
88 SourceLocation &ExpansionLoc,
91 void startingCommit();
92 void finishedCommit();
97 } // end namespace clang