@@ -32,8 +32,6 @@ class SourceFile final : public FileUnit {
32
32
friend class ParseSourceFileRequest ;
33
33
34
34
public:
35
- struct SourceFileSyntaxInfo ;
36
-
37
35
// / Possible attributes for imports in source files.
38
36
enum class ImportFlags {
39
37
// / The imported module is exposed to anyone who imports the parent module.
@@ -107,15 +105,27 @@ class SourceFile final : public FileUnit {
107
105
// / decl.
108
106
// /
109
107
// / FIXME: When condition evaluation moves to a later phase, remove this
110
- // / and adjust the client call 'performParseOnly' .
108
+ // / and the associated language option .
111
109
DisablePoundIfEvaluation = 1 << 1 ,
112
110
111
+ // / Whether to build a syntax tree.
112
+ BuildSyntaxTree = 1 << 2 ,
113
+
114
+ // / Whether to save the file's parsed tokens.
115
+ CollectParsedTokens = 1 << 3 ,
116
+
117
+ // / Whether to compute the interface hash of the file.
118
+ EnableInterfaceHash = 1 << 4 ,
119
+
113
120
// / Whether to suppress warnings when parsing. This is set for secondary
114
121
// / files, as they get parsed multiple times.
115
- SuppressWarnings = 1 << 2
122
+ SuppressWarnings = 1 << 5 ,
116
123
};
117
124
using ParsingOptions = OptionSet<ParsingFlags>;
118
125
126
+ // / Retrieve the parsing options specified in the LangOptions.
127
+ static ParsingOptions getDefaultParsingOptions (const LangOptions &langOpts);
128
+
119
129
private:
120
130
std::unique_ptr<SourceLookupCache> Cache;
121
131
SourceLookupCache &getCache () const ;
@@ -313,7 +323,6 @@ class SourceFile final : public FileUnit {
313
323
llvm::StringMap<SourceFilePathInfo> getInfoForUsedFilePaths () const ;
314
324
315
325
SourceFile (ModuleDecl &M, SourceFileKind K, Optional<unsigned > bufferID,
316
- bool KeepParsedTokens = false , bool KeepSyntaxTree = false ,
317
326
ParsingOptions parsingOpts = {}, bool isPrimary = false );
318
327
319
328
~SourceFile ();
@@ -481,7 +490,7 @@ class SourceFile final : public FileUnit {
481
490
}
482
491
483
492
SWIFT_DEBUG_DUMP;
484
- void dump (raw_ostream &os) const ;
493
+ void dump (raw_ostream &os, bool parseIfNeeded = false ) const ;
485
494
486
495
// / Pretty-print the contents of this source file.
487
496
// /
@@ -544,50 +553,35 @@ class SourceFile final : public FileUnit {
544
553
// / Set the root refinement context for the file.
545
554
void setTypeRefinementContext (TypeRefinementContext *TRC);
546
555
547
- void enableInterfaceHash () {
548
- assert (!hasInterfaceHash ());
549
- InterfaceHash.emplace ();
550
- }
551
-
556
+ // / Whether this file has an interface hash available.
552
557
bool hasInterfaceHash () const {
553
- return InterfaceHash. hasValue ( );
558
+ return ParsingOpts. contains (ParsingFlags::EnableInterfaceHash );
554
559
}
555
560
556
- NullablePtr<llvm::MD5> getInterfaceHashPtr () {
557
- return InterfaceHash ? InterfaceHash.getPointer () : nullptr ;
558
- }
559
-
560
- void getInterfaceHash (llvm::SmallString<32 > &str) const {
561
- // Copy to preserve idempotence.
562
- llvm::MD5 md5 = *InterfaceHash;
563
- llvm::MD5::MD5Result result;
564
- md5.final (result);
565
- llvm::MD5::stringifyResult (result, str);
566
- }
561
+ // / Output this file's interface hash into the provided string buffer.
562
+ void getInterfaceHash (llvm::SmallString<32 > &str) const ;
567
563
568
564
void dumpInterfaceHash (llvm::raw_ostream &out) {
569
565
llvm::SmallString<32 > str;
570
566
getInterfaceHash (str);
571
567
out << str << ' \n ' ;
572
568
}
573
569
574
- std::vector<Token> & getTokenVector ();
575
-
570
+ // / If this source file has been told to collect its parsed tokens, retrieve
571
+ // / those tokens.
576
572
ArrayRef<Token> getAllTokens () const ;
577
573
578
- bool shouldCollectToken () const ;
574
+ // / Whether the parsed tokens of this source file should be saved, allowing
575
+ // / them to be accessed from \c getAllTokens.
576
+ bool shouldCollectTokens () const ;
579
577
580
578
bool shouldBuildSyntaxTree () const ;
581
579
582
- bool canBeParsedInFull () const ;
583
-
584
580
// / Whether the bodies of types and functions within this file can be lazily
585
581
// / parsed.
586
582
bool hasDelayedBodyParsing () const ;
587
583
588
584
syntax::SourceFileSyntax getSyntaxRoot () const ;
589
- void setSyntaxRoot (syntax::SourceFileSyntax &&Root);
590
- bool hasSyntaxRoot () const ;
591
585
592
586
OpaqueTypeDecl *lookupOpaqueResultType (StringRef MangledName) override ;
593
587
@@ -602,10 +596,12 @@ class SourceFile final : public FileUnit {
602
596
603
597
private:
604
598
605
- // / If not None, the underlying vector should contain tokens of this source file.
606
- Optional<std::vector<Token>> AllCorrectedTokens;
599
+ // / If not \c None, the underlying vector contains the parsed tokens of this
600
+ // / source file.
601
+ Optional<ArrayRef<Token>> AllCollectedTokens;
607
602
608
- std::unique_ptr<SourceFileSyntaxInfo> SyntaxInfo;
603
+ // / The root of the syntax tree representing the source file.
604
+ std::unique_ptr<syntax::SourceFileSyntax> SyntaxRoot;
609
605
};
610
606
611
607
inline SourceFile::ParsingOptions operator |(SourceFile::ParsingFlags lhs,
0 commit comments