MCPcopy Create free account
hub / github.com/acidicoala/SmokeAPI / parse_header

Function parse_header

tools/src/steamworks_parser.cpp:30–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28 }
29
30 void parse_header(const std::string_view& source, nlohmann::ordered_json& lookup) {
31 const auto tree = parser::parse_source(source);
32 const auto root = tree.getRootNode();
33
34 nlohmann::ordered_json current_lookup = {};
35 std::string interface_version;
36
37 parser::walk(
38 root,
39 [&](const ts::Node& current_node) {
40 const auto current_type = current_node.getType();
41 // const auto current_value = current_node.getSourceRange(source);
42 const auto current_sexpr = current_node.getSExpr();
43
44 if(current_type == "class_specifier") {
45 std::string interface_name;
46 [[maybe_unused]] int vt_idx = 0;
47
48 parser::walk(
49 current_node,
50 [&](const ts::Node& class_node) {
51 const auto type = class_node.getType();
52 const auto value = class_node.getSourceRange(source);
53
54 if(type == "type_identifier" && interface_name.empty()) {
55 interface_name = value;
56 LOG_DEBUG("Found interface: {}", interface_name);
57
58 return parser::visit_result::Continue;
59 }
60
61 if(type == "field_declaration" && value.starts_with("virtual ")) {
62 if(value.starts_with("virtual ")) {
63 parser::walk(
64 class_node,
65 [&](const ts::Node& decl_node) {
66 if(decl_node.getType() == "field_identifier") {
67 const auto function_name = decl_node.getSourceRange(
68 source
69 );
70
71 // Note: This doesn't take into account overloaded functions.
72 // However, so far this project hasn't had any need to hook such
73 // functions. Hence, no fixes have been implemented so far.
74
75 current_lookup[function_name] = vt_idx++;
76 return parser::visit_result::Stop;
77 }
78 return parser::visit_result::Continue;
79 }
80 );
81 }
82
83 return parser::visit_result::SkipChildren;
84 }
85
86 return parser::visit_result::Continue;
87 }

Callers 1

parse_sdkFunction · 0.85

Calls 1

unquote_if_quotedFunction · 0.85

Tested by

no test coverage detected