Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkg/codesearch/testdata/query-def-source-quote-type
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def-source source0.c function_with_quotes_in_type yes

function function_with_quotes_in_type is defined in source0.c:

35: void function_with_quotes_in_type(void __attribute__((btf_type_tag("user"))) *)
36: {
37: }
1 change: 1 addition & 0 deletions pkg/codesearch/testdata/query-file-index-source
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ file source0.c defines the following entities:
function close
function func_accepting_a_struct
function function_with_comment_in_header
function function_with_quotes_in_type
function open
struct struct_in_c_file
4 changes: 4 additions & 0 deletions pkg/codesearch/testdata/source0.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ int func_accepting_a_struct(struct some_struct* p)
return ((some_struct_t*)p)->x +
((union some_union*)p)->x;
}

void function_with_quotes_in_type(void __attribute__((btf_type_tag("user"))) *)
{
}
51 changes: 31 additions & 20 deletions pkg/codesearch/testdata/source0.c.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
{
"definitions": [
{
"name": "some_enum",
"kind": "enum",
"body": {
"file": "source0.h",
"start_line": 45,
"end_line": 48
},
"comment": {}
},
{
"name": "close",
"type": "int ()",
Expand Down Expand Up @@ -89,6 +79,17 @@
}
]
},
{
"name": "function_with_quotes_in_type",
"type": "void (void __attribute__((btf_type_tag(\"user\")))*)",
"kind": "function",
"body": {
"file": "source0.c",
"start_line": 35,
"end_line": 37
},
"comment": {}
},
{
"name": "open",
"type": "int ()",
Expand Down Expand Up @@ -148,6 +149,26 @@
},
"comment": {}
},
{
"name": "some_union",
"kind": "union",
"body": {
"file": "source0.h",
"start_line": 40,
"end_line": 43
},
"comment": {}
},
{
"name": "some_enum",
"kind": "enum",
"body": {
"file": "source0.h",
"start_line": 45,
"end_line": 48
},
"comment": {}
},
{
"name": "another_struct_t",
"kind": "typedef",
Expand Down Expand Up @@ -187,16 +208,6 @@
"end_line": 34
},
"comment": {}
},
{
"name": "some_union",
"kind": "union",
"body": {
"file": "source0.h",
"start_line": 40,
"end_line": 43
},
"comment": {}
}
]
}
38 changes: 37 additions & 1 deletion tools/clang/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,47 @@ class JSONPrinter {
Scope Top;
};

inline void print(JSONPrinter& Printer, const char* V) {
printf("\"");
if (V) {
for (; *V; ++V) {
switch (*V) {
case '"':
printf("\\\"");
break;
case '\\':
printf("\\\\");
break;
case '\b':
printf("\\b");
break;
case '\f':
printf("\\f");
break;
case '\n':
printf("\\n");
break;
case '\r':
printf("\\r");
break;
case '\t':
printf("\\t");
break;
default:
if ((unsigned char)*V < 0x20)
printf("\\u%04x", (unsigned char)*V);
else
printf("%c", *V);
}
}
}
printf("\"");
}

inline void print(JSONPrinter& Printer, int V) { printf("%d", V); }
inline void print(JSONPrinter& Printer, unsigned V) { printf("%u", V); }
inline void print(JSONPrinter& Printer, int64_t V) { printf("%ld", V); }
inline void print(JSONPrinter& Printer, bool V) { printf("%s", V ? "true" : "false"); }
inline void print(JSONPrinter& Printer, const char* V) { printf("\"%s\"", V ? V : ""); }
inline void print(JSONPrinter& Printer, const std::string& V) { print(Printer, V.c_str()); }

template <typename E> void print(JSONPrinter& Printer, const std::unique_ptr<E>& V) {
Expand Down
Loading