Skip to content

Commit 5896774

Browse files
committed
IsComplete should try to instantiate a type if it was a template.
This patch removes the external calls to getInterpreter/getSema in favor of storing them as static variables. That improves the ABI resilience of the API.
1 parent 26c3946 commit 5896774

File tree

9 files changed

+511
-602
lines changed

9 files changed

+511
-602
lines changed

include/clang/Interpreter/CppInterOp.h

Lines changed: 41 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@ namespace Cpp {
2121
using TCppFunction_t = void*;
2222
using TCppConstFunction_t = const void*;
2323
using TCppFuncAddr_t = void*;
24-
using TCppSema_t = void *;
2524
using TInterp_t = void*;
2625
using TCppObject_t = void*;
2726
/// A class modeling function calls for functions produced by the interpreter
2827
/// in compiled code. It provides an information if we are calling a standard
2928
/// function, constructor or destructor.
3029
class JitCall {
3130
public:
32-
friend JitCall MakeFunctionCallable(TInterp_t, TCppConstFunction_t);
31+
friend JitCall MakeFunctionCallable(TCppConstFunction_t);
3332
enum Kind : char {
3433
kUnknown = 0,
3534
kGenericCall,
@@ -160,29 +159,27 @@ namespace Cpp {
160159

161160
TCppIndex_t GetEnumConstantValue(TCppScope_t scope);
162161

163-
size_t GetSizeOfType(TCppSema_t sema, TCppType_t type);
162+
size_t GetSizeOfType(TCppType_t type);
164163

165164
bool IsVariable(TCppScope_t scope);
166165

167166
std::string GetName(TCppType_t klass);
168167

169-
std::string GetCompleteName(TCppSema_t sema, TCppType_t klass);
168+
std::string GetCompleteName(TCppType_t klass);
170169

171170
std::string GetQualifiedName(TCppType_t klass);
172171

173-
std::string GetQualifiedCompleteName(TCppSema_t sema, TCppType_t klass);
172+
std::string GetQualifiedCompleteName(TCppType_t klass);
174173

175174
std::vector<TCppScope_t> GetUsingNamespaces(TCppScope_t scope);
176175

177-
TCppScope_t GetGlobalScope(TCppSema_t sema);
176+
TCppScope_t GetGlobalScope();
178177

179-
TCppScope_t GetScope(TCppSema_t sema, const std::string &name,
180-
TCppScope_t parent = 0);
178+
TCppScope_t GetScope(const std::string &name, TCppScope_t parent = 0);
181179

182-
TCppScope_t GetScopeFromCompleteName(TCppSema_t sema,
183-
const std::string &name);
180+
TCppScope_t GetScopeFromCompleteName(const std::string &name);
184181

185-
TCppScope_t GetNamed(TCppSema_t sema, const std::string &name,
182+
TCppScope_t GetNamed(const std::string &name,
186183
TCppScope_t parent = nullptr);
187184

188185
TCppScope_t GetParentScope(TCppScope_t scope);
@@ -193,26 +190,23 @@ namespace Cpp {
193190

194191
TCppScope_t GetBaseClass(TCppType_t klass, TCppIndex_t ibase);
195192

196-
bool IsSubclass(TInterp_t interp, TCppScope_t derived, TCppScope_t base);
193+
bool IsSubclass(TCppScope_t derived, TCppScope_t base);
197194

198-
int64_t GetBaseClassOffset(TCppSema_t sema, TCppScope_t derived,
199-
TCppScope_t base);
195+
int64_t GetBaseClassOffset(TCppScope_t derived, TCppScope_t base);
200196

201-
std::vector<TCppFunction_t> GetClassMethods(TCppSema_t sema,
202-
TCppScope_t klass);
197+
std::vector<TCppFunction_t> GetClassMethods(TCppScope_t klass);
203198

204199
///\returns if a class has a default constructor.
205200
bool HasDefaultConstructor(TCppScope_t scope);
206201

207202
///\returns the default constructor of a class if any.
208-
TCppFunction_t GetDefaultConstructor(TCppSema_t sema, TCppScope_t scope);
203+
TCppFunction_t GetDefaultConstructor(TCppScope_t scope);
209204

210205
///\returns the class destructor.
211-
TCppFunction_t GetDestructor(TCppSema_t sema, TCppScope_t scope);
206+
TCppFunction_t GetDestructor(TCppScope_t scope);
212207

213-
std::vector<TCppFunction_t> GetFunctionsUsingName(TCppSema_t sema,
214-
TCppScope_t scope,
215-
const std::string &name);
208+
std::vector<TCppFunction_t> GetFunctionsUsingName(
209+
TCppScope_t scope, const std::string& name);
216210

217211
TCppType_t GetFunctionReturnType(TCppFunction_t func);
218212

@@ -231,8 +225,8 @@ namespace Cpp {
231225

232226
bool IsTemplatedFunction(TCppFunction_t func);
233227

234-
bool ExistsFunctionTemplate(TCppSema_t sema, const std::string &name,
235-
TCppScope_t parent = 0);
228+
bool ExistsFunctionTemplate(const std::string& name,
229+
TCppScope_t parent = 0);
236230

237231
bool IsMethod(TCppConstFunction_t method);
238232

@@ -248,18 +242,17 @@ namespace Cpp {
248242

249243
bool IsStaticMethod(TCppFunction_t method);
250244

251-
TCppFuncAddr_t GetFunctionAddress(TInterp_t interp, TCppFunction_t method);
245+
TCppFuncAddr_t GetFunctionAddress(TCppFunction_t method);
252246

253247
bool IsVirtualMethod(TCppFunction_t method);
254248

255249
std::vector<TCppScope_t> GetDatamembers(TCppScope_t scope);
256250

257-
TCppScope_t LookupDatamember(TCppSema_t sema, const std::string &name,
258-
TCppScope_t parent);
251+
TCppScope_t LookupDatamember(const std::string& name, TCppScope_t parent);
259252

260253
TCppType_t GetVariableType(TCppScope_t var);
261254

262-
intptr_t GetVariableOffset(TInterp_t interp, TCppScope_t var);
255+
intptr_t GetVariableOffset(TCppScope_t var);
263256

264257
bool IsPublicVariable(TCppScope_t var);
265258

@@ -273,26 +266,26 @@ namespace Cpp {
273266

274267
bool IsRecordType(TCppType_t type);
275268

276-
bool IsPODType(TCppSema_t sema, TCppType_t type);
269+
bool IsPODType(TCppType_t type);
277270

278271
TCppType_t GetUnderlyingType(TCppType_t type);
279272

280273
std::string GetTypeAsString(TCppType_t type);
281274

282275
TCppType_t GetCanonicalType(TCppType_t type);
283276

284-
TCppType_t GetType(TCppSema_t sema, const std::string &type);
277+
TCppType_t GetType(const std::string &type);
285278

286-
TCppType_t GetComplexType(TCppSema_t sema, TCppType_t element_type);
279+
TCppType_t GetComplexType(TCppType_t element_type);
287280

288281
TCppType_t GetTypeFromScope(TCppScope_t klass);
289282

290283
/// Check if a C++ type derives from another.
291-
bool IsTypeDerivedFrom(TInterp_t interp, TCppType_t derived, TCppType_t base);
284+
bool IsTypeDerivedFrom(TCppType_t derived, TCppType_t base);
292285

293286
/// Creates a trampoline function by using the interpreter and returns a
294287
/// uniform interface to call it from compiled code.
295-
JitCall MakeFunctionCallable(TInterp_t interp, TCppConstFunction_t func);
288+
JitCall MakeFunctionCallable(TCppConstFunction_t func);
296289

297290
/// Checks if a function declared is of const type or not
298291
bool IsConstMethod(TCppFunction_t method);
@@ -310,41 +303,40 @@ namespace Cpp {
310303
/// adds additional arguments to the interpreter.
311304
TInterp_t CreateInterpreter(const std::vector<const char *> &Args = {});
312305

313-
TCppSema_t GetSema(TInterp_t interp);
306+
///\returns the current interpreter instance, if any.
307+
TInterp_t GetInterpreter();
314308

315-
void AddSearchPath(TInterp_t interp, const char *dir, bool isUser = true,
316-
bool prepend = false);
309+
void AddSearchPath(const char *dir, bool isUser = true, bool prepend = false);
317310

318311
/// Returns the resource-dir path.
319-
const char *GetResourceDir(TInterp_t interp);
312+
const char* GetResourceDir();
320313

321-
void AddIncludePath(TInterp_t interp, const char *dir);
314+
void AddIncludePath(const char *dir);
322315

323-
TCppIndex_t Declare(TInterp_t interp, const char *code, bool silent = false);
316+
TCppIndex_t Declare(const char *code, bool silent = false);
324317

325318
/// Declares and runs a code snippet in \c code.
326319
///\returns 0 on success
327-
int Process(TInterp_t interp, const char *code);
320+
int Process(const char *code);
328321

329322
/// Declares, runs and returns the execution result as a intptr_t.
330323
///\returns the expression results as a intptr_t.
331-
intptr_t Evaluate(TInterp_t interp, const char *code,
332-
bool *HadError = nullptr);
324+
intptr_t Evaluate(const char *code, bool *HadError = nullptr);
333325

334-
const std::string LookupLibrary(TInterp_t interp, const char *lib_name);
326+
const std::string LookupLibrary(const char *lib_name);
335327

336-
bool LoadLibrary(TInterp_t interp, const char *lib_path, bool lookup = true);
328+
bool LoadLibrary(const char *lib_path, bool lookup = true);
337329

338-
std::string ObjToString(TInterp_t interp, const char *type, void *obj);
330+
std::string ObjToString(const char *type, void *obj);
339331

340332
struct TemplateArgInfo {
341333
TCppScope_t m_Type;
342334
const char* m_IntegralValue;
343335
TemplateArgInfo(TCppScope_t type, const char* integral_value = nullptr)
344336
: m_Type(type), m_IntegralValue(integral_value) {}
345337
};
346-
TCppScope_t InstantiateClassTemplate(TInterp_t interp, TCppScope_t tmpl,
347-
TemplateArgInfo *template_args,
338+
TCppScope_t InstantiateClassTemplate(TCppScope_t tmpl,
339+
TemplateArgInfo* template_args,
348340
size_t template_args_size);
349341

350342
std::vector<std::string> GetAllCppNames(TCppScope_t scope);
@@ -367,12 +359,12 @@ namespace Cpp {
367359

368360
/// Creates an object of class \c scope and calls its default constructor. If
369361
/// \c arena is set it uses placement new.
370-
TCppObject_t Construct(TInterp_t interp, TCppScope_t scope,
371-
void *arena = nullptr);
362+
TCppObject_t Construct(TCppScope_t scope,
363+
void* arena = nullptr);
372364

373365
/// Calls the destructor of object of type \c type. When withFree is true it
374366
/// calls operator delete/free.
375-
void Destruct(TInterp_t interp, TCppObject_t This, TCppScope_t type,
367+
void Destruct(TCppObject_t This, TCppScope_t type,
376368
bool withFree = true);
377369
} // end namespace Cpp
378370

0 commit comments

Comments
 (0)