@@ -108,6 +108,12 @@ OldSyntaxTreeFilename("old-syntax-tree-filename",
108
108
llvm::cl::desc (" Path to the serialized syntax tree of "
109
109
" the pre-edit file" ));
110
110
111
+ static llvm::cl::opt<std::string>
112
+ OldSourceFilename (" old-source-filename" ,
113
+ llvm::cl::desc (" Path to the pre-edit source file to "
114
+ " translate line:column edits into the "
115
+ " file's byte offsets" ));
116
+
111
117
static llvm::cl::list<std::string>
112
118
IncrementalEdits (" incremental-edit" ,
113
119
llvm::cl::desc (" An edit that was applied to reach the input "
@@ -197,8 +203,17 @@ getTokensFromFile(const StringRef InputFilename,
197
203
void anchorForGetMainExecutable () {}
198
204
199
205
bool parseIncrementalEditArguments (SyntaxParsingCache *Cache,
200
- SourceManager &SourceMgr,
201
- unsigned BufferID) {
206
+ StringRef OldFileName) {
207
+ // Get a source manager for the old file
208
+ InputFile OldFile = InputFile (OldFileName, true );
209
+ auto OldFileBufferOrErrror = llvm::MemoryBuffer::getFileOrSTDIN (OldFileName);
210
+ if (!OldFileBufferOrErrror) {
211
+ llvm::errs () << " Unable to open old source file" ;
212
+ return false ;
213
+ }
214
+ SourceManager SourceMgr;
215
+ unsigned BufferID = SourceMgr.addNewSourceBuffer (std::move (OldFileBufferOrErrror.get ()));
216
+
202
217
// Parse the source edits
203
218
for (auto EditPattern : options::IncrementalEdits) {
204
219
llvm::Regex MatchRegex (" ([0-9]+):([0-9]+)-([0-9]+):([0-9]+)=(.*)" );
@@ -330,6 +345,16 @@ int parseFile(const char *MainExecutablePath, const StringRef InputFileName,
330
345
SyntaxCache = new SyntaxParsingCache (OldSyntaxTree.getValue ());
331
346
332
347
SyntaxCache->recordReuseInformation ();
348
+
349
+ if (options::OldSourceFilename.empty ()) {
350
+ llvm::errs () << " The old syntax file must be provided to translate "
351
+ " line:column edits to byte offsets" ;
352
+ return EXIT_FAILURE;
353
+ }
354
+ if (!parseIncrementalEditArguments (SyntaxCache,
355
+ options::OldSourceFilename)) {
356
+ return EXIT_FAILURE;
357
+ }
333
358
}
334
359
335
360
// Set up the compiler invocation
@@ -356,13 +381,6 @@ int parseFile(const char *MainExecutablePath, const StringRef InputFileName,
356
381
assert (BufferIDs.size () == 1 && " Only expecting to process one source file" );
357
382
unsigned BufferID = BufferIDs.front ();
358
383
359
- if (SyntaxCache) {
360
- if (!parseIncrementalEditArguments (SyntaxCache, Instance.getSourceMgr (),
361
- BufferID)) {
362
- return EXIT_FAILURE;
363
- }
364
- }
365
-
366
384
// Parse the actual source file
367
385
Instance.performParseOnly ();
368
386
0 commit comments