From: Chandler Carruth Date: Thu, 14 Jul 2011 08:41:15 +0000 (+0000) Subject: Update all of the libclang code corresponding to the preprocessor X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9b2a0ac970a077bdc0bf08c6c682f80ad733c892;p=clang Update all of the libclang code corresponding to the preprocessor MacroInstantiation -> MacroExpansion rename. Internally, everything is switched. Introduce a new cursor kind enum with the new name, but retain the old name as an alias so that we don't break backwards compatibility. Also update the debug printing routine to use 'macro expansions' as its explicitly not guaranteed to be stable, and mechanically switch the test cases over to that. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135140 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h index bfcc88244a..858b2ce4fc 100644 --- a/include/clang-c/Index.h +++ b/include/clang-c/Index.h @@ -1421,7 +1421,8 @@ enum CXCursorKind { /* Preprocessing */ CXCursor_PreprocessingDirective = 500, CXCursor_MacroDefinition = 501, - CXCursor_MacroInstantiation = 502, + CXCursor_MacroExpansion = 502, + CXCursor_MacroInstantiation = CXCursor_MacroExpansion, CXCursor_InclusionDirective = 503, CXCursor_FirstPreprocessing = CXCursor_PreprocessingDirective, CXCursor_LastPreprocessing = CXCursor_InclusionDirective diff --git a/test/Index/annotate-tokens-pp.c b/test/Index/annotate-tokens-pp.c index 01a615f0e4..e6bb0869d0 100644 --- a/test/Index/annotate-tokens-pp.c +++ b/test/Index/annotate-tokens-pp.c @@ -53,14 +53,14 @@ void test() { // CHECK: Identifier: "X" [4:22 - 4:23] macro definition=WIBBLE // CHECK: Punctuation: "##" [4:23 - 4:25] macro definition=WIBBLE // CHECK: Identifier: "Y" [4:25 - 4:26] macro definition=WIBBLE -// CHECK: Identifier: "NOTHING" [5:1 - 5:8] macro instantiation=NOTHING:1:9 +// CHECK: Identifier: "NOTHING" [5:1 - 5:8] macro expansion=NOTHING:1:9 // CHECK: Punctuation: "(" [5:8 - 5:9] // CHECK: Identifier: "more" [5:9 - 5:13] // CHECK: Punctuation: "," [5:13 - 5:14] // CHECK: Identifier: "junk" [5:14 - 5:18] // CHECK: Punctuation: ")" [5:18 - 5:19] // CHECK: Keyword: "float" [5:20 - 5:25] -// CHECK: Identifier: "WIBBLE" [5:26 - 5:32] macro instantiation=WIBBLE:4:9 +// CHECK: Identifier: "WIBBLE" [5:26 - 5:32] macro expansion=WIBBLE:4:9 // CHECK: Punctuation: "(" [5:32 - 5:33] // CHECK: Keyword: "int" [5:33 - 5:36] // CHECK: Punctuation: "," [5:36 - 5:37] @@ -68,8 +68,8 @@ void test() { // CHECK: Punctuation: ")" [5:43 - 5:44] // CHECK: Punctuation: ";" [5:44 - 5:45] // CHECK: Keyword: "int" [6:1 - 6:4] -// CHECK: Identifier: "BAR" [6:5 - 6:8] macro instantiation=BAR:3:9 -// CHECK: Identifier: "STILL_NOTHING" [6:9 - 6:22] macro instantiation=STILL_NOTHING:2:9 +// CHECK: Identifier: "BAR" [6:5 - 6:8] macro expansion=BAR:3:9 +// CHECK: Identifier: "STILL_NOTHING" [6:9 - 6:22] macro expansion=STILL_NOTHING:2:9 // CHECK: Punctuation: ";" [6:22 - 6:23] // CHECK: Punctuation: "#" [7:1 - 7:2] inclusion directive=foo.h // CHECK: Identifier: "include" [7:2 - 7:9] inclusion directive=foo.h @@ -115,7 +115,7 @@ void test() { // CHECK: Keyword: "int" [16:3 - 16:6] VarDecl=k:16:7 (Definition) // CHECK: Identifier: "k" [16:7 - 16:8] VarDecl=k:16:7 (Definition) // CHECK: Punctuation: "=" [16:9 - 16:10] VarDecl=k:16:7 (Definition) -// CHECK: Identifier: "REVERSE_MACRO" [16:11 - 16:24] macro instantiation=REVERSE_MACRO:10:9 +// CHECK: Identifier: "REVERSE_MACRO" [16:11 - 16:24] macro expansion=REVERSE_MACRO:10:9 // CHECK: Punctuation: "(" [16:24 - 16:25] UnexposedStmt= // CHECK: Identifier: "t" [16:25 - 16:26] DeclRefExpr=t:15:7 // CHECK: Punctuation: "," [16:26 - 16:27] UnexposedStmt= @@ -125,7 +125,7 @@ void test() { // CHECK: Keyword: "int" [17:3 - 17:6] VarDecl=j:17:7 (Definition) // CHECK: Identifier: "j" [17:7 - 17:8] VarDecl=j:17:7 (Definition) // CHECK: Punctuation: "=" [17:9 - 17:10] VarDecl=j:17:7 (Definition) -// CHECK: Identifier: "TWICE_MACRO" [17:11 - 17:22] macro instantiation=TWICE_MACRO:11:9 +// CHECK: Identifier: "TWICE_MACRO" [17:11 - 17:22] macro expansion=TWICE_MACRO:11:9 // CHECK: Punctuation: "(" [17:22 - 17:23] UnexposedStmt= // CHECK: Identifier: "k" [17:23 - 17:24] DeclRefExpr=k:16:7 // CHECK: Punctuation: "+" [17:25 - 17:26] UnexposedStmt= @@ -170,7 +170,7 @@ void test() { // CHECK: Punctuation: "=" [24:9 - 24:10] VarDecl=x:24:7 (Definition) // CHECK: Literal: "10" [24:11 - 24:13] UnexposedExpr= // CHECK: Punctuation: ";" [24:13 - 24:14] UnexposedStmt= -// CHECK: Identifier: "fun_with_macro_bodies" [25:3 - 25:24] macro instantiation=fun_with_macro_bodies:21:9 +// CHECK: Identifier: "fun_with_macro_bodies" [25:3 - 25:24] macro expansion=fun_with_macro_bodies:21:9 // CHECK: Punctuation: "(" [25:24 - 25:25] UnexposedStmt= // CHECK: Identifier: "x" [25:25 - 25:26] DeclRefExpr=x:24:7 // CHECK: Punctuation: "," [25:26 - 25:27] UnexposedStmt= diff --git a/test/Index/annotate-tokens.m b/test/Index/annotate-tokens.m index 4f6b4b9dc8..1dc7621232 100644 --- a/test/Index/annotate-tokens.m +++ b/test/Index/annotate-tokens.m @@ -227,7 +227,7 @@ static Rdar8595462_A * Rdar8595462_staticVar; // CHECK: Identifier: "IBActionTests" [32:12 - 32:25] ObjCInterfaceDecl=IBActionTests:32:12 // CHECK: Punctuation: "-" [33:1 - 33:2] ObjCInstanceMethodDecl=actionMethod::33:1 // CHECK: Punctuation: "(" [33:3 - 33:4] ObjCInstanceMethodDecl=actionMethod::33:1 -// CHECK: Identifier: "IBAction" [33:4 - 33:12] macro instantiation=IBAction +// CHECK: Identifier: "IBAction" [33:4 - 33:12] macro expansion=IBAction // CHECK: Punctuation: ")" [33:12 - 33:13] ObjCInstanceMethodDecl=actionMethod::33:1 // CHECK: Identifier: "actionMethod" [33:14 - 33:26] ObjCInstanceMethodDecl=actionMethod::33:1 // CHECK: Punctuation: ":" [33:26 - 33:27] ObjCInstanceMethodDecl=actionMethod::33:1 @@ -262,7 +262,7 @@ static Rdar8595462_A * Rdar8595462_staticVar; // CHECK: Identifier: "IBActionTests" [37:17 - 37:30] ObjCImplementationDecl=IBActionTests:37:1 (Definition) // CHECK: Punctuation: "-" [38:1 - 38:2] ObjCInstanceMethodDecl=actionMethod::38:1 (Definition) // CHECK: Punctuation: "(" [38:3 - 38:4] ObjCInstanceMethodDecl=actionMethod::38:1 (Definition) -// CHECK: Identifier: "IBAction" [38:4 - 38:12] macro instantiation=IBAction +// CHECK: Identifier: "IBAction" [38:4 - 38:12] macro expansion=IBAction // CHECK: Punctuation: ")" [38:12 - 38:13] ObjCInstanceMethodDecl=actionMethod::38:1 (Definition) // CHECK: Identifier: "actionMethod" [38:14 - 38:26] ObjCInstanceMethodDecl=actionMethod::38:1 (Definition) // CHECK: Punctuation: ":" [38:26 - 38:27] ObjCInstanceMethodDecl=actionMethod::38:1 (Definition) @@ -306,7 +306,7 @@ static Rdar8595462_A * Rdar8595462_staticVar; // CHECK: Keyword: "interface" [51:2 - 51:11] ObjCInterfaceDecl=IBOutletTests:51:12 // CHECK: Identifier: "IBOutletTests" [51:12 - 51:25] ObjCInterfaceDecl=IBOutletTests:51:12 // CHECK: Punctuation: "{" [52:1 - 52:2] ObjCInterfaceDecl=IBOutletTests:51:12 -// CHECK: Identifier: "IBOutlet" [53:5 - 53:13] macro instantiation=IBOutlet +// CHECK: Identifier: "IBOutlet" [53:5 - 53:13] macro expansion=IBOutlet // CHECK: Keyword: "char" [53:14 - 53:18] ObjCIvarDecl=anOutlet:53:21 (Definition) // CHECK: Punctuation: "*" [53:19 - 53:20] ObjCIvarDecl=anOutlet:53:21 (Definition) // CHECK: Identifier: "anOutlet" [53:21 - 53:29] ObjCIvarDecl=anOutlet:53:21 (Definition) @@ -314,7 +314,7 @@ static Rdar8595462_A * Rdar8595462_staticVar; // CHECK: Punctuation: "}" [54:1 - 54:2] ObjCInterfaceDecl=IBOutletTests:51:12 // CHECK: Punctuation: "-" [55:1 - 55:2] ObjCInstanceMethodDecl=actionMethod::55:1 // CHECK: Punctuation: "(" [55:3 - 55:4] ObjCInstanceMethodDecl=actionMethod::55:1 -// CHECK: Identifier: "IBAction" [55:4 - 55:12] macro instantiation=IBAction +// CHECK: Identifier: "IBAction" [55:4 - 55:12] macro expansion=IBAction // CHECK: Punctuation: ")" [55:12 - 55:13] ObjCInstanceMethodDecl=actionMethod::55:1 // CHECK: Identifier: "actionMethod" [55:14 - 55:26] ObjCInstanceMethodDecl=actionMethod::55:1 // CHECK: Punctuation: ":" [55:26 - 55:27] ObjCInstanceMethodDecl=actionMethod::55:1 @@ -325,7 +325,7 @@ static Rdar8595462_A * Rdar8595462_staticVar; // CHECK: Punctuation: ";" [55:34 - 55:35] ObjCInstanceMethodDecl=actionMethod::55:1 // CHECK: Punctuation: "@" [56:1 - 56:2] ObjCPropertyDecl=aPropOutlet:56:26 // CHECK: Keyword: "property" [56:2 - 56:10] ObjCPropertyDecl=aPropOutlet:56:26 -// CHECK: Identifier: "IBOutlet" [56:11 - 56:19] macro instantiation=IBOutlet +// CHECK: Identifier: "IBOutlet" [56:11 - 56:19] macro expansion=IBOutlet // CHECK: Keyword: "int" [56:20 - 56:23] ObjCPropertyDecl=aPropOutlet:56:26 // CHECK: Punctuation: "*" [56:24 - 56:25] ObjCPropertyDecl=aPropOutlet:56:26 // CHECK: Identifier: "aPropOutlet" [56:26 - 56:37] ObjCPropertyDecl=aPropOutlet:56:26 @@ -389,7 +389,7 @@ static Rdar8595462_A * Rdar8595462_staticVar; // CHECK: Identifier: "self" [76:18 - 76:22] DeclRefExpr=self:0:0 // CHECK: Identifier: "foo" [76:23 - 76:26] ObjCMessageExpr=foo::66:1 // CHECK: Punctuation: ":" [76:26 - 76:27] ObjCMessageExpr=foo::66:1 -// CHECK: Identifier: "VAL" [76:27 - 76:30] macro instantiation=VAL:63:9 +// CHECK: Identifier: "VAL" [76:27 - 76:30] macro expansion=VAL:63:9 // CHECK: Punctuation: "]" [76:30 - 76:31] ObjCMessageExpr=foo::66:1 // CHECK: Punctuation: ";" [76:31 - 76:32] UnexposedStmt= // CHECK: Keyword: "int" [77:5 - 77:8] VarDecl=second:77:9 (Definition) diff --git a/test/Index/c-index-getCursor-pp.c b/test/Index/c-index-getCursor-pp.c index 8f986912cd..df61ec0329 100644 --- a/test/Index/c-index-getCursor-pp.c +++ b/test/Index/c-index-getCursor-pp.c @@ -18,15 +18,15 @@ B(int x); // RUN: c-index-test -cursor-at=%s:2:14 -I%S/Inputs %s | FileCheck -check-prefix=CHECK-2 %s // CHECK-2: macro definition=DECORATION // RUN: c-index-test -cursor-at=%s:5:7 -I%S/Inputs %s | FileCheck -check-prefix=CHECK-3 %s -// CHECK-3: macro instantiation=OBSCURE:1:9 +// CHECK-3: macro expansion=OBSCURE:1:9 // RUN: c-index-test -cursor-at=%s:6:6 -I%S/Inputs %s | FileCheck -check-prefix=CHECK-4 %s -// CHECK-4: macro instantiation=OBSCURE:1:9 +// CHECK-4: macro expansion=OBSCURE:1:9 // RUN: c-index-test -cursor-at=%s:6:19 -I%S/Inputs %s | FileCheck -check-prefix=CHECK-5 %s -// CHECK-5: macro instantiation=DECORATION:2:9 +// CHECK-5: macro expansion=DECORATION:2:9 // RUN: c-index-test -cursor-at=%s:9:10 -I%S/Inputs %s | FileCheck -check-prefix=CHECK-6 %s // CHECK-6: inclusion directive=a.h // RUN: c-index-test -cursor-at=%s:14:1 -I%S/Inputs %s | FileCheck -check-prefix=CHECK-7 %s -// CHECK-7: macro instantiation=B:12:9 +// CHECK-7: macro expansion=B:12:9 // Same tests, but with "editing" optimizations // RUN: env CINDEXTEST_EDITING=1 c-index-test -cursor-at=%s:1:11 -I%S/Inputs %s | FileCheck -check-prefix=CHECK-1 %s diff --git a/test/Index/c-index-getCursor-test.m b/test/Index/c-index-getCursor-test.m index c2ff6963c9..6df8c1abfe 100644 --- a/test/Index/c-index-getCursor-test.m +++ b/test/Index/c-index-getCursor-test.m @@ -165,4 +165,4 @@ void f() { // CHECK: [55:9 - 55:26] macro definition=CONCAT // CHECK: [57:1 - 57:10] FunctionDecl=f:57:6 (Definition) // CHECK: [58:4 - 58:8] VarDecl=my_var:58:8 (Definition) -// CHECK: [58:8 - 58:14] macro instantiation=CONCAT:55:9 +// CHECK: [58:8 - 58:14] macro expansion=CONCAT:55:9 diff --git a/test/Index/nested-macro-instantiations.cpp b/test/Index/nested-macro-instantiations.cpp index d0c9bbb1e7..9d0c0521f4 100644 --- a/test/Index/nested-macro-instantiations.cpp +++ b/test/Index/nested-macro-instantiations.cpp @@ -7,14 +7,14 @@ WIBBLE(int x); // RUN: env CINDEXTEST_NESTED_MACROS=1 c-index-test -test-load-source all %s | FileCheck -check-prefix CHECK-WITH-NESTED %s // RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_NESTED_MACROS=1 c-index-test -test-load-source all %s | FileCheck -check-prefix CHECK-WITH-NESTED %s // RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_NESTED_MACROS=1 c-index-test -test-load-source-reparse 5 all %s | FileCheck -check-prefix CHECK-WITH-NESTED %s -// CHECK-WITH-NESTED: nested-macro-instantiations.cpp:5:1: macro instantiation=WIBBLE:3:9 Extent=[5:1 - 5:7] -// CHECK-WITH-NESTED: nested-macro-instantiations.cpp:3:19: macro instantiation=BAR:2:9 Extent=[3:19 - 5:14] -// CHECK-WITH-NESTED: nested-macro-instantiations.cpp:2:16: macro instantiation=FOO:1:9 Extent=[2:16 - 5:14] +// CHECK-WITH-NESTED: nested-macro-instantiations.cpp:5:1: macro expansion=WIBBLE:3:9 Extent=[5:1 - 5:7] +// CHECK-WITH-NESTED: nested-macro-instantiations.cpp:3:19: macro expansion=BAR:2:9 Extent=[3:19 - 5:14] +// CHECK-WITH-NESTED: nested-macro-instantiations.cpp:2:16: macro expansion=FOO:1:9 Extent=[2:16 - 5:14] // CHECK-WITH-NESTED: nested-macro-instantiations.cpp:5:1: VarDecl=x:5:1 (Definition) Extent=[5:1 - 5:14] // RUN: c-index-test -test-load-source all %s | FileCheck -check-prefix CHECK-WITHOUT-NESTED %s // RUN: env CINDEXTEST_EDITING=1 c-index-test -test-load-source all %s | FileCheck -check-prefix CHECK-WITHOUT-NESTED %s // RUN: env CINDEXTEST_EDITING=1 c-index-test -test-load-source-reparse 5 all %s | FileCheck -check-prefix CHECK-WITHOUT-NESTED %s -// CHECK-WITHOUT-NESTED: nested-macro-instantiations.cpp:5:1: macro instantiation=WIBBLE:3:9 Extent=[5:1 - 5:7] -// CHECK-WITHOUT-NESTED-NOT: nested-macro-instantiations.cpp:3:19: macro instantiation=BAR:2:9 Extent=[3:19 - 5:14] +// CHECK-WITHOUT-NESTED: nested-macro-instantiations.cpp:5:1: macro expansion=WIBBLE:3:9 Extent=[5:1 - 5:7] +// CHECK-WITHOUT-NESTED-NOT: nested-macro-instantiations.cpp:3:19: macro expansion=BAR:2:9 Extent=[3:19 - 5:14] // CHECK-WITHOUT-NESTED: nested-macro-instantiations.cpp:5:1: VarDecl=x:5:1 (Definition) Extent=[5:1 - 5:14] diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index e85b94f4f7..02ef6f82c2 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -3151,7 +3151,7 @@ CXString clang_getCursorSpelling(CXCursor C) { return createCXString(""); } - if (C.kind == CXCursor_MacroInstantiation) + if (C.kind == CXCursor_MacroExpansion) return createCXString(getCursorMacroExpansion(C)->getName() ->getNameStart()); @@ -3352,8 +3352,8 @@ CXString clang_getCursorKindSpelling(enum CXCursorKind Kind) { return createCXString("preprocessing directive"); case CXCursor_MacroDefinition: return createCXString("macro definition"); - case CXCursor_MacroInstantiation: - return createCXString("macro instantiation"); + case CXCursor_MacroExpansion: + return createCXString("macro expansion"); case CXCursor_InclusionDirective: return createCXString("inclusion directive"); case CXCursor_Namespace: @@ -3672,7 +3672,7 @@ CXSourceLocation clang_getCursorLocation(CXCursor C) { return cxloc::translateSourceLocation(getCursorContext(C), L); } - if (C.kind == CXCursor_MacroInstantiation) { + if (C.kind == CXCursor_MacroExpansion) { SourceLocation L = cxcursor::getCursorMacroExpansion(C)->getSourceRange().getBegin(); return cxloc::translateSourceLocation(getCursorContext(C), L); @@ -3759,7 +3759,7 @@ static SourceRange getRawCursorExtent(CXCursor C) { if (C.kind == CXCursor_PreprocessingDirective) return cxcursor::getCursorPreprocessingDirective(C); - if (C.kind == CXCursor_MacroInstantiation) + if (C.kind == CXCursor_MacroExpansion) return cxcursor::getCursorMacroExpansion(C)->getSourceRange(); if (C.kind == CXCursor_MacroDefinition) @@ -3876,7 +3876,7 @@ CXCursor clang_getCursorReferenced(CXCursor C) { return clang_getNullCursor(); } - if (C.kind == CXCursor_MacroInstantiation) { + if (C.kind == CXCursor_MacroExpansion) { if (MacroDefinition *Def = getCursorMacroExpansion(C)->getDefinition()) return MakeMacroDefinitionCursor(Def, tu); } @@ -3945,7 +3945,7 @@ CXCursor clang_getCursorDefinition(CXCursor C) { WasReference = true; } - if (C.kind == CXCursor_MacroInstantiation) + if (C.kind == CXCursor_MacroExpansion) return clang_getCursorReferenced(C); if (!clang_isDeclaration(C.kind)) @@ -4543,7 +4543,7 @@ AnnotateTokensWorker::Visit(CXCursor cursor, CXCursor parent) { if (clang_isPreprocessing(cursor.kind)) { // For macro instantiations, just note where the beginning of the macro // instantiation occurs. - if (cursor.kind == CXCursor_MacroInstantiation) { + if (cursor.kind == CXCursor_MacroExpansion) { Annotated[Loc.int_data] = cursor; return CXChildVisit_Recurse; } diff --git a/tools/libclang/CXCursor.cpp b/tools/libclang/CXCursor.cpp index b48ad91098..86997d6701 100644 --- a/tools/libclang/CXCursor.cpp +++ b/tools/libclang/CXCursor.cpp @@ -380,12 +380,12 @@ MacroDefinition *cxcursor::getCursorMacroDefinition(CXCursor C) { CXCursor cxcursor::MakeMacroExpansionCursor(MacroExpansion *MI, CXTranslationUnit TU) { - CXCursor C = { CXCursor_MacroInstantiation, { MI, 0, TU } }; + CXCursor C = { CXCursor_MacroExpansion, { MI, 0, TU } }; return C; } MacroExpansion *cxcursor::getCursorMacroExpansion(CXCursor C) { - assert(C.kind == CXCursor_MacroInstantiation); + assert(C.kind == CXCursor_MacroExpansion); return static_cast(C.data[0]); }