Expand description
Lightweight C/C++ parser using [tree-sitter-cpp].
This module provides a fast, zero‑dependency alternative to Clang for extracting call‑graph facts from C and C++ source code. It does not perform semantic analysis (types, overload resolution); it only produces syntactic nodes suitable for building a call graph.
§Supported node kinds
Function– function definitions, declarations, and template instantiations,Class– class/struct/union/interface definitions, including template specialisations,CallSite– call expressions,Variable– variable declarations outside parameter lists,Parameter– parameter declarations inside parameter lists.
§Class detection
Unlike the original implementation, this version correctly reads the
name field of class_specifier, struct_specifier and
interface_specifier nodes, which contains the class name as a
type_identifier or identifier. Template parameters are ignored.
§Example
use icb_parser::cpp_tree_sitter::parse_cpp_file;
let code = r#"
template <typename T>
class MyClass {
void method() {}
};
"#;
let facts = parse_cpp_file(code).unwrap();
assert!(facts.iter().any(|n| n.kind == icb_common::NodeKind::Class
&& n.name.as_deref() == Some("MyClass")));Functions§
- function_
name 🔒 - Extract the function name from a function definition/declaration node.
- parent_
kind_ 🔒is - Check whether the node’s immediate parent has the expected kind.
- parse_
cpp_ file - Parse a C/C++ source file and return a flat list of facts.
- traverse_
node 🔒