Skip to main content
The Symbol is the primary way developers interact with code in Codegen. It maps to how developers think about code - as functions, classes, variables, and other named entities. Both the Function and Class symbols are subclasses of the Symbol class.

Accessing Symbols

The Codebase class provides getters and iterators for functions, classes and symbols:

Shared APIs

All symbols share common APIs for manipulation:

Name operations

Function Statement Manipulation

Functions provide special APIs for adding statements to their body:
The statement manipulation APIs (prepend_statements and add_statements) are only available on Function objects. For other symbols, use the general Editable APIs like insert_before and insert_after.

Common Patterns

Most Codegen programs focus on finding and manipulating symbols:
The Symbol API is designed to be intuitive and match how developers think about code. Most transformations start with finding relevant symbols and then applying changes to them.