Porytiles
Loading...
Searching...
No Matches
porytiles::FunctionDefinition Class Reference

Represents a parsed C function definition. More...

#include <function_definition.hpp>

Public Member Functions

 FunctionDefinition (std::string name, std::vector< Token > body_tokens, SourcePosition position)
 Constructs a FunctionDefinition.
 
const std::string & name () const
 Returns the function name.
 
const std::vector< Token > & body_tokens () const
 Returns the function body tokens.
 
const SourcePositionposition () const
 Returns the source position of the function name.
 

Detailed Description

Represents a parsed C function definition.

FunctionDefinition captures the name and body tokens of a C function definition like:

static void QueueAnimTiles_General_Flower(u16 timer) {
u16 i = timer % ARRAY_COUNT(gTilesetAnims_General_Flower);
AppendTilesetAnimToBuffer(..., TILE_OFFSET_4BPP(12), 4 * TILE_SIZE_4BPP);
}

Rather than parsing the function body into an AST, we capture the raw tokens between the braces. This allows for targeted pattern matching within the body (e.g., finding TILE_OFFSET_4BPP calls) without implementing a full C parser.

Invariant
name_ is never empty
position_ contains valid 1-based line and column numbers

Definition at line 30 of file function_definition.hpp.

Constructor & Destructor Documentation

◆ FunctionDefinition()

porytiles::FunctionDefinition::FunctionDefinition ( std::string  name,
std::vector< Token body_tokens,
SourcePosition  position 
)
inline

Constructs a FunctionDefinition.

Parameters
nameThe function name
body_tokensAll tokens between the opening and closing braces (exclusive of braces)
positionThe source position of the function name

Definition at line 39 of file function_definition.hpp.

Member Function Documentation

◆ body_tokens()

const std::vector< Token > & porytiles::FunctionDefinition::body_tokens ( ) const
inline

Returns the function body tokens.

Returns all tokens that appeared between the opening and closing braces of the function body. The braces themselves are not included. This allows callers to perform targeted pattern matching for specific constructs like macro invocations.

Returns
A const reference to the body token vector

Definition at line 64 of file function_definition.hpp.

◆ name()

const std::string & porytiles::FunctionDefinition::name ( ) const
inline

Returns the function name.

Returns
A const reference to the name

Definition at line 49 of file function_definition.hpp.

◆ position()

const SourcePosition & porytiles::FunctionDefinition::position ( ) const
inline

Returns the source position of the function name.

Returns
A const reference to the source position

Definition at line 74 of file function_definition.hpp.


The documentation for this class was generated from the following file: