diff options
| -rw-r--r-- | clang/include/clang-c/Index.h | 19 | ||||
| -rw-r--r-- | clang/test/Index/get-cursor.m | 11 | ||||
| -rw-r--r-- | clang/tools/c-index-test/c-index-test.c | 13 | ||||
| -rw-r--r-- | clang/tools/libclang/CIndex.cpp | 29 | ||||
| -rw-r--r-- | clang/tools/libclang/libclang.exports | 1 |
5 files changed, 72 insertions, 1 deletions
diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h index c50ac1b6d24..bb2cbe30e3a 100644 --- a/clang/include/clang-c/Index.h +++ b/clang/include/clang-c/Index.h @@ -32,7 +32,7 @@ * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable. */ #define CINDEX_VERSION_MAJOR 0 -#define CINDEX_VERSION_MINOR 38 +#define CINDEX_VERSION_MINOR 39 #define CINDEX_VERSION_ENCODE(major, minor) ( \ ((major) * 10000) \ @@ -4081,6 +4081,23 @@ CINDEX_LINKAGE unsigned clang_Cursor_isObjCOptional(CXCursor C); CINDEX_LINKAGE unsigned clang_Cursor_isVariadic(CXCursor C); /** + * \brief Returns non-zero if the given cursor points to a symbol marked with + * external_source_symbol attribute. + * + * \param language If non-NULL, and the attribute is present, will be set to + * the 'language' string from the attribute. + * + * \param definedIn If non-NULL, and the attribute is present, will be set to + * the 'definedIn' string from the attribute. + * + * \param isGenerated If non-NULL, and the attribute is present, will be set to + * non-zero is the 'generated_declaration' is set in the attribute. + */ +CINDEX_LINKAGE unsigned clang_Cursor_isExternalSymbol(CXCursor C, + CXString *language, CXString *definedIn, + unsigned *isGenerated); + +/** * \brief Given a cursor that represents a declaration, return the associated * comment's source range. The range may include multiple consecutive comments * with whitespace in between. diff --git a/clang/test/Index/get-cursor.m b/clang/test/Index/get-cursor.m index af277d45fdf..e85d49fb0c3 100644 --- a/clang/test/Index/get-cursor.m +++ b/clang/test/Index/get-cursor.m @@ -154,6 +154,12 @@ SomeT someVar; typedef MY_TYPE2(SomeT2) { int x; }; SomeT2 someVar2; +#define GEN_DECL(mod_name) __attribute__((external_source_symbol(language="Swift", defined_in=mod_name, generated_declaration))) + +GEN_DECL("some_module") +@interface ExtCls +-(void)method; +@end // RUN: c-index-test -cursor-at=%s:4:28 -cursor-at=%s:5:28 %s | FileCheck -check-prefix=CHECK-PROP %s // CHECK-PROP: ObjCPropertyDecl=foo1:4:26 @@ -226,3 +232,8 @@ SomeT2 someVar2; // CHECK-TRANSPARENT: 147:1 TypeRef=TokenPaste_t:144:9 Extent=[147:1 - 147:13] Spelling=TokenPaste_t ([147:1 - 147:13]) // CHECK-TRANSPARENT: 151:1 TypeRef=SomeT:150:17 (Transparent: struct SomeT) Extent=[151:1 - 151:6] Spelling=SomeT ([151:1 - 151:6]) // CHECK-TRANSPARENT: 155:1 TypeRef=SomeT2:154:18 Extent=[155:1 - 155:7] Spelling=SomeT2 ([155:1 - 155:7]) + +// RUN: c-index-test -cursor-at=%s:160:12 -cursor-at=%s:161:8 %s | FileCheck -check-prefix=CHECK-EXTERNAL %s +// CHECK-EXTERNAL: 160:12 ObjCInterfaceDecl=ExtCls:160:12 (external lang: Swift, defined: some_module, gen: 1) +// CHECK-EXTERNAL: 161:8 ObjCInstanceMethodDecl=method:161:8 (external lang: Swift, defined: some_module, gen: 1) +C
\ No newline at end of file diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c index 1179fbf3911..1f5d6044319 100644 --- a/clang/tools/c-index-test/c-index-test.c +++ b/clang/tools/c-index-test/c-index-test.c @@ -809,6 +809,19 @@ static void PrintCursor(CXCursor Cursor, const char *CommentSchemaFile) { if (clang_Cursor_isObjCOptional(Cursor)) printf(" (@optional)"); + { + CXString language; + CXString definedIn; + unsigned generated; + if (clang_Cursor_isExternalSymbol(Cursor, &language, &definedIn, + &generated)) { + printf(" (external lang: %s, defined: %s, gen: %d)", + clang_getCString(language), clang_getCString(definedIn), generated); + clang_disposeString(language); + clang_disposeString(definedIn); + } + } + if (Cursor.kind == CXCursor_IBOutletCollectionAttr) { CXType T = clang_getCanonicalType(clang_getIBOutletCollectionType(Cursor)); diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp index c251d83e209..9c795ae9c5b 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -7479,6 +7479,35 @@ unsigned clang_Cursor_isVariadic(CXCursor C) { return 0; } +unsigned clang_Cursor_isExternalSymbol(CXCursor C, + CXString *language, CXString *definedIn, + unsigned *isGenerated) { + if (!clang_isDeclaration(C.kind)) + return 0; + + const Decl *D = getCursorDecl(C); + + auto getExternalSymAttr = [](const Decl *D) -> ExternalSourceSymbolAttr* { + if (auto *attr = D->getAttr<ExternalSourceSymbolAttr>()) + return attr; + if (auto *dcd = dyn_cast<Decl>(D->getDeclContext())) { + if (auto *attr = dcd->getAttr<ExternalSourceSymbolAttr>()) + return attr; + } + return nullptr; + }; + if (auto *attr = getExternalSymAttr(D)) { + if (language) + *language = cxstring::createDup(attr->getLanguage()); + if (definedIn) + *definedIn = cxstring::createDup(attr->getDefinedIn()); + if (isGenerated) + *isGenerated = attr->getGeneratedDeclaration(); + return 1; + } + return 0; +} + CXSourceRange clang_Cursor_getCommentRange(CXCursor C) { if (!clang_isDeclaration(C.kind)) return clang_getNullRange(); diff --git a/clang/tools/libclang/libclang.exports b/clang/tools/libclang/libclang.exports index 895dd804b00..d9a406e5741 100644 --- a/clang/tools/libclang/libclang.exports +++ b/clang/tools/libclang/libclang.exports @@ -35,6 +35,7 @@ clang_Cursor_getReceiverType clang_Cursor_isAnonymous clang_Cursor_isBitField clang_Cursor_isDynamicCall +clang_Cursor_isExternalSymbol clang_Cursor_isNull clang_Cursor_isObjCOptional clang_Cursor_isVariadic |

