Skip to content

Commit c15be21

Browse files
committed
fix-up
1 parent 5dd4bf2 commit c15be21

File tree

2 files changed

+78
-54
lines changed

2 files changed

+78
-54
lines changed

include/clang-c/CXCppInterOp.h

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,12 @@ typedef void* TInterp_t;
4646
CXInterpreter clang_createInterpreterFromPtr(TInterp_t I);
4747

4848
/**
49-
* Returns a \c TInterp_t.
49+
* Returns a pointer to the underlying interpreter.
5050
*/
51-
TInterp_t clang_interpreter_getInterpreterAsPtr(CXInterpreter I);
51+
void* clang_interpreter_getUnderlyingInterpreter(CXInterpreter I);
5252

5353
/**
54-
* Similar to \c clang_interpreter_getInterpreterAsPtr() but it takes the
55-
* ownership.
54+
* Returns a \c TInterp_t and takes the ownership.
5655
*/
5756
TInterp_t clang_interpreter_takeInterpreterAsPtr(CXInterpreter I);
5857

@@ -359,18 +358,20 @@ bool clang_qualtype_isTypeDerivedFrom(CXQualType derived, CXQualType base);
359358
*/
360359
enum CXScopeKind {
361360
CXScope_Unexposed = 1, // FIXME: merge with CXCursorKind?
361+
CXScope_Enum = 5,
362+
CXScope_Field = 6,
363+
CXScope_EnumConstant = 7,
364+
CXScope_Function = 8,
365+
CXCursor_Var = 9,
362366
CXScope_Typedef = 20,
363367
CXScope_Namespace = 22,
364368
CXScope_ClassTemplate = 31,
365369
CXScope_TypeAlias = 36,
366370
CXScope_Invalid = 70,
367371
CXScope_TranslationUnit = 350,
368372

369-
CXScope_Record,
370-
CXScope_Function,
371-
CXScope_Variable,
372-
CXScope_EnumConstant,
373-
CXScope_Field,
373+
CXScope_Record = 999,
374+
CXScope_CXXRecord,
374375
};
375376

376377
/**
@@ -857,6 +858,14 @@ void clang_destruct(CXObject This, CXScope S, bool withFree);
857858
*/
858859
typedef struct CXJitCallImpl* CXJitCall;
859860

861+
/**
862+
* Creates a trampoline function by using the interpreter and returns a uniform
863+
* interface to call it from compiled code.
864+
*
865+
* \returns a \c CXJitCall.
866+
*/
867+
CXJitCall clang_jitcall_create(CXScope func);
868+
860869
/**
861870
* Dispose of the given CXJitCall.
862871
*
@@ -891,32 +900,21 @@ CXJitCallKind clang_jitcall_getKind(CXJitCall J);
891900
*/
892901
bool clang_jitcall_isValid(CXJitCall J);
893902

894-
typedef struct {
895-
void** data;
896-
size_t numArgs;
897-
} CXJitCallArgList;
898-
899903
/**
900904
* Makes a call to a generic function or method.
901905
*
902-
* \param[in] J The CXJitCall.
906+
* \param J The CXJitCall.
903907
*
904-
* \param[in] result The location where the return result will be placed.
908+
* \param result The location where the return result will be placed.
905909
*
906-
* \param[in] args The arguments to pass to the invocation.
910+
* \param args The arguments to pass to the invocation.
907911
*
908-
* \param[in] self The 'this pointer' of the object.
909-
*/
910-
void clang_jitcall_invoke(CXJitCall J, void* result, CXJitCallArgList args,
911-
void* self);
912-
913-
/**
914-
* Creates a trampoline function by using the interpreter and returns a uniform
915-
* interface to call it from compiled code.
912+
* \param n The number of arguments.
916913
*
917-
* \returns a \c CXJitCall.
914+
* \param self The 'this pointer' of the object.
918915
*/
919-
CXJitCall clang_jitcall_makeFunctionCallable(CXScope func);
916+
void clang_jitcall_invoke(CXJitCall J, void* result, void** args,
917+
unsigned int n, void* self);
920918

