clang 18.0.0git
IncrementalParser.h
Go to the documentation of this file.
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
18
19#include "llvm/ADT/ArrayRef.h"
20#include "llvm/ADT/StringRef.h"
21#include "llvm/Support/Error.h"
22
23#include <list>
24#include <memory>
25namespace llvm {
26class LLVMContext;
27} // namespace llvm
28
29namespace clang {
30class ASTConsumer;
31class CodeGenerator;
32class CompilerInstance;
33class IncrementalAction;
34class Interpreter;
35class Parser;
36/// Provides support for incremental compilation. Keeps track of the state
37/// changes between the subsequent incremental input.
38///
40protected:
41 /// Long-lived, incremental parsing action.
42 std::unique_ptr<IncrementalAction> Act;
43
44 /// Compiler instance performing the incremental compilation.
45 std::unique_ptr<CompilerInstance> CI;
46
47 /// Parser.
48 std::unique_ptr<Parser> P;
49
50 /// Consumer to process the produced top level decls. Owned by Act.
52
53 /// Counts the number of direct user input lines that have been parsed.
54 unsigned InputCount = 0;
55
56 /// List containing every information about every incrementally parsed piece
57 /// of code.
58 std::list<PartialTranslationUnit> PTUs;
59
61
62public:
64 std::unique_ptr<CompilerInstance> Instance,
65 llvm::LLVMContext &LLVMCtx, llvm::Error &Err);
66 virtual ~IncrementalParser();
67
68 CompilerInstance *getCI() { return CI.get(); }
70
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);
75
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;
79
81
82 std::list<PartialTranslationUnit> &getPTUs() { return PTUs; }
83
84 std::unique_ptr<llvm::Module> GenModule();
85
86private:
87 llvm::Expected<PartialTranslationUnit &> ParseOrWrapTopLevelDecl();
88};
89} // end namespace clang
90
91#endif // LLVM_CLANG_LIB_INTERPRETER_INCREMENTALPARSER_H
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs.
Definition: ASTConsumer.h:33
The primary public interface to the Clang code generator.
Definition: ModuleBuilder.h:48
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
GlobalDecl - represents a global declaration.
Definition: GlobalDecl.h:56
Provides support for incremental compilation.
std::list< PartialTranslationUnit > PTUs
List containing every information about every incrementally parsed piece of code.
llvm::StringRef GetMangledName(GlobalDecl GD) const
Uses the CodeGenModule mangled name cache and avoids recomputing.
std::unique_ptr< IncrementalAction > Act
Long-lived, incremental parsing action.
virtual llvm::Expected< PartialTranslationUnit & > Parse(llvm::StringRef Input)
Parses incremental input by creating an in-memory file.
CompilerInstance * getCI()
std::unique_ptr< CompilerInstance > CI
Compiler instance performing the incremental compilation.
void CleanUpPTU(PartialTranslationUnit &PTU)
unsigned InputCount
Counts the number of direct user input lines that have been parsed.
std::unique_ptr< llvm::Module > GenModule()
std::list< PartialTranslationUnit > & getPTUs()
std::unique_ptr< Parser > P
Parser.
ASTConsumer * Consumer
Consumer to process the produced top level decls. Owned by Act.
CodeGenerator * getCodeGen() const
Provides top-level interfaces for incremental compilation and execution.
Definition: Interpreter.h:76
YAML serialization mapping.
Definition: Dominators.h:30
The class keeps track of various objects created as part of processing incremental inputs.