clang 22.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
16#include "llvm/ADT/StringRef.h"
17#include "llvm/Support/Error.h"
18
19#include <list>
20#include <memory>
21
22namespace llvm {
23class Module;
24}
25
26namespace clang {
27class ASTConsumer;
28class CompilerInstance;
29class Parser;
30class Sema;
31class TranslationUnitDecl;
32class IncrementalAction;
33struct PartialTranslationUnit;
34
35/// Provides support for incremental compilation. Keeps track of the state
36/// changes between the subsequent incremental input.
37///
39protected:
40 /// The Sema performing the incremental compilation.
42
43 /// Parser.
44 std::unique_ptr<Parser> P;
45
46 /// Consumer to process the produced top level decls. Owned by Act.
48
49 /// Counts the number of direct user input lines that have been parsed.
50 unsigned InputCount = 0;
51
52 /// The FrontendAction used during incremental parsing.
54
55 std::list<PartialTranslationUnit> &PTUs;
56
57public:
59 llvm::Error &Err, std::list<PartialTranslationUnit> &PTUs);
60 virtual ~IncrementalParser();
61
62 /// Parses incremental input by creating an in-memory file.
63 ///\returns a \c PartialTranslationUnit which holds information about the
64 /// \c TranslationUnitDecl.
65 virtual llvm::Expected<TranslationUnitDecl *> Parse(llvm::StringRef Input);
66
67 void CleanUpPTU(TranslationUnitDecl *MostRecentTU);
68
69 /// Register a PTU produced by Parse.
71 std::unique_ptr<llvm::Module> M = {});
72
73private:
74 llvm::Expected<TranslationUnitDecl *> ParseOrWrapTopLevelDecl();
75};
76} // end namespace clang
77
78#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:34
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
A custom action enabling the incremental processing functionality.
Provides support for incremental compilation.
IncrementalAction * Act
The FrontendAction used during incremental parsing.
std::list< PartialTranslationUnit > & PTUs
unsigned InputCount
Counts the number of direct user input lines that have been parsed.
void CleanUpPTU(TranslationUnitDecl *MostRecentTU)
PartialTranslationUnit & RegisterPTU(TranslationUnitDecl *TU, std::unique_ptr< llvm::Module > M={})
Register a PTU produced by Parse.
std::unique_ptr< Parser > P
Parser.
ASTConsumer * Consumer
Consumer to process the produced top level decls. Owned by Act.
Sema & S
The Sema performing the incremental compilation.
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:850
The top declaration context.
Definition: Decl.h:104
The JSON file list parser is used to communicate input to InstallAPI.
@ Parse
Parse the block; this code is always used.
@ Module
Module linkage, which indicates that the entity can be referred to from other translation units withi...
Diagnostic wrappers for TextAPI types for error reporting.
Definition: Dominators.h:30
The class keeps track of various objects created as part of processing incremental inputs.