Skip to content

Commit 6af5d3c

Browse files
committed
libSyntax: rename KeepTokensInSourceFile to KeepSyntaxInfoInSourceFile.
1 parent 4ee32a1 commit 6af5d3c

File tree

12 files changed

+29
-30
lines changed

12 files changed

+29
-30
lines changed

include/swift/AST/Module.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ class SourceFile final : public FileUnit {
891891
ASTStage_t ASTStage = Parsing;
892892

893893
SourceFile(ModuleDecl &M, SourceFileKind K, Optional<unsigned> bufferID,
894-
ImplicitModuleImportKind ModImpKind, bool KeepTokens);
894+
ImplicitModuleImportKind ModImpKind, bool KeepSyntaxInfo);
895895

896896
void
897897
addImports(ArrayRef<std::pair<ModuleDecl::ImportedModule, ImportOptions>> IM);
@@ -1080,7 +1080,7 @@ class SourceFile final : public FileUnit {
10801080

10811081
ArrayRef<Token> getAllTokens() const;
10821082

1083-
bool shouldKeepTokens() const;
1083+
bool shouldKeepSyntaxInfo() const;
10841084

10851085
syntax::SourceFileSyntax getSyntaxRoot() const;
10861086

include/swift/Basic/LangOptions.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,9 @@ namespace swift {
246246
/// This is used to guard preemptive testing for the fix-it.
247247
bool FixStringToSubstringConversions = false;
248248

249-
/// Whether to keep track of a refined token stream in SourceFile while
250-
/// parsing. This is set true usually for tooling purposes like semantic
251-
/// coloring.
252-
bool KeepTokensInSourceFile = false;
249+
/// Whether to create and keep track of a libSyntax tree associated with
250+
/// this source file.
251+
bool KeepSyntaxInfoInSourceFile = false;
253252

254253
/// Sets the target we are building for and updates platform conditions
255254
/// to match.

lib/AST/Module.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,7 @@ static void performAutoImport(
13461346
SourceFile::SourceFile(ModuleDecl &M, SourceFileKind K,
13471347
Optional<unsigned> bufferID,
13481348
ImplicitModuleImportKind ModImpKind,
1349-
bool KeepTokens)
1349+
bool KeepSyntaxInfo)
13501350
: FileUnit(FileUnitKind::Source, M),
13511351
BufferID(bufferID ? *bufferID : -1),
13521352
Kind(K), SyntaxInfo(*new SourceFileSyntaxInfo()) {
@@ -1358,24 +1358,24 @@ SourceFile::SourceFile(ModuleDecl &M, SourceFileKind K,
13581358
assert(!problem && "multiple main files?");
13591359
(void)problem;
13601360
}
1361-
if (KeepTokens) {
1361+
if (KeepSyntaxInfo) {
13621362
AllCorrectedTokens = std::vector<Token>();
13631363
}
13641364
}
13651365

13661366
SourceFile::~SourceFile() { delete &SyntaxInfo; }
13671367

13681368
std::vector<Token> &SourceFile::getTokenVector() {
1369-
assert(shouldKeepTokens() && "Disabled");
1369+
assert(shouldKeepSyntaxInfo() && "Disabled");
13701370
return *AllCorrectedTokens;
13711371
}
13721372

13731373
ArrayRef<Token> SourceFile::getAllTokens() const {
1374-
assert(shouldKeepTokens() && "Disabled");
1374+
assert(shouldKeepSyntaxInfo() && "Disabled");
13751375
return *AllCorrectedTokens;
13761376
}
13771377

1378-
bool SourceFile::shouldKeepTokens() const {
1378+
bool SourceFile::shouldKeepSyntaxInfo() const {
13791379
switch (Kind) {
13801380
case SourceFileKind::Library:
13811381
case SourceFileKind::Main:

lib/Frontend/Frontend.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ void CompilerInstance::createREPLFile(
391391
const ImplicitImports &implicitImports) const {
392392
auto *SingleInputFile = new (*Context) SourceFile(
393393
*MainModule, Invocation.getSourceFileKind(), None, implicitImports.kind,
394-
Invocation.getLangOptions().KeepTokensInSourceFile);
394+
Invocation.getLangOptions().KeepSyntaxInfoInSourceFile);
395395
MainModule->addFile(*SingleInputFile);
396396
addAdditionalInitialImportsTo(SingleInputFile, implicitImports);
397397
}
@@ -416,7 +416,7 @@ void CompilerInstance::addMainFileToModule(
416416

417417
auto *MainFile = new (*Context) SourceFile(
418418
*MainModule, Invocation.getSourceFileKind(), MainBufferID,
419-
implicitImports.kind, Invocation.getLangOptions().KeepTokensInSourceFile);
419+
implicitImports.kind, Invocation.getLangOptions().KeepSyntaxInfoInSourceFile);
420420
MainModule->addFile(*MainFile);
421421
addAdditionalInitialImportsTo(MainFile, implicitImports);
422422

@@ -484,7 +484,7 @@ void CompilerInstance::parseLibraryFile(
484484

485485
auto *NextInput = new (*Context) SourceFile(
486486
*MainModule, SourceFileKind::Library, BufferID, implicitImports.kind,
487-
Invocation.getLangOptions().KeepTokensInSourceFile);
487+
Invocation.getLangOptions().KeepSyntaxInfoInSourceFile);
488488
MainModule->addFile(*NextInput);
489489
addAdditionalInitialImportsTo(NextInput, implicitImports);
490490

@@ -639,7 +639,7 @@ void CompilerInstance::performParseOnly(bool EvaluateConditionals) {
639639
const InputFileKind Kind = Invocation.getInputKind();
640640
ModuleDecl *MainModule = getMainModule();
641641
Context->LoadedModules[MainModule->getName()] = MainModule;
642-
bool KeepTokens = Invocation.getLangOptions().KeepTokensInSourceFile;
642+
bool KeepSyntaxInfo = Invocation.getLangOptions().KeepSyntaxInfoInSourceFile;
643643

644644
assert((Kind == InputFileKind::IFK_Swift ||
645645
Kind == InputFileKind::IFK_Swift_Library) &&
@@ -656,7 +656,7 @@ void CompilerInstance::performParseOnly(bool EvaluateConditionals) {
656656

657657
auto *MainFile = new (*Context)
658658
SourceFile(*MainModule, Invocation.getSourceFileKind(), MainBufferID,
659-
implicitModuleImportKind, KeepTokens);
659+
implicitModuleImportKind, KeepSyntaxInfo);
660660
MainModule->addFile(*MainFile);
661661

662662
if (MainBufferID == PrimaryBufferID)
@@ -672,7 +672,7 @@ void CompilerInstance::performParseOnly(bool EvaluateConditionals) {
672672

673673
auto *NextInput = new (*Context)
674674
SourceFile(*MainModule, SourceFileKind::Library, BufferID,
675-
implicitModuleImportKind, KeepTokens);
675+
implicitModuleImportKind, KeepSyntaxInfo);
676676
MainModule->addFile(*NextInput);
677677
if (BufferID == PrimaryBufferID)
678678
setPrimarySourceFile(NextInput);

lib/Parse/Parser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ Parser::Parser(std::unique_ptr<Lexer> Lex, SourceFile &SF,
432432
SIL(SIL),
433433
CurDeclContext(&SF),
434434
Context(SF.getASTContext()),
435-
TokReceiver(SF.shouldKeepTokens() ?
435+
TokReceiver(SF.shouldKeepSyntaxInfo() ?
436436
new TokenRecorder(SF) :
437437
new ConsumeTokenReceiver()),
438438
SyntaxContext(new syntax::SyntaxParsingContextRoot(SF, L->getBufferID(), Tok)) {
@@ -912,7 +912,7 @@ struct ParserUnit::Implementation {
912912
*ModuleDecl::create(Ctx.getIdentifier(ModuleName), Ctx),
913913
SourceFileKind::Main, BufferID,
914914
SourceFile::ImplicitModuleImportKind::None,
915-
Opts.KeepTokensInSourceFile)) {
915+
Opts.KeepSyntaxInfoInSourceFile)) {
916916
}
917917
};
918918

lib/Sema/SourceLoader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ ModuleDecl *SourceLoader::loadModule(SourceLoc importLoc,
132132

133133
auto *importFile = new (Ctx) SourceFile(*importMod, SourceFileKind::Library,
134134
bufferID, implicitImportKind,
135-
Ctx.LangOpts.KeepTokensInSourceFile);
135+
Ctx.LangOpts.KeepSyntaxInfoInSourceFile);
136136
importMod->addFile(*importFile);
137137

138138
bool done;

lib/Syntax/SyntaxParsingContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ struct SyntaxParsingContext::ContextInfo {
7575

7676
public:
7777
ContextInfo(SourceFile &File, unsigned BufferID):
78-
Enabled(File.shouldKeepTokens()) {
78+
Enabled(File.shouldKeepSyntaxInfo()) {
7979
if (Enabled) {
8080
populateTokenSyntaxMap(File.getASTContext().LangOpts,
8181
File.getASTContext().SourceMgr,

tools/SourceKit/lib/SwiftLang/SwiftASTManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ bool SwiftASTManager::initCompilerInvocation(CompilerInvocation &Invocation,
420420
Invocation.setSerializedDiagnosticsPath(StringRef());
421421
Invocation.getLangOptions().AttachCommentsToDecls = true;
422422
Invocation.getLangOptions().DiagnosticsEditorMode = true;
423-
Invocation.getLangOptions().KeepTokensInSourceFile = true;
423+
Invocation.getLangOptions().KeepSyntaxInfoInSourceFile = true;
424424
auto &FrontendOpts = Invocation.getFrontendOptions();
425425
if (FrontendOpts.PlaygroundTransform) {
426426
// The playground instrumenter changes the AST in ways that disrupt the
@@ -812,7 +812,7 @@ ASTUnitRef ASTProducer::createASTUnit(SwiftASTManager::Implementation &MgrImpl,
812812

813813
CompilerInvocation Invocation;
814814
Opts.applyTo(Invocation);
815-
Invocation.getLangOptions().KeepTokensInSourceFile = true;
815+
Invocation.getLangOptions().KeepSyntaxInfoInSourceFile = true;
816816
for (auto &Content : Contents)
817817
Invocation.addInputBuffer(Content.Buffer.get());
818818

tools/driver/swift_format_main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class FormatterDocument {
5555
public:
5656
FormatterDocument(std::unique_ptr<llvm::MemoryBuffer> Buffer) {
5757
// Formatting logic requires tokens on source file.
58-
CompInv.getLangOptions().KeepTokensInSourceFile = true;
58+
CompInv.getLangOptions().KeepSyntaxInfoInSourceFile = true;
5959
updateCode(std::move(Buffer));
6060
}
6161

tools/swift-ide-test/swift-ide-test.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ static int doSyntaxColoring(const CompilerInvocation &InitInvok,
942942
PrintingDiagnosticConsumer PrintDiags;
943943
CI.addDiagnosticConsumer(&PrintDiags);
944944
Invocation.getLangOptions().Playground = Playground;
945-
Invocation.getLangOptions().KeepTokensInSourceFile = true;
945+
Invocation.getLangOptions().KeepSyntaxInfoInSourceFile = true;
946946
if (CI.setup(Invocation))
947947
return 1;
948948
if (!RunTypeChecker)
@@ -1153,7 +1153,7 @@ class StructureAnnotator : public ide::SyntaxModelWalker {
11531153
static int doStructureAnnotation(const CompilerInvocation &InitInvok,
11541154
StringRef SourceFilename) {
11551155
CompilerInvocation Invocation(InitInvok);
1156-
Invocation.getLangOptions().KeepTokensInSourceFile = true;
1156+
Invocation.getLangOptions().KeepSyntaxInfoInSourceFile = true;
11571157
Invocation.addInputFilename(SourceFilename);
11581158

11591159
CompilerInstance CI;
@@ -2670,7 +2670,7 @@ static int doPrintRangeInfo(const CompilerInvocation &InitInvok,
26702670
CompilerInvocation Invocation(InitInvok);
26712671
Invocation.addInputFilename(SourceFileName);
26722672
Invocation.getLangOptions().DisableAvailabilityChecking = false;
2673-
Invocation.getLangOptions().KeepTokensInSourceFile = true;
2673+
Invocation.getLangOptions().KeepSyntaxInfoInSourceFile = true;
26742674

26752675
CompilerInstance CI;
26762676

@@ -2991,7 +2991,7 @@ int main(int argc, char *argv[]) {
29912991
InitInvok.setModuleName(options::ModuleName);
29922992

29932993
InitInvok.setSDKPath(options::SDK);
2994-
InitInvok.getLangOptions().KeepTokensInSourceFile = true;
2994+
InitInvok.getLangOptions().KeepSyntaxInfoInSourceFile = true;
29952995
if (!options::Triple.empty())
29962996
InitInvok.setTargetTriple(options::Triple);
29972997
if (!options::SwiftVersion.empty()) {

tools/swift-refactor/swift-refactor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ int main(int argc, char *argv[]) {
229229
reinterpret_cast<void *>(&anchorForGetMainExecutable)));
230230
Invocation.addInputFilename(options::SourceFilename);
231231
Invocation.getLangOptions().AttachCommentsToDecls = true;
232-
Invocation.getLangOptions().KeepTokensInSourceFile = true;
232+
Invocation.getLangOptions().KeepSyntaxInfoInSourceFile = true;
233233

234234
for (auto FileName : options::InputFilenames)
235235
Invocation.addInputFilename(FileName);

tools/swift-syntax-test/swift-syntax-test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ SourceFile *getSourceFile(CompilerInstance &Instance,
128128
StringRef InputFileName,
129129
const char *MainExecutablePath) {
130130
CompilerInvocation Invocation;
131-
Invocation.getLangOptions().KeepTokensInSourceFile = true;
131+
Invocation.getLangOptions().KeepSyntaxInfoInSourceFile = true;
132132
Invocation.addInputFilename(InputFileName);
133133
Invocation.setMainExecutablePath(
134134
llvm::sys::fs::getMainExecutable(MainExecutablePath,

0 commit comments

Comments
 (0)