@@ -71,7 +71,11 @@ TInterp_t clang_interpreter_takeInterpreterAsPtr(CXInterpreter I) {
7171}
7272
7373enum CXErrorCode clang_interpreter_Undo (CXInterpreter I, unsigned int N) {
74+ #ifdef USE_CLING
75+ return CXError_Failure;
76+ #else
7477 return getInterpreter (I)->Undo (N) ? CXError_Failure : CXError_Success;
78+ #endif // USE_CLING
7579}
7680
7781void clang_interpreter_dispose (CXInterpreter I) {
@@ -286,19 +290,6 @@ CXQualType clang_qualtype_getCanonicalType(CXQualType type) {
286290 return makeCXQualType (getMeta (type), QT.getCanonicalType ());
287291}
288292
289- namespace Cpp {
290- clang::QualType GetType (const std::string& name, clang::Sema& sema);
291- } // namespace Cpp
292-
293- CXQualType clang_qualtype_getType (CXInterpreter I, const char * name) {
294- auto & S = getInterpreter (I)->getSema ();
295- const clang::QualType QT = Cpp::GetType (std::string (name), S);
296- if (QT.isNull ())
297- return makeCXQualType (I, QT, CXType_Invalid);
298-
299- return makeCXQualType (I, QT);
300- }
301-
302293CXQualType clang_qualtype_getComplexType (CXQualType eltype) {
303294 const auto & C = getInterpreter (eltype)->getSema ().getASTContext ();
304295 return makeCXQualType (getMeta (eltype), C.getComplexType (getType (eltype)));
@@ -353,6 +344,28 @@ static inline compat::Interpreter* getInterpreter(const CXScope& S) {
353344
354345void clang_scope_dump (CXScope S) { getDecl (S)->dump (); }
355346
347+ namespace Cpp {
348+ clang::QualType GetBuiltinType (const std::string& name, clang::Sema& sema);
349+ } // namespace Cpp
350+
351+ CXQualType clang_qualtype_getType (CXInterpreter I, const char * name) {
352+ auto & S = getInterpreter (I)->getSema ();
353+ const clang::QualType builtin = Cpp::GetBuiltinType (std::string (name), S);
354+ if (!builtin.isNull ())
355+ return makeCXQualType (I, builtin);
356+
357+ auto scope = clang_scope_getNamed (name, clang_scope_getGlobalScope (I));
358+ if (isNull (scope))
359+ return makeCXQualType (I, clang::QualType (), CXType_Invalid);
360+
361+ if (auto * TD = llvm::dyn_cast_or_null<clang::TypeDecl>(getDecl (scope))) {
362+ auto QT = clang::QualType (TD->getTypeForDecl (), 0 );
363+ return makeCXQualType (I, QT);
364+ }
365+
366+ return makeCXQualType (I, clang::QualType (), CXType_Invalid);
367+ }
368+
356369CXQualType clang_scope_getTypeFromScope (CXScope S) {
357370 if (isNull (S))
358371 return makeCXQualType (getMeta (S), clang::QualType (), CXType_Invalid);
@@ -605,7 +618,7 @@ CXScopeSet* clang_scope_getUsingNamespaces(CXScope S) {
605618CXScope clang_scope_getGlobalScope (CXInterpreter I) {
606619 const auto & C = getInterpreter (I)->getSema ().getASTContext ();
607620 auto * DC = C.getTranslationUnitDecl ();
608- return makeCXScope (I, DC, CXScope_Global );
621+ return makeCXScope (I, DC, CXScope_TranslationUnit );
609622}
610623
611624CXScope clang_scope_getUnderlyingScope (CXScope S) {
@@ -627,11 +640,21 @@ CXScope clang_scope_getScope(const char* name, CXScope parent) {
627640 return S;
628641
629642 auto * ND = llvm::dyn_cast<clang::NamedDecl>(getDecl (S));
630- if (llvm::isa<clang::NamespaceDecl>(ND) || llvm::isa<clang::RecordDecl>(ND) ||
631- llvm::isa<clang::ClassTemplateDecl>(ND) ||
632- llvm::isa<clang::TypedefNameDecl>(ND)) {
633- return makeCXScope (getMeta (S), ND->getCanonicalDecl ());
634- }
643+ if (llvm::isa<clang::NamespaceDecl>(ND))
644+ return makeCXScope (getMeta (S), ND->getCanonicalDecl (), CXScope_Namespace);
645+
646+ if (llvm::isa<clang::TypedefDecl>(ND))
647+ return makeCXScope (getMeta (S), ND->getCanonicalDecl (), CXScope_Typedef);
648+
649+ if (llvm::isa<clang::TypeAliasDecl>(ND))
650+ return makeCXScope (getMeta (S), ND->getCanonicalDecl (), CXScope_TypeAlias);
651+
652+ if (llvm::isa<clang::RecordDecl>(ND))
653+ return makeCXScope (getMeta (S), ND->getCanonicalDecl (), CXScope_Record);
654+
655+ if (llvm::isa<clang::ClassTemplateDecl>(ND))
656+ return makeCXScope (getMeta (S), ND->getCanonicalDecl (),
657+ CXScope_ClassTemplate);
635658
636659 return S;
637660}
0 commit comments