1 //===--- IncrementalParser.h - Incremental Compilation ----------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file implements the class which performs incremental code compilation. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef LLVM_CLANG_LIB_INTERPRETER_INCREMENTALPARSER_H 14 #define LLVM_CLANG_LIB_INTERPRETER_INCREMENTALPARSER_H 15 16 #include "llvm/ADT/StringRef.h" 17 #include "llvm/Support/Error.h" 18 19 #include <list> 20 #include <memory> 21 22 namespace clang { 23 class ASTConsumer; 24 class CodeGenerator; 25 class CompilerInstance; 26 class Parser; 27 class Sema; 28 class TranslationUnitDecl; 29 30 /// Provides support for incremental compilation. Keeps track of the state 31 /// changes between the subsequent incremental input. 32 /// 33 class IncrementalParser { 34 protected: 35 /// The Sema performing the incremental compilation. 36 Sema &S; 37 38 /// Parser. 39 std::unique_ptr<Parser> P; 40 41 /// Consumer to process the produced top level decls. Owned by Act. 42 ASTConsumer *Consumer = nullptr; 43 44 /// Counts the number of direct user input lines that have been parsed. 45 unsigned InputCount = 0; 46 47 // IncrementalParser(); 48 49 public: 50 IncrementalParser(CompilerInstance &Instance, llvm::Error &Err); 51 virtual ~IncrementalParser(); 52 53 /// Parses incremental input by creating an in-memory file. 54 ///\returns a \c PartialTranslationUnit which holds information about the 55 /// \c TranslationUnitDecl. 56 virtual llvm::Expected<TranslationUnitDecl *> Parse(llvm::StringRef Input); 57 58 void CleanUpPTU(TranslationUnitDecl *MostRecentTU); 59 60 private: 61 llvm::Expected<TranslationUnitDecl *> ParseOrWrapTopLevelDecl(); 62 }; 63 } // end namespace clang 64 65 #endif // LLVM_CLANG_LIB_INTERPRETER_INCREMENTALPARSER_H 66