@@ -990,12 +990,12 @@ getFileOutputStream(StringRef OutputFilename, ASTContext &Ctx) {
990
990
}
991
991
992
992
// / Writes the Syntax tree to the given file
993
- static bool emitSyntax (SourceFile * SF, StringRef OutputFilename) {
994
- auto os = getFileOutputStream (OutputFilename, SF-> getASTContext ());
993
+ static bool emitSyntax (SourceFile & SF, StringRef OutputFilename) {
994
+ auto os = getFileOutputStream (OutputFilename, SF. getASTContext ());
995
995
if (!os) return true ;
996
996
997
997
json::Output jsonOut (*os, /* UserInfo=*/ {}, /* PrettyPrint=*/ false );
998
- auto Root = SF-> getSyntaxRoot ().getRaw ();
998
+ auto Root = SF. getSyntaxRoot ().getRaw ();
999
999
jsonOut << *Root;
1000
1000
*os << " \n " ;
1001
1001
return false ;
@@ -1323,9 +1323,9 @@ static void verifyGenericSignaturesIfNeeded(const CompilerInvocation &Invocation
1323
1323
}
1324
1324
1325
1325
static bool dumpAndPrintScopeMap (const CompilerInstance &Instance,
1326
- SourceFile * SF) {
1326
+ SourceFile & SF) {
1327
1327
// Not const because may require reexpansion
1328
- ASTScope &scope = SF-> getScope ();
1328
+ ASTScope &scope = SF. getScope ();
1329
1329
1330
1330
const auto &opts = Instance.getInvocation ().getFrontendOptions ();
1331
1331
if (opts.DumpScopeMapLocations .empty ()) {
@@ -1342,14 +1342,12 @@ static bool dumpAndPrintScopeMap(const CompilerInstance &Instance,
1342
1342
return Instance.getASTContext ().hadError ();
1343
1343
}
1344
1344
1345
- static SourceFile *
1345
+ static SourceFile &
1346
1346
getPrimaryOrMainSourceFile (const CompilerInstance &Instance) {
1347
- SourceFile *SF = Instance.getPrimarySourceFile ();
1348
- if (!SF) {
1349
- SourceFileKind Kind = Instance.getInvocation ().getSourceFileKind ();
1350
- SF = &Instance.getMainModule ()->getMainSourceFile (Kind);
1347
+ if (SourceFile *SF = Instance.getPrimarySourceFile ()) {
1348
+ return *SF;
1351
1349
}
1352
- return SF ;
1350
+ return Instance. getMainModule ()-> getMainSourceFile () ;
1353
1351
}
1354
1352
1355
1353
// / Dumps the AST of all available primary source files. If corresponding output
@@ -1366,8 +1364,8 @@ static bool dumpAST(CompilerInstance &Instance) {
1366
1364
} else {
1367
1365
// Some invocations don't have primary files. In that case, we default to
1368
1366
// looking for the main file and dumping it to `stdout`.
1369
- auto * SF = getPrimaryOrMainSourceFile (Instance);
1370
- SF-> dump (llvm::outs (), /* parseIfNeeded*/ true );
1367
+ auto & SF = getPrimaryOrMainSourceFile (Instance);
1368
+ SF. dump (llvm::outs (), /* parseIfNeeded*/ true );
1371
1369
}
1372
1370
return Instance.getASTContext ().hadError ();
1373
1371
}
@@ -1902,7 +1900,7 @@ static bool performAction(CompilerInstance &Instance,
1902
1900
case FrontendOptions::ActionType::PrintAST:
1903
1901
return withSemanticAnalysis (
1904
1902
Instance, observer, [](CompilerInstance &Instance) {
1905
- getPrimaryOrMainSourceFile (Instance)-> print (
1903
+ getPrimaryOrMainSourceFile (Instance). print (
1906
1904
llvm::outs (), PrintOptions::printEverything ());
1907
1905
return Instance.getASTContext ().hadError ();
1908
1906
});
@@ -1915,13 +1913,12 @@ static bool performAction(CompilerInstance &Instance,
1915
1913
case FrontendOptions::ActionType::DumpTypeRefinementContexts:
1916
1914
return withSemanticAnalysis (
1917
1915
Instance, observer, [](CompilerInstance &Instance) {
1918
- getPrimaryOrMainSourceFile (Instance)
1919
- ->getTypeRefinementContext ()
1920
- ->dump (llvm::errs (), Instance.getASTContext ().SourceMgr );
1916
+ getPrimaryOrMainSourceFile (Instance).getTypeRefinementContext ()->dump (
1917
+ llvm::errs (), Instance.getASTContext ().SourceMgr );
1921
1918
return Instance.getASTContext ().hadError ();
1922
1919
});
1923
1920
case FrontendOptions::ActionType::DumpInterfaceHash:
1924
- getPrimaryOrMainSourceFile (Instance)-> dumpInterfaceHash (llvm::errs ());
1921
+ getPrimaryOrMainSourceFile (Instance). dumpInterfaceHash (llvm::errs ());
1925
1922
return Context.hadError ();
1926
1923
case FrontendOptions::ActionType::EmitSyntax:
1927
1924
return emitSyntax (getPrimaryOrMainSourceFile (Instance),
0 commit comments