1 //===--- IncrementalParser.h - Incremental Compilation ----------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
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"
32 class CompilerInstance
;
33 class IncrementalAction
;
36 /// Provides support for incremental compilation. Keeps track of the state
37 /// changes between the subsequent incremental input.
39 class IncrementalParser
{
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
;
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
58 std::list
<PartialTranslationUnit
> PTUs
;
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();
87 llvm::Expected
<PartialTranslationUnit
&> ParseOrWrapTopLevelDecl();
89 } // end namespace clang
91 #endif // LLVM_CLANG_LIB_INTERPRETER_INCREMENTALPARSER_H