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;
31 const bool ForceCommitInSystemHeader;
37 FileEdit() : RemoveLen(0) {}
40 typedef std::map<FileOffset, FileEdit> FileEditsTy;
41 FileEditsTy FileEdits;
43 llvm::DenseMap<unsigned, SourceLocation> ExpansionToArgMap;
45 llvm::BumpPtrAllocator StrAlloc;
48 EditedSource(const SourceManager &SM, const LangOptions &LangOpts,
49 const PPConditionalDirectiveRecord *PPRec = 0,
50 const bool FCommitInSystemHeader = true)
51 : SourceMgr(SM), LangOpts(LangOpts), PPRec(PPRec),
52 ForceCommitInSystemHeader(FCommitInSystemHeader),
53 StrAlloc(/*size=*/512) { }
55 const SourceManager &getSourceManager() const { return SourceMgr; }
56 const LangOptions &getLangOpts() const { return LangOpts; }
57 const PPConditionalDirectiveRecord *getPPCondDirectiveRecord() const {
61 bool getForceCommitInSystemHeader() const {
62 return ForceCommitInSystemHeader;
65 bool canInsertInOffset(SourceLocation OrigLoc, FileOffset Offs);
67 bool commit(const Commit &commit);
69 void applyRewrites(EditsReceiver &receiver);
72 StringRef copyString(StringRef str) {
73 char *buf = StrAlloc.Allocate<char>(str.size());
74 std::memcpy(buf, str.data(), str.size());
75 return StringRef(buf, str.size());
77 StringRef copyString(const Twine &twine);
80 bool commitInsert(SourceLocation OrigLoc, FileOffset Offs, StringRef text,
81 bool beforePreviousInsertions);
82 bool commitInsertFromRange(SourceLocation OrigLoc, FileOffset Offs,
83 FileOffset InsertFromRangeOffs, unsigned Len,
84 bool beforePreviousInsertions);
85 void commitRemove(SourceLocation OrigLoc, FileOffset BeginOffs, unsigned Len);
87 StringRef getSourceText(FileOffset BeginOffs, FileOffset EndOffs,
89 FileEditsTy::iterator getActionForOffset(FileOffset Offs);
94 } // end namespace clang