921919
/**
922920
* @}

lib/Interpreter/CXCppInterOp.cpp

Lines changed: 53 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,14 @@ CXInterpreter clang_createInterpreterFromPtr(TInterp_t I) {
6262
return II;
6363
}
6464

65-
TInterp_t clang_interpreter_getInterpreterAsPtr(CXInterpreter I) {
66-
return getInterpreter(I);
65+
void* clang_interpreter_getUnderlyingInterpreter(CXInterpreter I) {
66+
#ifdef USE_CLING
67+
return nullptr;
68+
#else
69+
auto* interp = getInterpreter(I);
70+
auto* clInterp = &static_cast<clang::Interpreter&>(*interp);
71+
return clInterp;
72+
#endif // USE_CLING
6773
}
6874

6975
TInterp_t clang_interpreter_takeInterpreterAsPtr(CXInterpreter I) {
@@ -251,8 +257,16 @@ bool clang_scope_isPODType(CXQualType type) {
251257
}
252258

253259
CXQualType clang_qualtype_getIntegerTypeFromEnumType(CXQualType type) {
254-
const void* Ptr = Cpp::GetIntegerTypeFromEnumType(type.data);
255-
return makeCXQualType(getMeta(type), clang::QualType::getFromOpaquePtr(Ptr));
260+
const clang::QualType QT = getType(type);
261+
if (QT.isNull())
262+
return makeCXQualType(getMeta(type), clang::QualType(), CXType_Invalid);
263+
264+
if (auto* ET = QT->getAs<clang::EnumType>())
265+
return makeCXQualType(
266+
getMeta(type),
267+
ET->getDecl()->getIntegerType()); // TODO: expose type kind?
268+
269+
return makeCXQualType(getMeta(type), clang::QualType(), CXType_Invalid);
256270
}
257271

258272
CXQualType clang_qualtype_getUnderlyingType(CXQualType type) {
@@ -627,11 +641,11 @@ CXScope clang_scope_getUnderlyingScope(CXScope S) {
627641
return S;
628642

629643
const clang::QualType QT = TND->getUnderlyingType();
630-
auto* D = Cpp::GetScopeFromType(QT.getAsOpaquePtr());
631-
if (!D)
644+
auto D = clang_scope_getScopeFromType(makeCXQualType(getMeta(S), QT));
645+
if (isNull(D))
632646
return S;
633647

634-
return makeCXScope(getMeta(S), static_cast<clang::Decl*>(D));
648+
return D;
635649
}
636650

637651
CXScope clang_scope_getScope(const char* name, CXScope parent) {
@@ -676,24 +690,36 @@ CXScope clang_scope_getNamed(const char* name, CXScope parent) {
676690
return makeCXScope(getMeta(parent), nullptr, CXScope_Invalid);
677691
}
678692

679-
CXScope clang_scope_getParentScope(CXScope parent) {
680-
auto* D = getDecl(parent);
693+
CXScope clang_scope_getParentScope(CXScope scope) {
694+
auto* D = getDecl(scope);
681695

682696
if (llvm::isa_and_nonnull<clang::TranslationUnitDecl>(D))
683-
return makeCXScope(getMeta(parent), nullptr, CXScope_Invalid);
697+
return makeCXScope(getMeta(scope), nullptr, CXScope_Invalid);
684698

685699
const auto* ParentDC = D->getDeclContext();
686700
if (!ParentDC)
687-
return makeCXScope(getMeta(parent), nullptr, CXScope_Invalid);
701+
return makeCXScope(getMeta(scope), nullptr, CXScope_Invalid);
688702

689703
auto* CD = clang::Decl::castFromDeclContext(ParentDC)->getCanonicalDecl();
690704

691-
return makeCXScope(getMeta(parent), CD);
705+
return makeCXScope(getMeta(scope), CD);
692706
}
693707

694708
CXScope clang_scope_getScopeFromType(CXQualType type) {
695-
auto* D = Cpp::GetScopeFromType(type.data);
696-
return makeCXScope(getMeta(type), static_cast<clang::Decl*>(D));
709+
const clang::QualType QT = getType(type);
710+
if (auto* Type = QT.getCanonicalType().getTypePtrOrNull()) {
711+
Type = Type->getPointeeOrArrayElementType();
712+
Type = Type->getUnqualifiedDesugaredType();
713+
if (auto* ET = llvm::dyn_cast<clang::EnumType>(Type))
714+
return makeCXScope(getMeta(type), ET->getDecl(), CXScope_Enum);
715+
716+
if (auto* FnType = llvm::dyn_cast<clang::FunctionProtoType>(Type))
717+
Type = const_cast<clang::Type*>(FnType->getReturnType().getTypePtr());
718+
719+
auto* CXXRD = Type->getAsCXXRecordDecl();
720+
return makeCXScope(getMeta(type), CXXRD, CXScope_CXXRecord);
721+
}
722+
return makeCXScope(getMeta(type), nullptr, CXScope_Invalid);
697723
}
698724

699725
size_t clang_scope_getNumBases(CXScope S) {
@@ -1343,6 +1369,16 @@ void clang_destruct(CXObject This, CXScope S, bool withFree) {
13431369
Cpp::DestructImpl(*getInterpreter(S), This, getDecl(S), withFree);
13441370
}
13451371

1372+
CXJitCall clang_jitcall_create(CXScope func) {
1373+
auto J = Cpp::MakeFunctionCallableImpl(getInterpreter(func), getDecl(func));
1374+
auto Ptr = std::make_unique<Cpp::JitCall>(J);
1375+
return reinterpret_cast<CXJitCall>(Ptr.release()); // NOLINT(*-cast)
1376+
}
1377+
1378+
void clang_jitcall_dispose(CXJitCall J) {
1379+
delete reinterpret_cast<Cpp::JitCall*>(J); // NOLINT(*-owning-memory, *-cast)
1380+
}
1381+
13461382
CXJitCallKind clang_jitcall_getKind(CXJitCall J) {
13471383
const auto* call = reinterpret_cast<Cpp::JitCall*>(J); // NOLINT(*-cast)
13481384
return static_cast<CXJitCallKind>(call->getKind());
@@ -1352,18 +1388,8 @@ bool clang_jitcall_isValid(CXJitCall J) {
13521388
return reinterpret_cast<Cpp::JitCall*>(J)->isValid(); // NOLINT(*-cast)
13531389
}
13541390

1355-
void clang_jitcall_invoke(CXJitCall J, void* result, CXJitCallArgList args,
1356-
void* self) {
1391+
void clang_jitcall_invoke(CXJitCall J, void* result, void** args,
1392+
unsigned int n, void* self) {
13571393
const auto* call = reinterpret_cast<Cpp::JitCall*>(J); // NOLINT(*-cast)
1358-
call->Invoke(result, {args.data, args.numArgs}, self);
1359-
}
1360-
1361-
CXJitCall clang_jitcall_makeFunctionCallable(CXScope func) {
1362-
auto J = Cpp::MakeFunctionCallableImpl(getInterpreter(func), getDecl(func));
1363-
auto Ptr = std::make_unique<Cpp::JitCall>(J);
1364-
return reinterpret_cast<CXJitCall>(Ptr.release()); // NOLINT(*-cast)
1365-
}
1366-
1367-
void clang_jitcall_dispose(CXJitCall J) {
1368-
delete reinterpret_cast<Cpp::JitCall*>(J); // NOLINT(*-owning-memory, *-cast)
1394+
call->Invoke(result, {args, n}, self);
13691395
}

0 commit comments

Comments
 (0)