@@ -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
6975TInterp_t clang_interpreter_takeInterpreterAsPtr (CXInterpreter I) {
@@ -251,8 +257,16 @@ bool clang_scope_isPODType(CXQualType type) {
251257}
252258
253259CXQualType 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
258272CXQualType 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
637651CXScope 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
694708CXScope 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
699725size_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+
13461382CXJitCallKind 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