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#include <string>
29#include <utility>
30#include <vector>
31
32namespace Cpp {
33
36 bool isOwned = true;
37 // Store the list of builtin types.
38 llvm::StringMap<clang::QualType> BuiltinMap;
39 // Per-interpreter wrapper caches. Keyed on AST nodes that belong to this
40 // interpreter, so the caches must be destroyed together with it.
41 std::map<const clang::FunctionDecl*, void*> WrapperStore;
42 std::map<const clang::Decl*, void*> DtorWrapperStore;
43 // A deque keeps element addresses stable so DiagnosticRef::data
44 // survives push_back.
45 std::deque<StoredDiagView> StoredDiags;
46 // Owns the string arguments passed to clang during creation, since the
47 // interpreter keeps the raw argv pointers for its whole lifetime
48 std::vector<std::string> ArgvStorage;
49
51 std::vector<std::string> ArgvStrs = {})
52 : Interpreter(I), isOwned(Owned), ArgvStorage(std::move(ArgvStrs)) {}
53
55 : Interpreter(Other.Interpreter), isOwned(Other.isOwned),
56 ArgvStorage(std::move(Other.ArgvStorage)) {
57 Other.Interpreter = nullptr;
58 Other.isOwned = false;
59 }
61 if (this != &Other) {
62 if (isOwned)
63 delete Interpreter;
65 isOwned = Other.isOwned;
66 ArgvStorage = std::move(Other.ArgvStorage);
67 Other.Interpreter = nullptr;
68 Other.isOwned = false;
69 }
70 return *this;
71 }
72
74 if (isOwned)
75 delete Interpreter;
76 }
77
80};
81
82/// Resolve an InterpRef to the impl-side struct. When I is null,
83/// returns the active (last-created) interpreter.
84CPPINTEROP_API InterpreterInfo* GetInterpInfo(InterpRef I = nullptr);
85
86/// Wire CppInterOp's DiagnosticConsumer into the interpreter's
87/// DiagnosticsEngine so parser/sema diagnostics flow into II->StoredDiags
88/// and continue forwarding to whatever consumer Clang already had.
90
91} // namespace Cpp
92
93#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
std::vector< std::string > ArgvStorage
llvm::StringMap< clang::QualType > BuiltinMap
InterpreterInfo(compat::Interpreter *I, bool Owned, std::vector< std::string > ArgvStrs={})
InterpreterInfo(const InterpreterInfo &)=delete
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