CppInterOp
C++ Language Interoperability Layer
Loading...
Searching...
No Matches
InterpreterInfo.h
Go to the documentation of this file.
1//===--- InterpreterInfo.h - Per-interpreter impl state ---------*- C++ -*-===//
2//
3// Part of the compiler-research project, under the Apache License v2.0 with
4// LLVM Exceptions.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Impl-only header centralising the per-interpreter state struct used by
10// CppInterOp.cpp and Error.cpp. Not part of the public API; never
11// included from include/CppInterOp/.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef CPPINTEROP_LIB_INTERPRETERINFO_H
16#define CPPINTEROP_LIB_INTERPRETERINFO_H
17
18#include "Compatibility.h"
19#include "ErrorInternal.h"
20
21#include "clang/AST/Decl.h"
22#include "clang/AST/Type.h"
23
24#include "llvm/ADT/StringMap.h"
25
26#include <deque>
27#include <map>
28
29namespace Cpp {
30
33 bool isOwned = true;
34 // Store the list of builtin types.
35 llvm::StringMap<clang::QualType> BuiltinMap;
36 // Per-interpreter wrapper caches. Keyed on AST nodes that belong to this
37 // interpreter, so the caches must be destroyed together with it.
38 std::map<const clang::FunctionDecl*, void*> WrapperStore;
39 std::map<const clang::Decl*, void*> DtorWrapperStore;
40 // A deque keeps element addresses stable so DiagnosticRef::data
41 // survives push_back.
42 std::deque<StoredDiagView> StoredDiags;
43
45 : Interpreter(I), isOwned(Owned) {}
46
48 : Interpreter(Other.Interpreter), isOwned(Other.isOwned) {
49 Other.Interpreter = nullptr;
50 Other.isOwned = false;
51 }
53 if (this != &Other) {
54 if (isOwned)
55 delete Interpreter;
57 isOwned = Other.isOwned;
58 Other.Interpreter = nullptr;
59 Other.isOwned = false;
60 }
61 return *this;
62 }
63
65 if (isOwned)
66 delete Interpreter;
67 }
68
71};
72
73/// Resolve an InterpRef to the impl-side struct. When I is null,
74/// returns the active (last-created) interpreter.
75CPPINTEROP_API InterpreterInfo* GetInterpInfo(InterpRef I = nullptr);
76
77/// Wire CppInterOp's DiagnosticConsumer into the interpreter's
78/// DiagnosticsEngine so parser/sema diagnostics flow into II->StoredDiags
79/// and continue forwarding to whatever consumer Clang already had.
81
82} // namespace Cpp
83
84#endif // CPPINTEROP_LIB_INTERPRETERINFO_H
#define CPPINTEROP_API
CppInterOp Interpreter.
Interpreter(std::unique_ptr< clang::Interpreter > CI, std::unique_ptr< IOContext > ctx=nullptr, bool oop=false)
Definition Box.h:70
void InstallDiagConsumer(InterpreterInfo *II)
Wire CppInterOp's DiagnosticConsumer into the interpreter's DiagnosticsEngine so parser/sema diagnost...
InterpreterInfo * GetInterpInfo(InterpRef I)
Resolve an InterpRef to the impl-side struct.
InterpreterInfo & operator=(InterpreterInfo &&Other) noexcept
llvm::StringMap< clang::QualType > BuiltinMap
InterpreterInfo(const InterpreterInfo &)=delete
InterpreterInfo(compat::Interpreter *I, bool Owned)
std::map< const clang::FunctionDecl *, void * > WrapperStore
compat::Interpreter * Interpreter
std::map< const clang::Decl *, void * > DtorWrapperStore
std::deque< StoredDiagView > StoredDiags
InterpreterInfo & operator=(const InterpreterInfo &)=delete
InterpreterInfo(InterpreterInfo &&Other) noexcept