get_source
Retrieve the exact source body of a C/C++ function, enum, or macro using libclang AST extents, returning precise code without guessing line numbers.
Instructions
Read a C/C++ function/method/enum/macro body using libclang exact extents — no guessing line numbers. Uses AST-precise {start, end} extents so you get exactly the function body. Generic file readers don't know where a function actually ends — libclang tracks exact {start, end} from the AST.
For enums, includes a constants array listing all member constants
with their values. For macros, returns kind="macro" with value
(raw definition) and expanded_value (preprocessor-resolved).
For rich context (who calls this, what does it call) use
get_symbol_context instead — it returns body, callers, and callees
in a single call. For the full file, use a normal file read.
Read-only. No side effects.
Args: name: Fully qualified symbol name. Returns exact function body via libclang extent. project_root: Project root. Auto-detected if omitted.
Returns:
dict: {name, qualified_name, kind, file, line, signature,
docstring, is_definition, is_template, is_virtual, is_pure_virtual,
source (str — the function/enum/macro body, truncated at 8000 chars),
warning (str, optional — when source file cannot be read)}.
May also include template_usr, parent_usr, enum_value,
constants (list for enums), value (raw macro definition),
expanded_value (preprocessor-resolved macro value) when applicable.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Fully qualified symbol name. Returns exact function body via libclang extent. | |
| project_root | No | Project root. Auto-detected if omitted. |