Skip to content

Commit cd22ee8

Browse files
committed
Store state
1 parent 05c3bb8 commit cd22ee8

File tree

9 files changed

+33
-37
lines changed

9 files changed

+33
-37
lines changed

clang/include/clang/AST/ASTContext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,8 @@ class ASTContext : public RefCountedBase<ASTContext> {
10661066
Module *getCurrentNamedModule() const { return CurrentCXXNamedModule; }
10671067

10681068
TranslationUnitDecl *getTranslationUnitDecl() const {
1069+
assert(TUDecl->getMostRecentDecl() == TUDecl &&
1070+
"The active TU is not current one!");
10691071
return TUDecl->getMostRecentDecl();
10701072
}
10711073
void addTranslationUnitDecl() {

clang/include/clang/Interpreter/Interpreter.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ class Interpreter {
9494
Value LastValue;
9595

9696
public:
97+
class SynthesizingCodeRAII {
98+
99+
};
100+
101+
SynthesizingCodeRAII EnterCodeSynthesisScope() {
102+
103+
}
104+
97105
~Interpreter();
98106
static llvm::Expected<std::unique_ptr<Interpreter>>
99107
create(std::unique_ptr<CompilerInstance> CI);
@@ -142,6 +150,8 @@ class Interpreter {
142150

143151
std::unique_ptr<llvm::Module> GenModule();
144152

153+
154+
145155
private:
146156
size_t getEffectivePTUSize() const;
147157

clang/lib/Interpreter/IncrementalExecutor.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@ IncrementalExecutor::IncrementalExecutor(llvm::orc::ThreadSafeContext &TSC,
6565

6666
IncrementalExecutor::~IncrementalExecutor() {}
6767

68-
llvm::Error IncrementalExecutor::addModule(std::unique_ptr<llvm::Module> &M) {
69-
return Jit->addIRModule({std::move(M), TSCtx});
70-
}
71-
7268
llvm::Error IncrementalExecutor::addModule(PartialTranslationUnit &PTU) {
7369
llvm::orc::ResourceTrackerSP RT =
7470
Jit->getMainJITDylib().createResourceTracker();

clang/lib/Interpreter/IncrementalExecutor.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ class IncrementalExecutor {
5050
const clang::TargetInfo &TI);
5151
~IncrementalExecutor();
5252

53-
llvm::Error addModule(std::unique_ptr<llvm::Module> &M);
5453
llvm::Error addModule(PartialTranslationUnit &PTU);
5554
llvm::Error removeModule(PartialTranslationUnit &PTU);
5655
llvm::Error runCtors() const;

clang/lib/Interpreter/Interpreter.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -378,22 +378,6 @@ llvm::Error Interpreter::CreateExecutor() {
378378
return Err;
379379
}
380380

381-
llvm::Error Interpreter::ExecuteModule(std::unique_ptr<llvm::Module> &M) {
382-
if (!IncrExecutor) {
383-
auto Err = CreateExecutor();
384-
if (Err)
385-
return Err;
386-
}
387-
// FIXME: Add a callback to retain the llvm::Module once the JIT is done.
388-
if (auto Err = IncrExecutor->addModule(M))
389-
return Err;
390-
391-
if (auto Err = IncrExecutor->runCtors())
392-
return Err;
393-
394-
return llvm::Error::success();
395-
}
396-
397381
llvm::Error Interpreter::Execute(PartialTranslationUnit &T) {
398382
assert(T.TheModule);
399383
if (!IncrExecutor) {

clang/lib/Interpreter/InterpreterUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ QualType GetFullyQualifiedType(QualType QT, const ASTContext &Ctx) {
484484
if (Prefix) {
485485
// We intentionally always use ETK_None, we never want
486486
// the keyword (humm ... what about anonymous types?)
487-
QT = Ctx.getElaboratedType(ETK_None, Prefix, QT);
487+
QT = Ctx.getElaboratedType(ElaboratedTypeKeyword::None, Prefix, QT);
488488
QT = Ctx.getQualifiedType(QT, PrefixQualifiers);
489489
}
490490
return QT;

clang/lib/Interpreter/ValuePrinter.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ static std::string PrintEnum(const Value &V) {
115115
IsFirst = false;
116116
}
117117
}
118-
119-
SS << " : " << PrintQualType(Ctx, ED->getIntegerType()) << " "
120-
<< llvm::toString(AP, /*Radix=*/10);
118+
llvm::SmallString<64> APStr;
119+
AP.toString(APStr, /*Radix=*/10);
120+
SS << " : " << PrintQualType(Ctx, ED->getIntegerType()) << " " << APStr;
121121
return Str;
122122
}
123123

@@ -277,10 +277,15 @@ static llvm::Expected<llvm::orc::ExecutorAddr> CompileDecl(Interpreter &Interp,
277277
ASTConsumer &Consumer = Interp.getCompilerInstance()->getASTConsumer();
278278
Consumer.HandleTopLevelDecl(DeclGroupRef(D));
279279
Interp.getCompilerInstance()->getSema().PerformPendingInstantiations();
280-
Consumer.HandleTranslationUnit(Interp.getASTContext());
280+
ASTContext &C = Interp.getASTContext();
281+
TranslationUnitDecl *TUPart = C.getTranslationUnitDecl();
282+
assert(!TUPart->containsDecl(D) && "Decl already added!");
283+
TUPart->addDecl(D);
284+
Consumer.HandleTranslationUnit(C);
281285

282286
if (std::unique_ptr<llvm::Module> M = Interp.GenModule()) {
283-
if (llvm::Error Err = Interp.ExecuteModule(M))
287+
PartialTranslationUnit PTU = {TUPart, std::move(M)};
288+
if (llvm::Error Err = Interp.Execute(PTU))
284289
return Err;
285290
ASTNameGenerator ASTNameGen(Interp.getASTContext());
286291
llvm::Expected<llvm::orc::ExecutorAddr> AddrOrErr =

clang/tools/clang-repl/ClangRepl.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ static int checkDiagErrors(const clang::CompilerInstance *CI, bool HasError) {
8282
}
8383

8484
struct ReplListCompleter {
85-
clang::IncrementalCompilerBuilder &CB;
86-
clang::Interpreter &MainInterp;
87-
ReplListCompleter(clang::IncrementalCompilerBuilder &CB,
88-
clang::Interpreter &Interp)
85+
clang::caas::IncrementalCompilerBuilder &CB;
86+
clang::caas::Interpreter &MainInterp;
87+
ReplListCompleter(clang::caas::IncrementalCompilerBuilder &CB,
88+
clang::caas::Interpreter &Interp)
8989
: CB(CB), MainInterp(Interp){};
9090

9191
std::vector<llvm::LineEditor::Completion> operator()(llvm::StringRef Buffer,
@@ -117,7 +117,7 @@ ReplListCompleter::operator()(llvm::StringRef Buffer, size_t Pos,
117117

118118
size_t Lines =
119119
std::count(Buffer.begin(), std::next(Buffer.begin(), Pos), '\n') + 1;
120-
auto Interp = clang::Interpreter::create(std::move(*CI));
120+
auto Interp = clang::caas::Interpreter::create(std::move(*CI));
121121

122122
if (auto Err = Interp.takeError()) {
123123
// log the error and returns an empty vector;

clang/unittests/Interpreter/CodeCompletionTest.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313

1414
using namespace clang;
1515
namespace {
16-
auto CB = clang::IncrementalCompilerBuilder();
16+
auto CB = clang::caas::IncrementalCompilerBuilder();
1717

18-
static std::unique_ptr<Interpreter> createInterpreter() {
18+
static std::unique_ptr<caas::Interpreter> createInterpreter() {
1919
auto CI = cantFail(CB.CreateCpp());
20-
return cantFail(clang::Interpreter::create(std::move(CI)));
20+
return cantFail(caas::Interpreter::create(std::move(CI)));
2121
}
2222

23-
static std::vector<std::string> runComp(clang::Interpreter &MainInterp,
23+
static std::vector<std::string> runComp(caas::Interpreter &MainInterp,
2424
llvm::StringRef Input,
2525
llvm::Error &ErrR) {
2626
auto CI = CB.CreateCpp();
@@ -29,7 +29,7 @@ static std::vector<std::string> runComp(clang::Interpreter &MainInterp,
2929
return {};
3030
}
3131

32-
auto Interp = clang::Interpreter::create(std::move(*CI));
32+
auto Interp = caas::Interpreter::create(std::move(*CI));
3333
if (auto Err = Interp.takeError()) {
3434
// log the error and returns an empty vector;
3535
ErrR = std::move(Err);

0 commit comments

Comments
 (0)