1fe6060f1SDimitry Andric //===--- IncrementalParser.h - Incremental Compilation ----------*- C++ -*-===// 2fe6060f1SDimitry Andric // 3fe6060f1SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4fe6060f1SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5fe6060f1SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6fe6060f1SDimitry Andric // 7fe6060f1SDimitry Andric //===----------------------------------------------------------------------===// 8fe6060f1SDimitry Andric // 9fe6060f1SDimitry Andric // This file implements the class which performs incremental code compilation. 10fe6060f1SDimitry Andric // 11fe6060f1SDimitry Andric //===----------------------------------------------------------------------===// 12fe6060f1SDimitry Andric 13fe6060f1SDimitry Andric #ifndef LLVM_CLANG_LIB_INTERPRETER_INCREMENTALPARSER_H 14fe6060f1SDimitry Andric #define LLVM_CLANG_LIB_INTERPRETER_INCREMENTALPARSER_H 15fe6060f1SDimitry Andric 16fe6060f1SDimitry Andric #include "clang/Interpreter/PartialTranslationUnit.h" 17fe6060f1SDimitry Andric 18349cc55cSDimitry Andric #include "clang/AST/GlobalDecl.h" 19fe6060f1SDimitry Andric #include "llvm/ADT/ArrayRef.h" 20fe6060f1SDimitry Andric #include "llvm/ADT/StringRef.h" 21fe6060f1SDimitry Andric #include "llvm/Support/Error.h" 22fe6060f1SDimitry Andric 23fe6060f1SDimitry Andric #include <list> 24fe6060f1SDimitry Andric #include <memory> 25fe6060f1SDimitry Andric namespace llvm { 26fe6060f1SDimitry Andric class LLVMContext; 27fe6060f1SDimitry Andric } 28fe6060f1SDimitry Andric 29fe6060f1SDimitry Andric namespace clang { 30fe6060f1SDimitry Andric class ASTConsumer; 31*06c3fb27SDimitry Andric class CodeGenerator; 32fe6060f1SDimitry Andric class CompilerInstance; 33fe6060f1SDimitry Andric class IncrementalAction; 34*06c3fb27SDimitry Andric class Interpreter; 35fe6060f1SDimitry Andric class Parser; 36fe6060f1SDimitry Andric /// Provides support for incremental compilation. Keeps track of the state 37fe6060f1SDimitry Andric /// changes between the subsequent incremental input. 38fe6060f1SDimitry Andric /// 39fe6060f1SDimitry Andric class IncrementalParser { 40*06c3fb27SDimitry Andric protected: 41fe6060f1SDimitry Andric /// Long-lived, incremental parsing action. 42fe6060f1SDimitry Andric std::unique_ptr<IncrementalAction> Act; 43fe6060f1SDimitry Andric 44fe6060f1SDimitry Andric /// Compiler instance performing the incremental compilation. 45fe6060f1SDimitry Andric std::unique_ptr<CompilerInstance> CI; 46fe6060f1SDimitry Andric 47fe6060f1SDimitry Andric /// Parser. 48fe6060f1SDimitry Andric std::unique_ptr<Parser> P; 49fe6060f1SDimitry Andric 50fe6060f1SDimitry Andric /// Consumer to process the produced top level decls. Owned by Act. 51fe6060f1SDimitry Andric ASTConsumer *Consumer = nullptr; 52fe6060f1SDimitry Andric 53fe6060f1SDimitry Andric /// Counts the number of direct user input lines that have been parsed. 54fe6060f1SDimitry Andric unsigned InputCount = 0; 55fe6060f1SDimitry Andric 56fe6060f1SDimitry Andric /// List containing every information about every incrementally parsed piece 57fe6060f1SDimitry Andric /// of code. 58fe6060f1SDimitry Andric std::list<PartialTranslationUnit> PTUs; 59fe6060f1SDimitry Andric 60*06c3fb27SDimitry Andric IncrementalParser(); 61fe6060f1SDimitry Andric 62*06c3fb27SDimitry Andric public: 63*06c3fb27SDimitry Andric IncrementalParser(Interpreter &Interp, 64*06c3fb27SDimitry Andric std::unique_ptr<CompilerInstance> Instance, 65*06c3fb27SDimitry Andric llvm::LLVMContext &LLVMCtx, llvm::Error &Err); 66*06c3fb27SDimitry Andric virtual ~IncrementalParser(); 67*06c3fb27SDimitry Andric 68*06c3fb27SDimitry Andric CompilerInstance *getCI() { return CI.get(); } 69*06c3fb27SDimitry Andric CodeGenerator *getCodeGen() const; 70fe6060f1SDimitry Andric 71fe6060f1SDimitry Andric /// Parses incremental input by creating an in-memory file. 72fe6060f1SDimitry Andric ///\returns a \c PartialTranslationUnit which holds information about the 73fe6060f1SDimitry Andric /// \c TranslationUnitDecl and \c llvm::Module corresponding to the input. 74*06c3fb27SDimitry Andric virtual llvm::Expected<PartialTranslationUnit &> Parse(llvm::StringRef Input); 75fe6060f1SDimitry Andric 76349cc55cSDimitry Andric /// Uses the CodeGenModule mangled name cache and avoids recomputing. 77349cc55cSDimitry Andric ///\returns the mangled name of a \c GD. 78349cc55cSDimitry Andric llvm::StringRef GetMangledName(GlobalDecl GD) const; 79349cc55cSDimitry Andric 8081ad6265SDimitry Andric void CleanUpPTU(PartialTranslationUnit &PTU); 8181ad6265SDimitry Andric 8281ad6265SDimitry Andric std::list<PartialTranslationUnit> &getPTUs() { return PTUs; } 8381ad6265SDimitry Andric 84*06c3fb27SDimitry Andric std::unique_ptr<llvm::Module> GenModule(); 85*06c3fb27SDimitry Andric 86fe6060f1SDimitry Andric private: 87fe6060f1SDimitry Andric llvm::Expected<PartialTranslationUnit &> ParseOrWrapTopLevelDecl(); 88fe6060f1SDimitry Andric }; 89fe6060f1SDimitry Andric } // end namespace clang 90fe6060f1SDimitry Andric 91fe6060f1SDimitry Andric #endif // LLVM_CLANG_LIB_INTERPRETER_INCREMENTALPARSER_H 92