dang updated this revision to Diff 420598. dang added a comment. Add descriptive method names for manipulating the path component stack.
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D123045/new/ https://reviews.llvm.org/D123045 Files: clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp clang/test/ExtractAPI/enum.c clang/test/ExtractAPI/global_record.c clang/test/ExtractAPI/global_record_multifile.c clang/test/ExtractAPI/language.c clang/test/ExtractAPI/macro_undefined.c clang/test/ExtractAPI/macros.c clang/test/ExtractAPI/objc_interface.m clang/test/ExtractAPI/objc_protocol.m clang/test/ExtractAPI/struct.c
Index: clang/test/ExtractAPI/struct.c =================================================================== --- clang/test/ExtractAPI/struct.c +++ clang/test/ExtractAPI/struct.c @@ -48,7 +48,7 @@ "vendor": "apple" } }, - "relationhips": [ + "relationships": [ { "kind": "memberOf", "source": "c:@S@Color@FI@Red", @@ -72,6 +72,7 @@ ], "symbols": [ { + "accessLevel": "public", "declarationFragments": [ { "kind": "keyword", @@ -112,8 +113,10 @@ "identifier": "c.struct" }, "location": { - "character": 8, - "line": 2, + "position": { + "character": 8, + "line": 2 + }, "uri": "file://INPUT_DIR/input.h" }, "names": { @@ -124,9 +127,13 @@ } ], "title": "Color" - } + }, + "pathComponents": [ + "Color" + ] }, { + "accessLevel": "public", "declarationFragments": [ { "kind": "typeIdentifier", @@ -151,8 +158,10 @@ "identifier": "c.property" }, "location": { - "character": 12, - "line": 3, + "position": { + "character": 12, + "line": 3 + }, "uri": "file://INPUT_DIR/input.h" }, "names": { @@ -163,9 +172,14 @@ } ], "title": "Red" - } + }, + "pathComponents": [ + "Color", + "Red" + ] }, { + "accessLevel": "public", "declarationFragments": [ { "kind": "typeIdentifier", @@ -190,8 +204,10 @@ "identifier": "c.property" }, "location": { - "character": 12, - "line": 4, + "position": { + "character": 12, + "line": 4 + }, "uri": "file://INPUT_DIR/input.h" }, "names": { @@ -202,9 +218,14 @@ } ], "title": "Green" - } + }, + "pathComponents": [ + "Color", + "Green" + ] }, { + "accessLevel": "public", "declarationFragments": [ { "kind": "typeIdentifier", @@ -229,8 +250,10 @@ "identifier": "c.property" }, "location": { - "character": 12, - "line": 5, + "position": { + "character": 12, + "line": 5 + }, "uri": "file://INPUT_DIR/input.h" }, "names": { @@ -241,9 +264,14 @@ } ], "title": "Blue" - } + }, + "pathComponents": [ + "Color", + "Blue" + ] }, { + "accessLevel": "public", "declarationFragments": [ { "kind": "typeIdentifier", @@ -285,8 +313,10 @@ "identifier": "c.property" }, "location": { - "character": 12, - "line": 7, + "position": { + "character": 12, + "line": 7 + }, "uri": "file://INPUT_DIR/input.h" }, "names": { @@ -297,7 +327,11 @@ } ], "title": "Alpha" - } + }, + "pathComponents": [ + "Color", + "Alpha" + ] } ] } Index: clang/test/ExtractAPI/objc_protocol.m =================================================================== --- clang/test/ExtractAPI/objc_protocol.m +++ clang/test/ExtractAPI/objc_protocol.m @@ -45,7 +45,7 @@ "vendor": "apple" } }, - "relationhips": [ + "relationships": [ { "kind": "conformsTo", "source": "c:objc(pl)AnotherProtocol", @@ -54,6 +54,7 @@ ], "symbols": [ { + "accessLevel": "public", "declarationFragments": [ { "kind": "keyword", @@ -77,8 +78,10 @@ "identifier": "objective-c.protocol" }, "location": { - "character": 11, - "line": 1, + "position": { + "character": 11, + "line": 1 + }, "uri": "file://INPUT_DIR/input.h" }, "names": { @@ -89,9 +92,13 @@ } ], "title": "Protocol" - } + }, + "pathComponents": [ + "Protocol" + ] }, { + "accessLevel": "public", "declarationFragments": [ { "kind": "keyword", @@ -128,8 +135,10 @@ "identifier": "objective-c.protocol" }, "location": { - "character": 11, - "line": 4, + "position": { + "character": 11, + "line": 4 + }, "uri": "file://INPUT_DIR/input.h" }, "names": { @@ -140,7 +149,10 @@ } ], "title": "AnotherProtocol" - } + }, + "pathComponents": [ + "AnotherProtocol" + ] } ] } Index: clang/test/ExtractAPI/objc_interface.m =================================================================== --- clang/test/ExtractAPI/objc_interface.m +++ clang/test/ExtractAPI/objc_interface.m @@ -52,7 +52,7 @@ "vendor": "apple" } }, - "relationhips": [ + "relationships": [ { "kind": "memberOf", "source": "c:objc(cs)Super(cm)getWithProperty:", @@ -86,6 +86,7 @@ ], "symbols": [ { + "accessLevel": "public", "declarationFragments": [ { "kind": "keyword", @@ -109,8 +110,10 @@ "identifier": "objective-c.class" }, "location": { - "character": 12, - "line": 3, + "position": { + "character": 12, + "line": 3 + }, "uri": "file://INPUT_DIR/input.h" }, "names": { @@ -121,9 +124,13 @@ } ], "title": "Super" - } + }, + "pathComponents": [ + "Super" + ] }, { + "accessLevel": "public", "declarationFragments": [ { "kind": "text", @@ -172,8 +179,10 @@ "identifier": "objective-c.type.method" }, "location": { - "character": 1, - "line": 5, + "position": { + "character": 1, + "line": 5 + }, "uri": "file://INPUT_DIR/input.h" }, "names": { @@ -188,9 +197,14 @@ } ], "title": "getWithProperty:" - } + }, + "pathComponents": [ + "Super", + "getWithProperty:" + ] }, { + "accessLevel": "public", "declarationFragments": [ { "kind": "keyword", @@ -251,8 +265,10 @@ "identifier": "objective-c.property" }, "location": { - "character": 50, - "line": 4, + "position": { + "character": 50, + "line": 4 + }, "uri": "file://INPUT_DIR/input.h" }, "names": { @@ -263,9 +279,14 @@ } ], "title": "Property" - } + }, + "pathComponents": [ + "Super", + "Property" + ] }, { + "accessLevel": "public", "declarationFragments": [ { "kind": "keyword", @@ -298,8 +319,10 @@ "identifier": "objective-c.class" }, "location": { - "character": 12, - "line": 8, + "position": { + "character": 12, + "line": 8 + }, "uri": "file://INPUT_DIR/input.h" }, "names": { @@ -310,9 +333,13 @@ } ], "title": "Derived" - } + }, + "pathComponents": [ + "Derived" + ] }, { + "accessLevel": "public", "declarationFragments": [ { "kind": "typeIdentifier", @@ -337,8 +364,10 @@ "identifier": "objective-c.ivar" }, "location": { - "character": 8, - "line": 9, + "position": { + "character": 8, + "line": 9 + }, "uri": "file://INPUT_DIR/input.h" }, "names": { @@ -349,9 +378,14 @@ } ], "title": "Ivar" - } + }, + "pathComponents": [ + "Derived", + "Ivar" + ] }, { + "accessLevel": "public", "declarationFragments": [ { "kind": "text", @@ -380,8 +414,10 @@ "identifier": "objective-c.method" }, "location": { - "character": 1, - "line": 11, + "position": { + "character": 1, + "line": 11 + }, "uri": "file://INPUT_DIR/input.h" }, "names": { @@ -396,7 +432,11 @@ } ], "title": "getIvar" - } + }, + "pathComponents": [ + "Derived", + "getIvar" + ] } ] } Index: clang/test/ExtractAPI/macros.c =================================================================== --- clang/test/ExtractAPI/macros.c +++ clang/test/ExtractAPI/macros.c @@ -46,9 +46,10 @@ "vendor": "apple" } }, - "relationhips": [], + "relationships": [], "symbols": [ { + "accessLevel": "public", "declarationFragments": [ { "kind": "keyword", @@ -72,8 +73,10 @@ "identifier": "objective-c.macro" }, "location": { - "character": 9, - "line": 1, + "position": { + "character": 9, + "line": 1 + }, "uri": "file://INPUT_DIR/input.h" }, "names": { @@ -84,9 +87,13 @@ } ], "title": "HELLO" - } + }, + "pathComponents": [ + "HELLO" + ] }, { + "accessLevel": "public", "declarationFragments": [ { "kind": "keyword", @@ -110,8 +117,10 @@ "identifier": "objective-c.macro" }, "location": { - "character": 9, - "line": 2, + "position": { + "character": 9, + "line": 2 + }, "uri": "file://INPUT_DIR/input.h" }, "names": { @@ -122,9 +131,13 @@ } ], "title": "WORLD" - } + }, + "pathComponents": [ + "WORLD" + ] }, { + "accessLevel": "public", "declarationFragments": [ { "kind": "keyword", @@ -160,8 +173,10 @@ "identifier": "objective-c.macro" }, "location": { - "character": 9, - "line": 3, + "position": { + "character": 9, + "line": 3 + }, "uri": "file://INPUT_DIR/input.h" }, "names": { @@ -172,9 +187,13 @@ } ], "title": "MACRO_FUN" - } + }, + "pathComponents": [ + "MACRO_FUN" + ] }, { + "accessLevel": "public", "declarationFragments": [ { "kind": "keyword", @@ -226,8 +245,10 @@ "identifier": "objective-c.macro" }, "location": { - "character": 9, - "line": 4, + "position": { + "character": 9, + "line": 4 + }, "uri": "file://INPUT_DIR/input.h" }, "names": { @@ -238,9 +259,13 @@ } ], "title": "FUN" - } + }, + "pathComponents": [ + "FUN" + ] }, { + "accessLevel": "public", "declarationFragments": [ { "kind": "keyword", @@ -276,8 +301,10 @@ "identifier": "objective-c.macro" }, "location": { - "character": 9, - "line": 5, + "position": { + "character": 9, + "line": 5 + }, "uri": "file://INPUT_DIR/input.h" }, "names": { @@ -288,9 +315,13 @@ } ], "title": "FUNC99" - } + }, + "pathComponents": [ + "FUNC99" + ] }, { + "accessLevel": "public", "declarationFragments": [ { "kind": "keyword", @@ -326,8 +357,10 @@ "identifier": "objective-c.macro" }, "location": { - "character": 9, - "line": 6, + "position": { + "character": 9, + "line": 6 + }, "uri": "file://INPUT_DIR/input.h" }, "names": { @@ -338,7 +371,10 @@ } ], "title": "FUNGNU" - } + }, + "pathComponents": [ + "FUNGNU" + ] } ] } Index: clang/test/ExtractAPI/macro_undefined.c =================================================================== --- clang/test/ExtractAPI/macro_undefined.c +++ clang/test/ExtractAPI/macro_undefined.c @@ -45,9 +45,10 @@ "vendor": "apple" } }, - "relationhips": [], + "relationships": [], "symbols": [ { + "accessLevel": "public", "declarationFragments": [ { "kind": "typeIdentifier", @@ -67,6 +68,15 @@ "spelling": "()" } ], + "functionSignature": { + "returns": [ + { + "kind": "typeIdentifier", + "preciseIdentifier": "c:v", + "spelling": "void" + } + ] + }, "identifier": { "interfaceLanguage": "objective-c", "precise": "c:@F@foo" @@ -76,8 +86,10 @@ "identifier": "objective-c.func" }, "location": { - "character": 1, - "line": 3, + "position": { + "character": 1, + "line": 3 + }, "uri": "file://INPUT_DIR/input.h" }, "names": { @@ -89,17 +101,12 @@ ], "title": "foo" }, - "parameters": { - "returns": [ - { - "kind": "typeIdentifier", - "preciseIdentifier": "c:v", - "spelling": "void" - } - ] - } + "pathComponents": [ + "foo" + ] }, { + "accessLevel": "public", "declarationFragments": [ { "kind": "typeIdentifier", @@ -161,29 +168,7 @@ "spelling": ")" } ], - "identifier": { - "interfaceLanguage": "objective-c", - "precise": "c:@F@bar" - }, - "kind": { - "displayName": "Function", - "identifier": "objective-c.func" - }, - "location": { - "character": 1, - "line": 4, - "uri": "file://INPUT_DIR/input.h" - }, - "names": { - "subHeading": [ - { - "kind": "identifier", - "spelling": "bar" - } - ], - "title": "bar" - }, - "parameters": { + "functionSignature": { "parameters": [ { "declarationFragments": [ @@ -237,9 +222,37 @@ "spelling": "void" } ] - } + }, + "identifier": { + "interfaceLanguage": "objective-c", + "precise": "c:@F@bar" + }, + "kind": { + "displayName": "Function", + "identifier": "objective-c.func" + }, + "location": { + "position": { + "character": 1, + "line": 4 + }, + "uri": "file://INPUT_DIR/input.h" + }, + "names": { + "subHeading": [ + { + "kind": "identifier", + "spelling": "bar" + } + ], + "title": "bar" + }, + "pathComponents": [ + "bar" + ] }, { + "accessLevel": "public", "declarationFragments": [ { "kind": "keyword", @@ -263,8 +276,10 @@ "identifier": "objective-c.macro" }, "location": { - "character": 9, - "line": 1, + "position": { + "character": 9, + "line": 1 + }, "uri": "file://INPUT_DIR/input.h" }, "names": { @@ -275,7 +290,10 @@ } ], "title": "HELLO" - } + }, + "pathComponents": [ + "HELLO" + ] } ] } Index: clang/test/ExtractAPI/language.c =================================================================== --- clang/test/ExtractAPI/language.c +++ clang/test/ExtractAPI/language.c @@ -53,9 +53,10 @@ "vendor": "apple" } }, - "relationhips": [], + "relationships": [], "symbols": [ { + "accessLevel": "public", "declarationFragments": [ { "kind": "typeIdentifier", @@ -80,8 +81,10 @@ "identifier": "c.var" }, "location": { - "character": 6, - "line": 1, + "position": { + "character": 6, + "line": 1 + }, "uri": "file://INPUT_DIR/c.h" }, "names": { @@ -92,7 +95,10 @@ } ], "title": "c" - } + }, + "pathComponents": [ + "c" + ] } ] } @@ -121,9 +127,10 @@ "vendor": "apple" } }, - "relationhips": [], + "relationships": [], "symbols": [ { + "accessLevel": "public", "declarationFragments": [ { "kind": "typeIdentifier", @@ -148,8 +155,10 @@ "identifier": "objective-c.var" }, "location": { - "character": 6, - "line": 1, + "position": { + "character": 6, + "line": 1 + }, "uri": "file://INPUT_DIR/objc.h" }, "names": { @@ -160,7 +169,10 @@ } ], "title": "objc" - } + }, + "pathComponents": [ + "objc" + ] } ] } Index: clang/test/ExtractAPI/global_record_multifile.c =================================================================== --- clang/test/ExtractAPI/global_record_multifile.c +++ clang/test/ExtractAPI/global_record_multifile.c @@ -53,9 +53,10 @@ "vendor": "apple" } }, - "relationhips": [], + "relationships": [], "symbols": [ { + "accessLevel": "public", "declarationFragments": [ { "kind": "typeIdentifier", @@ -80,8 +81,10 @@ "identifier": "c.var" }, "location": { - "character": 5, - "line": 1, + "position": { + "character": 5, + "line": 1 + }, "uri": "file://INPUT_DIR/input1.h" }, "names": { @@ -92,9 +95,13 @@ } ], "title": "num" - } + }, + "pathComponents": [ + "num" + ] }, { + "accessLevel": "public", "declarationFragments": [ { "kind": "typeIdentifier", @@ -263,29 +270,7 @@ } ] }, - "identifier": { - "interfaceLanguage": "c", - "precise": "c:@F@add" - }, - "kind": { - "displayName": "Function", - "identifier": "c.func" - }, - "location": { - "character": 6, - "line": 7, - "uri": "file://INPUT_DIR/input2.h" - }, - "names": { - "subHeading": [ - { - "kind": "identifier", - "spelling": "add" - } - ], - "title": "add" - }, - "parameters": { + "functionSignature": { "parameters": [ { "declarationFragments": [ @@ -365,7 +350,34 @@ "spelling": "void" } ] - } + }, + "identifier": { + "interfaceLanguage": "c", + "precise": "c:@F@add" + }, + "kind": { + "displayName": "Function", + "identifier": "c.func" + }, + "location": { + "position": { + "character": 6, + "line": 7 + }, + "uri": "file://INPUT_DIR/input2.h" + }, + "names": { + "subHeading": [ + { + "kind": "identifier", + "spelling": "add" + } + ], + "title": "add" + }, + "pathComponents": [ + "add" + ] } ] } Index: clang/test/ExtractAPI/global_record.c =================================================================== --- clang/test/ExtractAPI/global_record.c +++ clang/test/ExtractAPI/global_record.c @@ -51,9 +51,10 @@ "vendor": "apple" } }, - "relationhips": [], + "relationships": [], "symbols": [ { + "accessLevel": "public", "declarationFragments": [ { "kind": "typeIdentifier", @@ -78,8 +79,10 @@ "identifier": "c.var" }, "location": { - "character": 5, - "line": 1, + "position": { + "character": 5, + "line": 1 + }, "uri": "file://INPUT_DIR/input.h" }, "names": { @@ -90,9 +93,13 @@ } ], "title": "num" - } + }, + "pathComponents": [ + "num" + ] }, { + "accessLevel": "public", "declarationFragments": [ { "kind": "typeIdentifier", @@ -261,29 +268,7 @@ } ] }, - "identifier": { - "interfaceLanguage": "c", - "precise": "c:@F@add" - }, - "kind": { - "displayName": "Function", - "identifier": "c.func" - }, - "location": { - "character": 6, - "line": 9, - "uri": "file://INPUT_DIR/input.h" - }, - "names": { - "subHeading": [ - { - "kind": "identifier", - "spelling": "add" - } - ], - "title": "add" - }, - "parameters": { + "functionSignature": { "parameters": [ { "declarationFragments": [ @@ -363,7 +348,34 @@ "spelling": "void" } ] - } + }, + "identifier": { + "interfaceLanguage": "c", + "precise": "c:@F@add" + }, + "kind": { + "displayName": "Function", + "identifier": "c.func" + }, + "location": { + "position": { + "character": 6, + "line": 9 + }, + "uri": "file://INPUT_DIR/input.h" + }, + "names": { + "subHeading": [ + { + "kind": "identifier", + "spelling": "add" + } + ], + "title": "add" + }, + "pathComponents": [ + "add" + ] } ] } Index: clang/test/ExtractAPI/enum.c =================================================================== --- clang/test/ExtractAPI/enum.c +++ clang/test/ExtractAPI/enum.c @@ -55,7 +55,7 @@ "vendor": "apple" } }, - "relationhips": [ + "relationships": [ { "kind": "memberOf", "source": "c:@E@Vehicle@Bicycle", @@ -104,6 +104,7 @@ ], "symbols": [ { + "accessLevel": "public", "declarationFragments": [ { "kind": "keyword", @@ -153,8 +154,10 @@ "identifier": "c.enum" }, "location": { - "character": 6, - "line": 2, + "position": { + "character": 6, + "line": 2 + }, "uri": "file://INPUT_DIR/input.h" }, "names": { @@ -165,9 +168,13 @@ } ], "title": "Vehicle" - } + }, + "pathComponents": [ + "Vehicle" + ] }, { + "accessLevel": "public", "declarationFragments": [ { "kind": "identifier", @@ -183,8 +190,10 @@ "identifier": "c.enum.case" }, "location": { - "character": 3, - "line": 3, + "position": { + "character": 3, + "line": 3 + }, "uri": "file://INPUT_DIR/input.h" }, "names": { @@ -195,9 +204,14 @@ } ], "title": "Bicycle" - } + }, + "pathComponents": [ + "Vehicle", + "Bicycle" + ] }, { + "accessLevel": "public", "declarationFragments": [ { "kind": "identifier", @@ -213,8 +227,10 @@ "identifier": "c.enum.case" }, "location": { - "character": 3, - "line": 4, + "position": { + "character": 3, + "line": 4 + }, "uri": "file://INPUT_DIR/input.h" }, "names": { @@ -225,9 +241,14 @@ } ], "title": "Car" - } + }, + "pathComponents": [ + "Vehicle", + "Car" + ] }, { + "accessLevel": "public", "declarationFragments": [ { "kind": "identifier", @@ -260,8 +281,10 @@ "identifier": "c.enum.case" }, "location": { - "character": 3, - "line": 5, + "position": { + "character": 3, + "line": 5 + }, "uri": "file://INPUT_DIR/input.h" }, "names": { @@ -272,9 +295,14 @@ } ], "title": "Train" - } + }, + "pathComponents": [ + "Vehicle", + "Train" + ] }, { + "accessLevel": "public", "declarationFragments": [ { "kind": "identifier", @@ -290,8 +318,10 @@ "identifier": "c.enum.case" }, "location": { - "character": 3, - "line": 6, + "position": { + "character": 3, + "line": 6 + }, "uri": "file://INPUT_DIR/input.h" }, "names": { @@ -302,9 +332,14 @@ } ], "title": "Ship" - } + }, + "pathComponents": [ + "Vehicle", + "Ship" + ] }, { + "accessLevel": "public", "declarationFragments": [ { "kind": "identifier", @@ -320,8 +355,10 @@ "identifier": "c.enum.case" }, "location": { - "character": 3, - "line": 7, + "position": { + "character": 3, + "line": 7 + }, "uri": "file://INPUT_DIR/input.h" }, "names": { @@ -332,9 +369,14 @@ } ], "title": "Airplane" - } + }, + "pathComponents": [ + "Vehicle", + "Airplane" + ] }, { + "accessLevel": "public", "declarationFragments": [ { "kind": "keyword", @@ -367,8 +409,10 @@ "identifier": "c.enum" }, "location": { - "character": 6, - "line": 10, + "position": { + "character": 6, + "line": 10 + }, "uri": "file://INPUT_DIR/input.h" }, "names": { @@ -379,9 +423,13 @@ } ], "title": "Direction" - } + }, + "pathComponents": [ + "Direction" + ] }, { + "accessLevel": "public", "declarationFragments": [ { "kind": "identifier", @@ -397,8 +445,10 @@ "identifier": "c.enum.case" }, "location": { - "character": 3, - "line": 11, + "position": { + "character": 3, + "line": 11 + }, "uri": "file://INPUT_DIR/input.h" }, "names": { @@ -409,9 +459,14 @@ } ], "title": "North" - } + }, + "pathComponents": [ + "Direction", + "North" + ] }, { + "accessLevel": "public", "declarationFragments": [ { "kind": "identifier", @@ -427,8 +482,10 @@ "identifier": "c.enum.case" }, "location": { - "character": 3, - "line": 12, + "position": { + "character": 3, + "line": 12 + }, "uri": "file://INPUT_DIR/input.h" }, "names": { @@ -439,9 +496,14 @@ } ], "title": "East" - } + }, + "pathComponents": [ + "Direction", + "East" + ] }, { + "accessLevel": "public", "declarationFragments": [ { "kind": "identifier", @@ -457,8 +519,10 @@ "identifier": "c.enum.case" }, "location": { - "character": 3, - "line": 13, + "position": { + "character": 3, + "line": 13 + }, "uri": "file://INPUT_DIR/input.h" }, "names": { @@ -469,9 +533,14 @@ } ], "title": "South" - } + }, + "pathComponents": [ + "Direction", + "South" + ] }, { + "accessLevel": "public", "declarationFragments": [ { "kind": "identifier", @@ -487,8 +556,10 @@ "identifier": "c.enum.case" }, "location": { - "character": 3, - "line": 14, + "position": { + "character": 3, + "line": 14 + }, "uri": "file://INPUT_DIR/input.h" }, "names": { @@ -499,7 +570,11 @@ } ], "title": "West" - } + }, + "pathComponents": [ + "Direction", + "West" + ] } ] } Index: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp =================================================================== --- clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp +++ clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp @@ -14,6 +14,7 @@ #include "clang/ExtractAPI/Serialization/SymbolGraphSerializer.h" #include "clang/Basic/Version.h" #include "clang/ExtractAPI/API.h" +#include "clang/ExtractAPI/DeclarationFragments.h" #include "llvm/Support/JSON.h" #include "llvm/Support/Path.h" #include "llvm/Support/VersionTuple.h" @@ -90,27 +91,35 @@ return Platform; } +/// Serialize a source position. +Object serializeSourcePosition(const PresumedLoc &Loc) { + assert(Loc.isValid() && "invalid source position"); + + Object SourcePosition; + SourcePosition["line"] = Loc.getLine(); + SourcePosition["character"] = Loc.getColumn(); + + return SourcePosition; +} + /// Serialize a source location in file. /// /// \param Loc The presumed location to serialize. /// \param IncludeFileURI If true, include the file path of \p Loc as a URI. /// Defaults to false. -Object serializeSourcePosition(const PresumedLoc &Loc, +Object serializeSourceLocation(const PresumedLoc &Loc, bool IncludeFileURI = false) { - assert(Loc.isValid() && "invalid source position"); - - Object SourcePosition; - SourcePosition["line"] = Loc.getLine(); - SourcePosition["character"] = Loc.getColumn(); + Object SourceLocation; + serializeObject(SourceLocation, "position", serializeSourcePosition(Loc)); if (IncludeFileURI) { std::string FileURI = "file://"; // Normalize file path to use forward slashes for the URI. FileURI += sys::path::convert_to_slash(Loc.getFilename()); - SourcePosition["uri"] = FileURI; + SourceLocation["uri"] = FileURI; } - return SourcePosition; + return SourceLocation; } /// Serialize a source range with begin and end locations. @@ -438,10 +447,12 @@ } Optional<Object> -SymbolGraphSerializer::serializeAPIRecord(const APIRecord &Record) const { +SymbolGraphSerializer::serializeAPIRecord(const APIRecord &Record) { if (shouldSkip(Record)) return None; + pushPathComponent(Record.Name); + Object Obj; serializeObject(Obj, "identifier", serializeIdentifier(Record, API.getLanguage())); @@ -449,12 +460,16 @@ serializeObject(Obj, "names", serializeNames(Record)); serializeObject( Obj, "location", - serializeSourcePosition(Record.Location, /*IncludeFileURI=*/true)); + serializeSourceLocation(Record.Location, /*IncludeFileURI=*/true)); serializeObject(Obj, "availbility", serializeAvailability(Record.Availability)); serializeObject(Obj, "docComment", serializeDocComment(Record.Comment)); serializeArray(Obj, "declarationFragments", serializeDeclarationFragments(Record.Declaration)); + // TODO: Once we keep track of symbol access information serialize it + // correctly here. + Obj["accessLevel"] = "public"; + serializeArray(Obj, "pathComponents", Array(PathComponentContext)); return Obj; } @@ -488,10 +503,11 @@ return; if (Record.GlobalKind == GVKind::Function) - serializeObject(*Obj, "parameters", + serializeObject(*Obj, "functionSignature", serializeFunctionSignature(Record.Signature)); Symbols.emplace_back(std::move(*Obj)); + popPathComponent(); } void SymbolGraphSerializer::serializeEnumRecord(const EnumRecord &Record) { @@ -503,12 +519,17 @@ for (const auto &Constant : Record.Constants) { auto EnumConstant = serializeAPIRecord(*Constant); + + popPathComponent(); + if (!EnumConstant) continue; Symbols.emplace_back(std::move(*EnumConstant)); serializeRelationship(RelationshipKind::MemberOf, *Constant, Record); } + + popPathComponent(); } void SymbolGraphSerializer::serializeStructRecord(const StructRecord &Record) { @@ -520,6 +541,9 @@ for (const auto &Field : Record.Fields) { auto StructField = serializeAPIRecord(*Field); + + popPathComponent(); + if (!StructField) continue; @@ -540,6 +564,9 @@ // the container. for (const auto &Ivar : Record.Ivars) { auto ObjCIvar = serializeAPIRecord(*Ivar); + + popPathComponent(); + if (!ObjCIvar) continue; @@ -550,6 +577,9 @@ // Record methods and that the methods are members of the container. for (const auto &Method : Record.Methods) { auto ObjCMethod = serializeAPIRecord(*Method); + + popPathComponent(); + if (!ObjCMethod) continue; @@ -560,6 +590,9 @@ // Record properties and that the properties are members of the container. for (const auto &Property : Record.Properties) { auto ObjCProperty = serializeAPIRecord(*Property); + + popPathComponent(); + if (!ObjCProperty) continue; @@ -577,17 +610,30 @@ // record that Record is inherited from SuperClass. serializeRelationship(RelationshipKind::InheritsFrom, Record, ObjCInterface->SuperClass); + + popPathComponent(); } void SymbolGraphSerializer::serializeMacroDefinitionRecord( const MacroDefinitionRecord &Record) { auto Macro = serializeAPIRecord(Record); + + popPathComponent(); + if (!Macro) return; Symbols.emplace_back(std::move(*Macro)); } +void SymbolGraphSerializer::pushPathComponent(StringRef Component) { + PathComponentContext.emplace_back(Component); +} + +void SymbolGraphSerializer::popPathComponent() { + PathComponentContext.pop_back(); +} + Object SymbolGraphSerializer::serialize() { Object Root; serializeObject(Root, "metadata", serializeMetadata()); @@ -617,7 +663,7 @@ serializeMacroDefinitionRecord(*Macro.second); Root["symbols"] = std::move(Symbols); - Root["relationhips"] = std::move(Relationships); + Root["relationships"] = std::move(Relationships); return Root; } Index: clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h =================================================================== --- clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h +++ clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h @@ -19,6 +19,7 @@ #include "clang/ExtractAPI/API.h" #include "clang/ExtractAPI/Serialization/SerializerBase.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/Support/JSON.h" #include "llvm/Support/VersionTuple.h" #include "llvm/Support/raw_ostream.h" @@ -45,6 +46,9 @@ /// The Symbol Graph format version used by this serializer. static const VersionTuple FormatVersion; + /// The current path component stack. + llvm::SmallVector<StringRef, 4> PathComponentContext; + public: /// Serialize the APIs in \c APISet in the Symbol Graph format. /// @@ -102,7 +106,7 @@ /// /// \returns \c None if this \p Record should be skipped, or a JSON object /// containing common symbol information of \p Record. - Optional<Object> serializeAPIRecord(const APIRecord &Record) const; + Optional<Object> serializeAPIRecord(const APIRecord &Record); /// Serialize the \p Kind relationship between \p Source and \p Target. /// @@ -126,6 +130,12 @@ /// Serialize a macro defintion record. void serializeMacroDefinitionRecord(const MacroDefinitionRecord &Record); + /// Push a component to the current path components stack. + void pushPathComponent(StringRef Component); + + /// Remove the latest component pushed to the current path components stack. + void popPathComponent(); + public: SymbolGraphSerializer(const APISet &API, StringRef ProductName, APISerializerOption Options = {})
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits