Path: blob/main/contrib/llvm-project/clang/lib/Interpreter/IncrementalParser.h
35233 views
//===--- IncrementalParser.h - Incremental Compilation ----------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file implements the class which performs incremental code compilation.9//10//===----------------------------------------------------------------------===//1112#ifndef LLVM_CLANG_LIB_INTERPRETER_INCREMENTALPARSER_H13#define LLVM_CLANG_LIB_INTERPRETER_INCREMENTALPARSER_H1415#include "clang/AST/GlobalDecl.h"16#include "clang/Interpreter/PartialTranslationUnit.h"1718#include "llvm/ADT/ArrayRef.h"19#include "llvm/ADT/StringRef.h"20#include "llvm/Support/Error.h"2122#include <list>23#include <memory>24namespace llvm {25class LLVMContext;26class Module;27} // namespace llvm2829namespace clang {30class ASTConsumer;31class CodeGenerator;32class CompilerInstance;33class IncrementalAction;34class Interpreter;35class Parser;36/// Provides support for incremental compilation. Keeps track of the state37/// changes between the subsequent incremental input.38///39class IncrementalParser {40protected:41/// Long-lived, incremental parsing action.42std::unique_ptr<IncrementalAction> Act;4344/// Compiler instance performing the incremental compilation.45std::unique_ptr<CompilerInstance> CI;4647/// Parser.48std::unique_ptr<Parser> P;4950/// Consumer to process the produced top level decls. Owned by Act.51ASTConsumer *Consumer = nullptr;5253/// Counts the number of direct user input lines that have been parsed.54unsigned InputCount = 0;5556/// List containing every information about every incrementally parsed piece57/// of code.58std::list<PartialTranslationUnit> PTUs;5960/// When CodeGen is created the first llvm::Module gets cached in many places61/// and we must keep it alive.62std::unique_ptr<llvm::Module> CachedInCodeGenModule;6364IncrementalParser();6566public:67IncrementalParser(Interpreter &Interp,68std::unique_ptr<CompilerInstance> Instance,69llvm::LLVMContext &LLVMCtx, llvm::Error &Err);70virtual ~IncrementalParser();7172CompilerInstance *getCI() { return CI.get(); }73CodeGenerator *getCodeGen() const;7475/// Parses incremental input by creating an in-memory file.76///\returns a \c PartialTranslationUnit which holds information about the77/// \c TranslationUnitDecl and \c llvm::Module corresponding to the input.78virtual llvm::Expected<PartialTranslationUnit &> Parse(llvm::StringRef Input);7980/// Uses the CodeGenModule mangled name cache and avoids recomputing.81///\returns the mangled name of a \c GD.82llvm::StringRef GetMangledName(GlobalDecl GD) const;8384void CleanUpPTU(PartialTranslationUnit &PTU);8586std::list<PartialTranslationUnit> &getPTUs() { return PTUs; }8788std::unique_ptr<llvm::Module> GenModule();8990private:91llvm::Expected<PartialTranslationUnit &> ParseOrWrapTopLevelDecl();92};93} // end namespace clang9495#endif // LLVM_CLANG_LIB_INTERPRETER_INCREMENTALPARSER_H969798