[DFAJumpThreading] Remove incoming StartBlock from all phis when unfolding select...
[llvm-project.git] / clang / lib / Interpreter / IncrementalParser.h
blobe13b74c7f6594890ac6481e4be41a2270086bac7
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.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_LIB_INTERPRETER_INCREMENTALPARSER_H
14 #define LLVM_CLANG_LIB_INTERPRETER_INCREMENTALPARSER_H
16 #include "clang/AST/GlobalDecl.h"
17 #include "clang/Interpreter/PartialTranslationUnit.h"
19 #include "llvm/ADT/ArrayRef.h"
20 #include "llvm/ADT/StringRef.h"
21 #include "llvm/Support/Error.h"
23 #include <list>
24 #include <memory>
25 namespace llvm {
26 class LLVMContext;
27 } // namespace llvm
29 namespace clang {
30 class ASTConsumer;
31 class CodeGenerator;
32 class CompilerInstance;
33 class IncrementalAction;
34 class Interpreter;
35 class Parser;
36 /// Provides support for incremental compilation. Keeps track of the state
37 /// changes between the subsequent incremental input.
38 ///
39 class IncrementalParser {
40 protected:
41 /// Long-lived, incremental parsing action.
42 std::unique_ptr<IncrementalAction> Act;
44 /// Compiler instance performing the incremental compilation.
45 std::unique_ptr<CompilerInstance> CI;
47 /// Parser.
48 std::unique_ptr<Parser> P;
50 /// Consumer to process the produced top level decls. Owned by Act.
51 ASTConsumer *Consumer = nullptr;
53 /// Counts the number of direct user input lines that have been parsed.
54 unsigned InputCount = 0;
56 /// List containing every information about every incrementally parsed piece
57 /// of code.
58 std::list<PartialTranslationUnit> PTUs;
60 IncrementalParser();
62 public:
63 IncrementalParser(Interpreter &Interp,
64 std::unique_ptr<CompilerInstance> Instance,
65 llvm::LLVMContext &LLVMCtx, llvm::Error &Err);
66 virtual ~IncrementalParser();
68 CompilerInstance *getCI() { return CI.get(); }
69 CodeGenerator *getCodeGen() const;
71 /// Parses incremental input by creating an in-memory file.
72 ///\returns a \c PartialTranslationUnit which holds information about the
73 /// \c TranslationUnitDecl and \c llvm::Module corresponding to the input.
74 virtual llvm::Expected<PartialTranslationUnit &> Parse(llvm::StringRef Input);
76 /// Uses the CodeGenModule mangled name cache and avoids recomputing.
77 ///\returns the mangled name of a \c GD.
78 llvm::StringRef GetMangledName(GlobalDecl GD) const;
80 void CleanUpPTU(PartialTranslationUnit &PTU);
82 std::list<PartialTranslationUnit> &getPTUs() { return PTUs; }
84 std::unique_ptr<llvm::Module> GenModule();
86 private:
87 llvm::Expected<PartialTranslationUnit &> ParseOrWrapTopLevelDecl();
89 } // end namespace clang
91 #endif // LLVM_CLANG_LIB_INTERPRETER_INCREMENTALPARSER_H