clang  15.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 
17 
18 #include "clang/AST/GlobalDecl.h"
19 
20 #include "llvm/ADT/ArrayRef.h"
21 #include "llvm/ADT/StringRef.h"
22 #include "llvm/Support/Error.h"
23 
24 #include <list>
25 #include <memory>
26 namespace llvm {
27 class LLVMContext;
28 }
29 
30 namespace clang {
31 class ASTConsumer;
32 class CompilerInstance;
33 class IncrementalAction;
34 class Parser;
35 
36 /// Provides support for incremental compilation. Keeps track of the state
37 /// changes between the subsequent incremental input.
38 ///
40  /// Long-lived, incremental parsing action.
41  std::unique_ptr<IncrementalAction> Act;
42 
43  /// Compiler instance performing the incremental compilation.
44  std::unique_ptr<CompilerInstance> CI;
45 
46  /// Parser.
47  std::unique_ptr<Parser> P;
48 
49  /// Consumer to process the produced top level decls. Owned by Act.
50  ASTConsumer *Consumer = nullptr;
51 
52  /// Counts the number of direct user input lines that have been parsed.
53  unsigned InputCount = 0;
54 
55  /// List containing every information about every incrementally parsed piece
56  /// of code.
57  std::list<PartialTranslationUnit> PTUs;
58 
59 public:
60  IncrementalParser(std::unique_ptr<CompilerInstance> Instance,
61  llvm::LLVMContext &LLVMCtx, llvm::Error &Err);
63 
64  const CompilerInstance *getCI() const { return CI.get(); }
65 
66  /// Parses incremental input by creating an in-memory file.
67  ///\returns a \c PartialTranslationUnit which holds information about the
68  /// \c TranslationUnitDecl and \c llvm::Module corresponding to the input.
69  llvm::Expected<PartialTranslationUnit &> Parse(llvm::StringRef Input);
70 
71  /// Uses the CodeGenModule mangled name cache and avoids recomputing.
72  ///\returns the mangled name of a \c GD.
73  llvm::StringRef GetMangledName(GlobalDecl GD) const;
74 
75 private:
76  llvm::Expected<PartialTranslationUnit &> ParseOrWrapTopLevelDecl();
77 };
78 } // end namespace clang
79 
80 #endif // LLVM_CLANG_LIB_INTERPRETER_INCREMENTALPARSER_H
llvm
YAML serialization mapping.
Definition: Dominators.h:30
llvm::Expected
Definition: LLVM.h:41
PartialTranslationUnit.h
clang::IncrementalParser::IncrementalParser
IncrementalParser(std::unique_ptr< CompilerInstance > Instance, llvm::LLVMContext &LLVMCtx, llvm::Error &Err)
Definition: IncrementalParser.cpp:122
clang::GlobalDecl
GlobalDecl - represents a global declaration.
Definition: GlobalDecl.h:56
clang::IncrementalParser::GetMangledName
llvm::StringRef GetMangledName(GlobalDecl GD) const
Uses the CodeGenModule mangled name cache and avoids recomputing.
Definition: IncrementalParser.cpp:296
clang::ASTConsumer
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs.
Definition: ASTConsumer.h:33
clang::IncrementalParser::Parse
llvm::Expected< PartialTranslationUnit & > Parse(llvm::StringRef Input)
Parses incremental input by creating an in-memory file.
Definition: IncrementalParser.cpp:232
clang::CompilerInstance
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
Definition: CompilerInstance.h:72
clang::IncrementalParser
Provides support for incremental compilation.
Definition: IncrementalParser.h:39
clang::IncrementalParser::getCI
const CompilerInstance * getCI() const
Definition: IncrementalParser.h:64
clang
Definition: CalledOnceCheck.h:17
clang::IncrementalParser::~IncrementalParser
~IncrementalParser()
Definition: IncrementalParser.cpp:137
GlobalDecl.h