@@ -32,8 +32,6 @@ class SourceFile final : public FileUnit {
3232 friend class ParseSourceFileRequest ;
3333
3434public:
35- struct SourceFileSyntaxInfo ;
36-
3735 // / Possible attributes for imports in source files.
3836 enum class ImportFlags {
3937 // / The imported module is exposed to anyone who imports the parent module.
@@ -110,12 +108,24 @@ class SourceFile final : public FileUnit {
110108 // / and adjust the client call 'performParseOnly'.
111109 DisablePoundIfEvaluation = 1 << 1 ,
112110
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+
113120 // / Whether to suppress warnings when parsing. This is set for secondary
114121 // / files, as they get parsed multiple times.
115- SuppressWarnings = 1 << 2
122+ SuppressWarnings = 1 << 5 ,
116123 };
117124 using ParsingOptions = OptionSet<ParsingFlags>;
118125
126+ // / Retrieve the parsing options specified in the LangOptions.
127+ static ParsingOptions getDefaultParsingOptions (const LangOptions &langOpts);
128+
119129private:
120130 std::unique_ptr<SourceLookupCache> Cache;
121131 SourceLookupCache &getCache () const ;
@@ -313,7 +323,6 @@ class SourceFile final : public FileUnit {
313323 llvm::StringMap<SourceFilePathInfo> getInfoForUsedFilePaths () const ;
314324
315325 SourceFile (ModuleDecl &M, SourceFileKind K, Optional<unsigned > bufferID,
316- bool KeepParsedTokens = false , bool KeepSyntaxTree = false ,
317326 ParsingOptions parsingOpts = {}, bool isPrimary = false );
318327
319328 ~SourceFile ();
@@ -544,50 +553,35 @@ class SourceFile final : public FileUnit {
544553 // / Set the root refinement context for the file.
545554 void setTypeRefinementContext (TypeRefinementContext *TRC);
546555
547- void enableInterfaceHash () {
548- assert (!hasInterfaceHash ());
549- InterfaceHash.emplace ();
550- }
551-
556+ // / Whether this file has an interface hash available.
552557 bool hasInterfaceHash () const {
553- return InterfaceHash. hasValue ( );
558+ return ParsingOpts. contains (ParsingFlags::EnableInterfaceHash );
554559 }
555560
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 ;
567563
568564 void dumpInterfaceHash (llvm::raw_ostream &out) {
569565 llvm::SmallString<32 > str;
570566 getInterfaceHash (str);
571567 out << str << ' \n ' ;
572568 }
573569
574- std::vector<Token> & getTokenVector ();
575-
570+ // / If this source file has been told to collect its parsed tokens, retrieve
571+ // / those tokens.
576572 ArrayRef<Token> getAllTokens () const ;
577573
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 ;
579577
580578 bool shouldBuildSyntaxTree () const ;
581579
582- bool canBeParsedInFull () const ;
583-
584580 // / Whether the bodies of types and functions within this file can be lazily
585581 // / parsed.
586582 bool hasDelayedBodyParsing () const ;
587583
588584 syntax::SourceFileSyntax getSyntaxRoot () const ;
589- void setSyntaxRoot (syntax::SourceFileSyntax &&Root);
590- bool hasSyntaxRoot () const ;
591585
592586 OpaqueTypeDecl *lookupOpaqueResultType (StringRef MangledName) override ;
593587
@@ -602,10 +596,12 @@ class SourceFile final : public FileUnit {
602596
603597private:
604598
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;
607602
608- std::unique_ptr<SourceFileSyntaxInfo> SyntaxInfo;
603+ // / The root of the syntax tree representing the source file.
604+ std::unique_ptr<syntax::SourceFileSyntax> SyntaxRoot;
609605};
610606
611607inline SourceFile::ParsingOptions operator |(SourceFile::ParsingFlags lhs,
0 commit comments