Skip to content

Commit be1340d

Browse files
committedDec 10, 2015
libclang: expose dllexport, dllimport attributes
These attributes were previously unexposed. Expose them through the libclang interfaces. Add tests that cover both the MSVC spelling and the GNU spelling. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@255273 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 6988851 commit be1340d

File tree

6 files changed

+79
-2
lines changed

6 files changed

+79
-2
lines changed
 

‎bindings/python/clang/cindex.py

+3
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,9 @@ def __repr__(self):
11021102

11031103
CursorKind.VISIBILITY_ATTR = CursorKind(417)
11041104

1105+
CursorKind.DLLEXPORT_ATTR = CursorKind(418)
1106+
CursorKind.DLLIMPORT_ATTR = CursorKind(419)
1107+
11051108
###
11061109
# Preprocessing
11071110
CursorKind.PREPROCESSING_DIRECTIVE = CursorKind(500)

‎include/clang-c/Index.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
3333
*/
3434
#define CINDEX_VERSION_MAJOR 0
35-
#define CINDEX_VERSION_MINOR 31
35+
#define CINDEX_VERSION_MINOR 32
3636

3737
#define CINDEX_VERSION_ENCODE(major, minor) ( \
3838
((major) * 10000) \
@@ -2297,7 +2297,9 @@ enum CXCursorKind {
22972297
CXCursor_CUDAHostAttr = 415,
22982298
CXCursor_CUDASharedAttr = 416,
22992299
CXCursor_VisibilityAttr = 417,
2300-
CXCursor_LastAttr = CXCursor_VisibilityAttr,
2300+
CXCursor_DLLExport = 418,
2301+
CXCursor_DLLImport = 419,
2302+
CXCursor_LastAttr = CXCursor_DLLImport,
23012303

23022304
/* Preprocessing */
23032305
CXCursor_PreprocessingDirective = 500,

‎test/Index/index-attrs.c

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: c-index-test -index-file -check-prefix CHECK %s -target armv7-windows-gnu -fdeclspec
2+
3+
void __declspec(dllexport) export_function(void) {}
4+
// CHECK: [indexDeclaraton]: kind: function | name: export_function | {{.*}} | lang: C
5+
// CHECK: <attribute>: attribute(dllexport)
6+
void __attribute__((dllexport)) export_gnu_attribute(void) {}
7+
// CHECK: [indexDeclaration] kind: function | name: export_gnu_attribute | {{.*}} | lang: C
8+
// CHECK: <attribute>: attribute(dllexport)
9+
10+
void __declspec(dllimport) import_function(void);
11+
// CHECK: [indexDeclaration] kind: function | name: import_function | {{.*}} | lang: C
12+
// CHECK: <attribute>: attribute(dllimport)
13+
void __attribute__((dllimport)) import_gnu_attribute(void);
14+
// CHECK: [indexDeclaration] kind: function | name: import_gnu_function | {{.*}} | lang: C
15+
// CHECK: <attribute>: attribute(dllimport)
16+

‎test/Index/index-attrs.cpp

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// RUN: c-index-test -index-file -check-prefix CHECK %s -target armv7-windows-gnu -fdeclspec
2+
3+
struct __declspec(dllexport) export_s {
4+
void m();
5+
};
6+
// CHECK: [indexDeclaration]: kind: struct | name: export_s | {{.*}} | lang: C++
7+
// CHECK: <attribute>: attribute(dllexport)
8+
// CHECK: [indexDeclaration]: kind: c++-instance-method | name: m | {{.*}} | lang: C++
9+
// CHECK: <attribute>: attribute(dllexport)
10+
11+
struct __declspec(dllimport) import_s {
12+
void m();
13+
};
14+
// CHECK: [indexDeclaration]: kind: struct | name: import_s | {{.*}} | lang: C++
15+
// CHECK: <attribute>: attribute(dllimport)
16+
// CHECK: [indexDeclaration]: kind: c++-instance-method | name: m | {{.*}} | lang: C++
17+
// CHECK: <attribute>: attribute(dllimport)
18+
19+
class __attribute__((dllexport)) export_gnu_s {
20+
void m();
21+
};
22+
// CHECK: [indexDeclaration]: kind: struct | name: export_gnu_s | {{.*}} | lang: C++
23+
// CHECK: <attribute>: attribute(dllexport)
24+
// CHECK: [indexDeclaration]: kind: c++-instance-method | name: m | {{.*}} | lang: C++
25+
// CHECK: <attribute>: attribute(dllexport)
26+
27+
class __attribute__((dllimport)) import_gnu_s {
28+
void m();
29+
};
30+
// CHECK: [indexDeclaration]: kind: struct | name: import_gnu_s | {{.*}} | lang: C++
31+
// CHECK: <attribute>: attribute(dllimport)
32+
// CHECK: [indexDeclaration]: kind: c++-instance-method | name: m | {{.*}} | lang: C++
33+
// CHECK: <attribute>: attribute(dllimport)
34+
35+
extern "C" void __declspec(dllexport) export_function(void) {}
36+
// CHECK: [indexDeclaraton]: kind: function | name: export_function | {{.*}} | lang: C
37+
// CHECK: <attribute>: attribute(dllexport)
38+
extern "C" void __attribute__((dllexport)) export_gnu_function(void) {}
39+
// CHECK: [indexDeclaraton]: kind: function | name: export_gnu_function | {{.*}} | lang: C
40+
// CHECK: <attribute>: attribute(dllexport)
41+
42+
extern "C" {
43+
void __declspec(dllimport) import_function(void);
44+
// CHECK: [indexDeclaration] kind: function | name: import_function | {{.*}} | lang: C
45+
// CHECK: <attribute>: attribute(dllimport)
46+
void __attribute__((dllimport)) import_gnu_function(void);
47+
// CHECK: [indexDeclaration] kind: function | name: import_gnu_function | {{.*}} | lang: C
48+
// CHECK: <attribute>: attribute(dllimport)
49+
}
50+

‎tools/libclang/CIndex.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -4389,6 +4389,10 @@ CXString clang_getCursorKindSpelling(enum CXCursorKind Kind) {
43894389
return cxstring::createRef("attribute(shared)");
43904390
case CXCursor_VisibilityAttr:
43914391
return cxstring::createRef("attribute(visibility)");
4392+
case CXCursor_DLLExport:
4393+
return cxstring::createRef("attribute(dllexport)");
4394+
case CXCursor_DLLImport:
4395+
return cxstring::createRef("attribute(dllimport)");
43924396
case CXCursor_PreprocessingDirective:
43934397
return cxstring::createRef("preprocessing directive");
43944398
case CXCursor_MacroDefinition:

‎tools/libclang/CXCursor.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ static CXCursorKind GetCursorKind(const Attr *A) {
5959
case attr::CUDAHost: return CXCursor_CUDAHostAttr;
6060
case attr::CUDAShared: return CXCursor_CUDASharedAttr;
6161
case attr::Visibility: return CXCursor_VisibilityAttr;
62+
case attr::DLLExport: return CXCursor_DLLExport;
63+
case attr::DLLImport: return CXCursor_DLLImport;
6264
}
6365

6466
return CXCursor_UnexposedAttr;

0 commit comments

Comments
 (0)
Please sign in to comment.