Skip to main content

Module parser

Module parser 

Source
Expand description

High‑performance Clang AST visitor that extracts ICB facts for the Code Property Graph.

§Overview

The parser translates a single C/C++ translation unit (TU) into a flat vector of RawNode values. It traverses the Clang AST recursively, but only materialises nodes that are relevant for call‑graph construction:

  • Functions and methods (Function),
  • Classes, structs (Class),
  • Call expressions (CallSite),
  • Variable declarations (Variable),
  • Parameter declarations (Parameter).

All other AST constructs – compound statements, binary operators, implicit casts – are transparently skipped. This keeps memory usage linear in the number of interesting declarations instead of quadratic in the AST depth.

§System header isolation

When allow_system is false, any cursor whose location Clang considers a system header is dropped together with its entire subtree. This removes thousands of standard‑library nodes at almost zero cost and is enabled by default in the CLI and server.

§Memory safety

Every CXString obtained from the Clang API is disposed via clang_disposeString immediately after its contents have been copied to a Rust String. Temporary C strings created for command‑line arguments are converted back to owned CString and dropped when no longer needed.

§Concurrency

A single parse_cpp_file call processes one TU on the calling thread. Parallelism is achieved by processing multiple TUs concurrently at the project level (see super::project).

§Limitations

  • The parser does not resolve overloaded functions – it stores the spelling of the call expression or its referenced entity as‑is.
  • Template instantiations are visited as part of the parent TU, which may cause the same function body to be processed multiple times.
  • Precompiled headers are not supported.

Structs§

VisitorContext 🔒

Functions§

body_visitor_callback 🔒
cursor_file 🔒
Returns the absolute path of the source file that contains cursor, or None if the information is unavailable.
cursor_location 🔒
cursor_spelling 🔒
cursor_usr 🔒
function_body_location 🔒
Returns the source location of the first compound_statement child of the given function/method cursor. Falls back to the cursor’s own extent when no compound statement is present (e.g. for forward declarations).
is_in_system_header 🔒
Returns true when the given cursor resides in a file that Clang treats as a system header.
parse_cpp_file
Parse a single C/C++ source file and return the extracted facts.
visit_children 🔒
visitor_callback 🔒