github.com/google/syzkaller@v0.0.0-20251211124644-a066d2bc4b02/tools/clang/codesearch/output.h (about) 1 // Copyright 2025 syzkaller project authors. All rights reserved. 2 // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 3 4 #ifndef SYZ_INDEXER_OUTPUT_H 5 #define SYZ_INDEXER_OUTPUT_H 6 7 #include "json.h" 8 #include <vector> 9 10 constexpr char KindFunction[] = "function"; 11 constexpr char KindStruct[] = "struct"; 12 constexpr char KindVariable[] = "variable"; 13 constexpr char KindMacro[] = "macro"; 14 constexpr char KindEnum[] = "enum"; 15 16 struct LineRange { 17 std::string File; 18 int StartLine = 0; 19 int EndLine = 0; 20 }; 21 22 struct Definition { 23 const char* Kind; // one of Kind* consts 24 std::string Name; 25 std::string Type; // raw C type 26 bool IsStatic = false; 27 // If the kernel-doc comment is placed around the body, 28 // then it's included in the body range. 29 LineRange Body; 30 // Location of the kernel-doc comment. 31 LineRange Comment; 32 }; 33 34 inline void print(JSONPrinter& Printer, const LineRange& V) { 35 JSONPrinter::Scope Scope(Printer); 36 Printer.Field("file", V.File); 37 Printer.Field("start_line", V.StartLine); 38 Printer.Field("end_line", V.EndLine, true); 39 } 40 41 inline void print(JSONPrinter& Printer, const Definition& V) { 42 JSONPrinter::Scope Scope(Printer); 43 Printer.Field("kind", V.Kind); 44 Printer.Field("name", V.Name); 45 Printer.Field("type", V.Type); 46 Printer.Field("is_static", V.IsStatic); 47 Printer.Field("body", V.Body); 48 Printer.Field("comment", V.Comment, true); 49 } 50 51 class Output { 52 public: 53 void emit(Definition&& V) { Definitions.push_back(std::move(V)); } 54 55 void print() const { 56 JSONPrinter Printer; 57 Printer.Field("definitions", Definitions, true); 58 } 59 60 private: 61 std::vector<Definition> Definitions; 62 }; 63 64 #endif