Luma 0.1.0
A low-level compiled alternative to C, C++, and more!
Loading...
Searching...
No Matches
Classes | Typedefs | Enumerations | Functions | Variables
type.h File Reference

Type checking and symbol table management for AST nodes with memory tracking. More...

#include "../ast/ast.h"
#include "../c_libs/memory/memory.h"
#include "../helper/help.h"
#include "../lexer/lexer.h"
Include dependency graph for type.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  StaticAllocation
 
struct  StaticMemoryAnalyzer
 
struct  Symbol
 Represents a symbol with associated type and metadata. More...
 
struct  Scope
 Represents a lexical scope with hierarchical relationships. More...
 
struct  ModuleImport
 Represents an imported module with optional aliasing. More...
 
struct  ModuleDependency
 
struct  TypeError
 Represents an error encountered during type checking. More...
 

Typedefs

typedef struct Scope Scope
 Represents a lexical scope with hierarchical relationships.
 

Enumerations

enum  TypeMatchResult { TYPE_MATCH_EXACT , TYPE_MATCH_COMPATIBLE , TYPE_MATCH_NONE }
 Result of type compatibility checking. More...
 

Functions

void static_memory_analyzer_init (StaticMemoryAnalyzer *analyzer, ArenaAllocator *arena)
 
void static_memory_track_alloc (StaticMemoryAnalyzer *analyzer, size_t line, size_t column, const char *var_name, const char *function_name, Token *tokens, size_t token_count, const char *file_path)
 
void static_memory_track_free (StaticMemoryAnalyzer *analyzer, const char *var_name, const char *function_name, bool is_conditional)
 
int static_memory_check_and_report (StaticMemoryAnalyzer *analyzer, ArenaAllocator *arena)
 
bool static_memory_check_use_after_free (StaticMemoryAnalyzer *analyzer, const char *var_name, size_t line, size_t column, ArenaAllocator *arena, Token *tokens, int token_count, const char *file_path, const char *function_name)
 
StaticMemoryAnalyzerget_static_analyzer (Scope *scope)
 
void static_memory_track_alias (StaticMemoryAnalyzer *analyzer, const char *new_var, const char *source_var, const char *function_name)
 
void static_memory_mark_addr_taken (StaticMemoryAnalyzer *analyzer, const char *var_name, const char *function_name)
 
void static_memory_check_free_nonalloc (StaticMemoryAnalyzer *analyzer, const char *var_name, size_t line, size_t column, Token *tokens, int token_count, const char *file_path, const char *function_name, ArenaAllocator *arena)
 
bool is_pointer_assignment (AstNode *assignment)
 
void init_scope (Scope *scope, Scope *parent, const char *name, ArenaAllocator *arena)
 Initialize a scope structure with enhanced metadata.
 
bool scope_add_symbol (Scope *scope, const char *name, AstNode *type, bool is_public, bool is_mutable, ArenaAllocator *arena)
 
bool scope_add_symbol_with_ownership (Scope *scope, const char *name, AstNode *type, bool is_public, bool is_mutable, bool returns_ownership, bool takes_ownership, ArenaAllocator *arena)
 
Symbolscope_lookup (Scope *scope, const char *name)
 Original scope_lookup - now wraps the visibility version.
 
Symbolscope_lookup_current_only (Scope *scope, const char *name)
 Original scope_lookup_current_only - now wraps the visibility version.
 
Symbolscope_lookup_with_visibility (Scope *scope, const char *name, Scope *requesting_module_scope)
 
Symbolscope_lookup_current_only_with_visibility (Scope *scope, const char *name, Scope *requesting_module_scope)
 Look up a symbol only in the current scope with visibility rules.
 
Scopefind_containing_module (Scope *scope)
 Find the containing module scope for a given scope.
 
Scopecreate_child_scope (Scope *parent, const char *name, ArenaAllocator *arena)
 Create a new child scope under the specified parent.
 
void debug_print_scope (Scope *scope, int indent_level)
 
void debug_print_struct_type (AstNode *struct_type, int indent)
 
void build_dependency_graph (AstNode **modules, size_t module_count, GrowableArray *dep_graph, ArenaAllocator *arena)
 
bool process_module_in_order (const char *module_name, GrowableArray *dep_graph, AstNode **modules, size_t module_count, Scope *global_scope, ArenaAllocator *arena)
 Process modules in dependency order (topological sort)
 
bool typecheck_program_multipass (AstNode *program, Scope *global_scope, ArenaAllocator *arena)
 Three-pass typechecking for modules to handle forward references.
 
const char * get_current_function_name (Scope *scope)
 
bool register_module (Scope *global_scope, const char *module_name, Scope *module_scope, ArenaAllocator *arena)
 Register a module scope in the global scope.
 
Scopefind_module_scope (Scope *global_scope, const char *module_name)
 Find a module scope by name.
 
bool add_module_import (Scope *importing_scope, const char *module_name, const char *alias, Scope *module_scope, ArenaAllocator *arena)
 Add a module import to a scope.
 
Symbollookup_qualified_symbol (Scope *scope, const char *module_alias, const char *symbol_name)
 Look up a qualified symbol (module_alias.symbol_name) with visibility rules.
 
Scopecreate_module_scope (Scope *global_scope, const char *module_name, ArenaAllocator *arena)
 Create a new module scope.
 
bool typecheck_module_stmt (AstNode *node, Scope *global_scope, ArenaAllocator *arena)
 
bool typecheck_use_stmt (AstNode *node, Scope *current_scope, Scope *global_scope, ArenaAllocator *arena)
 
void tc_error_init (Token *tokens, int token_count, const char *file_path, ArenaAllocator *arena)
 Set global context for error reporting Call this once at the start of typechecking.
 
void tc_error (AstNode *node, const char *error_type, const char *format,...)
 Simple error reporting - replaces fprintf(stderr, ...) Usage: tc_error(node, "Type Error", "Variable '%s' not found", var_name);.
 
void tc_error_help (AstNode *node, const char *error_type, const char *help, const char *format,...)
 Error with help message.
 
void tc_error_id (AstNode *node, const char *identifier, const char *error_type, const char *format,...)
 Error with identifier highlighting.
 
TypeMatchResult types_match (AstNode *type1, AstNode *type2)
 
bool is_numeric_type (AstNode *type)
 
bool is_integer_type (AstNode *type)
 
bool is_pointer_type (AstNode *type)
 
bool is_pointer_to_function_type (AstNode *type)
 
bool is_array_type (AstNode *type)
 
bool is_void_type (AstNode *type)
 
bool is_bool_type (AstNode *type)
 
bool is_struct_type_node (AstNode *type)
 
bool is_function_type (AstNode *type)
 
bool is_cast_valid (AstNode *from_type, AstNode *to_type)
 
AstNodeget_element_type (AstNode *array_or_pointer_type, ArenaAllocator *arena)
 
const char * type_to_string (AstNode *type, ArenaAllocator *arena)
 
bool contains_alloc_expression (AstNode *expr)
 
bool typecheck (AstNode *node, Scope *scope, ArenaAllocator *arena, BuildConfig *config)
 
AstNodetypecheck_expression (AstNode *expr, Scope *scope, ArenaAllocator *arena)
 
bool typecheck_statement (AstNode *stmt, Scope *scope, ArenaAllocator *arena)
 
const char * extract_variable_name (AstNode *expr)
 
bool typecheck_var_decl (AstNode *node, Scope *scope, ArenaAllocator *arena)
 
bool typecheck_func_decl (AstNode *node, Scope *scope, ArenaAllocator *arena)
 
AstNodecreate_struct_type (ArenaAllocator *arena, const char *name, AstNode **member_types, const char **member_names, size_t member_count, size_t line, size_t column)
 
AstNodeget_struct_member_type (AstNode *struct_type, const char *member_name)
 
bool struct_has_member (AstNode *struct_type, const char *member_name)
 
bool typecheck_struct_decl (AstNode *node, Scope *scope, ArenaAllocator *arena)
 
bool typecheck_spread_decl (AstNode *spread, Scope *scope, ArenaAllocator *arena, const char *child_name, GrowableArray *seen_names, AstNode ***member_types, const char ***member_names, size_t *member_count)
 
bool typecheck_enum_decl (AstNode *node, Scope *scope, ArenaAllocator *arena)
 
bool typecheck_return_decl (AstNode *node, Scope *scope, ArenaAllocator *arena)
 
bool typecheck_if_decl (AstNode *node, Scope *scope, ArenaAllocator *arena)
 
bool typecheck_defer_decl (AstNode *node, Scope *scope, ArenaAllocator *arena)
 
bool typecheck_switch_stmt (AstNode *node, Scope *scope, ArenaAllocator *arena)
 
bool typecheck_case_stmt (AstNode *node, Scope *scope, ArenaAllocator *arena, AstNode *expected_type)
 
bool typecheck_default_stmt (AstNode *node, Scope *scope, ArenaAllocator *arena)
 
bool typecheck_infinite_loop_decl (AstNode *node, Scope *scope, ArenaAllocator *arena)
 
bool typecheck_while_loop_decl (AstNode *node, Scope *scope, ArenaAllocator *arena)
 
bool typecheck_for_loop_decl (AstNode *node, Scope *scope, ArenaAllocator *arena)
 
bool typecheck_loop_decl (AstNode *node, Scope *scope, ArenaAllocator *arena)
 
bool typecheck_os_stmt (AstNode *node, Scope *scope, ArenaAllocator *arena)
 
bool typecheck_link_stmt (AstNode *node, Scope *scope, ArenaAllocator *arena)
 
AstNodetypecheck_binary_expr (AstNode *expr, Scope *scope, ArenaAllocator *arena)
 
AstNodetypecheck_unary_expr (AstNode *expr, Scope *scope, ArenaAllocator *arena)
 
AstNodetypecheck_call_expr (AstNode *expr, Scope *scope, ArenaAllocator *arena)
 
AstNodetypecheck_member_expr (AstNode *expr, Scope *scope, ArenaAllocator *arena)
 
AstNodetypecheck_index_expr (AstNode *expr, Scope *scope, ArenaAllocator *arena)
 
AstNodetypecheck_deref_expr (AstNode *expr, Scope *scope, ArenaAllocator *arena)
 
AstNodetypecheck_addr_expr (AstNode *expr, Scope *scope, ArenaAllocator *arena)
 
AstNodetypecheck_alloc_expr (AstNode *expr, Scope *scope, ArenaAllocator *arena)
 
AstNodetypecheck_free_expr (AstNode *expr, Scope *scope, ArenaAllocator *arena)
 
AstNodetypecheck_memcpy_expr (AstNode *expr, Scope *scope, ArenaAllocator *arena)
 
AstNodetypecheck_cast_expr (AstNode *expr, Scope *scope, ArenaAllocator *arena)
 
AstNodetypecheck_input_expr (AstNode *expr, Scope *scope, ArenaAllocator *arena)
 
AstNodetypecheck_system_expr (AstNode *expr, Scope *scope, ArenaAllocator *arena)
 
AstNodetypecheck_sizeof_expr (AstNode *expr, Scope *scope, ArenaAllocator *arena)
 
AstNodetypecheck_assignment_expr (AstNode *expr, Scope *scope, ArenaAllocator *arena)
 
AstNodetypecheck_array_expr (AstNode *expr, Scope *scope, ArenaAllocator *arena)
 
AstNodetypecheck_syscall_expr (AstNode *expr, Scope *scope, ArenaAllocator *arena)
 Type check a syscall expression.
 
AstNodetypecheck_struct_expr_internal (AstNode *expr, Scope *scope, ArenaAllocator *arena, AstNode *expected_type)
 
AstNodetypecheck_struct_expr (AstNode *expr, Scope *scope, ArenaAllocator *arena)
 
AstNodeget_enclosing_function_return_type (Scope *scope)
 
bool validate_array_type (AstNode *array_type, Scope *scope, ArenaAllocator *arena)
 
bool check_array_bounds (AstNode *array_type, AstNode *index_expr, ArenaAllocator *arena)
 
AstNodetypecheck_multidim_array_access (AstNode *base_type, AstNode **indices, size_t index_count, ArenaAllocator *arena)
 
TypeMatchResult check_array_compatibility (AstNode *type1, AstNode *type2)
 
bool validate_array_initializer (AstNode *declared_type, AstNode *initializer, Scope *scope, ArenaAllocator *arena)
 
void print_type_error (TypeError *error)
 

Variables

Tokeng_tokens
 
int g_token_count
 
const char * g_file_path
 
ArenaAllocatorg_arena
 

Detailed Description

Type checking and symbol table management for AST nodes with memory tracking.

Provides type checking for the Abstract Syntax Tree (AST), including:

Typedef Documentation

◆ Scope

typedef struct Scope Scope

Represents a lexical scope with hierarchical relationships.

Enumeration Type Documentation

◆ TypeMatchResult

Result of type compatibility checking.

Enumerator
TYPE_MATCH_EXACT 

Types match exactly

TYPE_MATCH_COMPATIBLE 

Implicitly convertible

TYPE_MATCH_NONE 

Incompatible

Function Documentation

◆ add_module_import()

bool add_module_import ( Scope importing_scope,
const char *  module_name,
const char *  alias,
Scope module_scope,
ArenaAllocator arena 
)

Add a module import to a scope.

◆ build_dependency_graph()

void build_dependency_graph ( AstNode **  modules,
size_t  module_count,
GrowableArray dep_graph,
ArenaAllocator arena 
)

◆ check_array_bounds()

bool check_array_bounds ( AstNode array_type,
AstNode index_expr,
ArenaAllocator arena 
)

◆ check_array_compatibility()

TypeMatchResult check_array_compatibility ( AstNode type1,
AstNode type2 
)

◆ contains_alloc_expression()

bool contains_alloc_expression ( AstNode expr)

◆ create_child_scope()

Scope * create_child_scope ( Scope parent,
const char *  name,
ArenaAllocator arena 
)

Create a new child scope under the specified parent.

Allocates and initializes a new scope as a child of the given parent, automatically establishing the parent-child relationship and adding the new scope to the parent's children list.

Parameters
parentParent scope for the new child (NULL for root scope)
nameDescriptive name for the new scope
arenaArena allocator for memory management
Returns
Pointer to the newly created and initialized child scope

Creation process:

  1. Allocate memory for new Scope structure from arena
  2. Initialize the scope with proper parent linkage
  3. Add the new scope to parent's children array (if parent exists)
  4. Return pointer to fully initialized child scope
Note
The child scope is automatically added to the parent's children list, maintaining the bidirectional parent-child relationship for debugging and traversal purposes
Warning
If memory allocation fails, this function may return NULL or an incompletely initialized scope. The caller should verify successful creation before using the returned scope.
If adding the child to the parent's children array fails due to memory constraints, the child scope will still be created and functional, but won't appear in the parent's children list.

◆ create_module_scope()

Scope * create_module_scope ( Scope global_scope,
const char *  module_name,
ArenaAllocator arena 
)

Create a new module scope.

◆ create_struct_type()

AstNode * create_struct_type ( ArenaAllocator arena,
const char *  name,
AstNode **  member_types,
const char **  member_names,
size_t  member_count,
size_t  line,
size_t  column 
)

◆ debug_print_scope()

void debug_print_scope ( Scope scope,
int  indent_level 
)

◆ debug_print_struct_type()

void debug_print_struct_type ( AstNode struct_type,
int  indent 
)

◆ extract_variable_name()

const char * extract_variable_name ( AstNode expr)

◆ find_containing_module()

Scope * find_containing_module ( Scope scope)

Find the containing module scope for a given scope.

◆ find_module_scope()

Scope * find_module_scope ( Scope global_scope,
const char *  module_name 
)

Find a module scope by name.

◆ get_current_function_name()

const char * get_current_function_name ( Scope scope)

◆ get_element_type()

AstNode * get_element_type ( AstNode array_or_pointer_type,
ArenaAllocator arena 
)

◆ get_enclosing_function_return_type()

AstNode * get_enclosing_function_return_type ( Scope scope)

◆ get_static_analyzer()

StaticMemoryAnalyzer * get_static_analyzer ( Scope scope)

◆ get_struct_member_type()

AstNode * get_struct_member_type ( AstNode struct_type,
const char *  member_name 
)

◆ init_scope()

void init_scope ( Scope scope,
Scope parent,
const char *  name,
ArenaAllocator arena 
)

Initialize a scope structure with enhanced metadata.

Sets up a new scope with proper initialization of all fields, including parent-child relationships, depth calculation, and growable arrays for symbols and children. The scope is fully prepared for symbol addition and child scope creation.

Parameters
scopePointer to the scope structure to initialize (must be pre-allocated)
parentParent scope for hierarchical lookup (NULL for global scope)
nameDescriptive name for debugging and identification (NULL becomes "unnamed")
arenaArena allocator for all memory allocations within this scope

Initialization includes:

  • Parent pointer assignment and depth calculation
  • Name duplication into arena memory for persistence
  • Default flag initialization (not a function scope, no associated AST node)
  • Growable array setup with reasonable initial capacities (16 symbols, 8 children)
Note
The scope name is duplicated using arena allocation, ensuring it remains valid for the lifetime of the scope without external string management
Warning
The scope parameter must point to valid, allocated memory. This function does not allocate the scope structure itself, only initializes it.

◆ is_array_type()

bool is_array_type ( AstNode type)

◆ is_bool_type()

bool is_bool_type ( AstNode type)

◆ is_cast_valid()

bool is_cast_valid ( AstNode from_type,
AstNode to_type 
)

◆ is_function_type()

bool is_function_type ( AstNode type)

◆ is_integer_type()

bool is_integer_type ( AstNode type)

◆ is_numeric_type()

bool is_numeric_type ( AstNode type)

◆ is_pointer_assignment()

bool is_pointer_assignment ( AstNode assignment)

◆ is_pointer_to_function_type()

bool is_pointer_to_function_type ( AstNode type)

◆ is_pointer_type()

bool is_pointer_type ( AstNode type)

◆ is_struct_type_node()

bool is_struct_type_node ( AstNode type)

◆ is_void_type()

bool is_void_type ( AstNode type)

◆ lookup_qualified_symbol()

Symbol * lookup_qualified_symbol ( Scope scope,
const char *  module_alias,
const char *  symbol_name 
)

Look up a qualified symbol (module_alias.symbol_name) with visibility rules.

◆ print_type_error()

void print_type_error ( TypeError error)

◆ process_module_in_order()

bool process_module_in_order ( const char *  module_name,
GrowableArray dep_graph,
AstNode **  modules,
size_t  module_count,
Scope global_scope,
ArenaAllocator arena 
)

Process modules in dependency order (topological sort)

◆ register_module()

bool register_module ( Scope global_scope,
const char *  module_name,
Scope module_scope,
ArenaAllocator arena 
)

Register a module scope in the global scope.

◆ scope_add_symbol()

bool scope_add_symbol ( Scope scope,
const char *  name,
AstNode type,
bool  is_public,
bool  is_mutable,
ArenaAllocator arena 
)

◆ scope_add_symbol_with_ownership()

bool scope_add_symbol_with_ownership ( Scope scope,
const char *  name,
AstNode type,
bool  is_public,
bool  is_mutable,
bool  returns_ownership,
bool  takes_ownership,
ArenaAllocator arena 
)

◆ scope_lookup()

Symbol * scope_lookup ( Scope scope,
const char *  name 
)

Original scope_lookup - now wraps the visibility version.

◆ scope_lookup_current_only()

Symbol * scope_lookup_current_only ( Scope scope,
const char *  name 
)

Original scope_lookup_current_only - now wraps the visibility version.

◆ scope_lookup_current_only_with_visibility()

Symbol * scope_lookup_current_only_with_visibility ( Scope scope,
const char *  name,
Scope requesting_module_scope 
)

Look up a symbol only in the current scope with visibility rules.

◆ scope_lookup_with_visibility()

Symbol * scope_lookup_with_visibility ( Scope scope,
const char *  name,
Scope requesting_module_scope 
)

◆ static_memory_analyzer_init()

void static_memory_analyzer_init ( StaticMemoryAnalyzer analyzer,
ArenaAllocator arena 
)

◆ static_memory_check_and_report()

int static_memory_check_and_report ( StaticMemoryAnalyzer analyzer,
ArenaAllocator arena 
)

◆ static_memory_check_free_nonalloc()

void static_memory_check_free_nonalloc ( StaticMemoryAnalyzer analyzer,
const char *  var_name,
size_t  line,
size_t  column,
Token tokens,
int  token_count,
const char *  file_path,
const char *  function_name,
ArenaAllocator arena 
)

◆ static_memory_check_use_after_free()

bool static_memory_check_use_after_free ( StaticMemoryAnalyzer analyzer,
const char *  var_name,
size_t  line,
size_t  column,
ArenaAllocator arena,
Token tokens,
int  token_count,
const char *  file_path,
const char *  function_name 
)

◆ static_memory_mark_addr_taken()

void static_memory_mark_addr_taken ( StaticMemoryAnalyzer analyzer,
const char *  var_name,
const char *  function_name 
)

◆ static_memory_track_alias()

void static_memory_track_alias ( StaticMemoryAnalyzer analyzer,
const char *  new_var,
const char *  source_var,
const char *  function_name 
)

◆ static_memory_track_alloc()

void static_memory_track_alloc ( StaticMemoryAnalyzer analyzer,
size_t  line,
size_t  column,
const char *  var_name,
const char *  function_name,
Token tokens,
size_t  token_count,
const char *  file_path 
)

◆ static_memory_track_free()

void static_memory_track_free ( StaticMemoryAnalyzer analyzer,
const char *  var_name,
const char *  function_name,
bool  is_conditional 
)

◆ struct_has_member()

bool struct_has_member ( AstNode struct_type,
const char *  member_name 
)

◆ tc_error()

void tc_error ( AstNode node,
const char *  error_type,
const char *  format,
  ... 
)

Simple error reporting - replaces fprintf(stderr, ...) Usage: tc_error(node, "Type Error", "Variable '%s' not found", var_name);.

◆ tc_error_help()

void tc_error_help ( AstNode node,
const char *  error_type,
const char *  help,
const char *  format,
  ... 
)

Error with help message.

◆ tc_error_id()

void tc_error_id ( AstNode node,
const char *  identifier,
const char *  error_type,
const char *  format,
  ... 
)

Error with identifier highlighting.

◆ tc_error_init()

void tc_error_init ( Token tokens,
int  token_count,
const char *  file_path,
ArenaAllocator arena 
)

Set global context for error reporting Call this once at the start of typechecking.

◆ type_to_string()

const char * type_to_string ( AstNode type,
ArenaAllocator arena 
)

◆ typecheck()

bool typecheck ( AstNode node,
Scope scope,
ArenaAllocator arena,
BuildConfig config 
)

◆ typecheck_addr_expr()

AstNode * typecheck_addr_expr ( AstNode expr,
Scope scope,
ArenaAllocator arena 
)

◆ typecheck_alloc_expr()

AstNode * typecheck_alloc_expr ( AstNode expr,
Scope scope,
ArenaAllocator arena 
)

◆ typecheck_array_expr()

AstNode * typecheck_array_expr ( AstNode expr,
Scope scope,
ArenaAllocator arena 
)

◆ typecheck_assignment_expr()

AstNode * typecheck_assignment_expr ( AstNode expr,
Scope scope,
ArenaAllocator arena 
)

◆ typecheck_binary_expr()

AstNode * typecheck_binary_expr ( AstNode expr,
Scope scope,
ArenaAllocator arena 
)

◆ typecheck_call_expr()

AstNode * typecheck_call_expr ( AstNode expr,
Scope scope,
ArenaAllocator arena 
)

◆ typecheck_case_stmt()

bool typecheck_case_stmt ( AstNode node,
Scope scope,
ArenaAllocator arena,
AstNode expected_type 
)

◆ typecheck_cast_expr()

AstNode * typecheck_cast_expr ( AstNode expr,
Scope scope,
ArenaAllocator arena 
)

◆ typecheck_default_stmt()

bool typecheck_default_stmt ( AstNode node,
Scope scope,
ArenaAllocator arena 
)

◆ typecheck_defer_decl()

bool typecheck_defer_decl ( AstNode node,
Scope scope,
ArenaAllocator arena 
)

◆ typecheck_deref_expr()

AstNode * typecheck_deref_expr ( AstNode expr,
Scope scope,
ArenaAllocator arena 
)

◆ typecheck_enum_decl()

bool typecheck_enum_decl ( AstNode node,
Scope scope,
ArenaAllocator arena 
)

◆ typecheck_expression()

AstNode * typecheck_expression ( AstNode expr,
Scope scope,
ArenaAllocator arena 
)

◆ typecheck_for_loop_decl()

bool typecheck_for_loop_decl ( AstNode node,
Scope scope,
ArenaAllocator arena 
)

◆ typecheck_free_expr()

AstNode * typecheck_free_expr ( AstNode expr,
Scope scope,
ArenaAllocator arena 
)

◆ typecheck_func_decl()

bool typecheck_func_decl ( AstNode node,
Scope scope,
ArenaAllocator arena 
)

◆ typecheck_if_decl()

bool typecheck_if_decl ( AstNode node,
Scope scope,
ArenaAllocator arena 
)

◆ typecheck_index_expr()

AstNode * typecheck_index_expr ( AstNode expr,
Scope scope,
ArenaAllocator arena 
)

◆ typecheck_infinite_loop_decl()

bool typecheck_infinite_loop_decl ( AstNode node,
Scope scope,
ArenaAllocator arena 
)

◆ typecheck_input_expr()

AstNode * typecheck_input_expr ( AstNode expr,
Scope scope,
ArenaAllocator arena 
)

◆ typecheck_link_stmt()

bool typecheck_link_stmt ( AstNode node,
Scope scope,
ArenaAllocator arena 
)

◆ typecheck_loop_decl()

bool typecheck_loop_decl ( AstNode node,
Scope scope,
ArenaAllocator arena 
)

◆ typecheck_member_expr()

AstNode * typecheck_member_expr ( AstNode expr,
Scope scope,
ArenaAllocator arena 
)

◆ typecheck_memcpy_expr()

AstNode * typecheck_memcpy_expr ( AstNode expr,
Scope scope,
ArenaAllocator arena 
)

◆ typecheck_module_stmt()

bool typecheck_module_stmt ( AstNode node,
Scope global_scope,
ArenaAllocator arena 
)

◆ typecheck_multidim_array_access()

AstNode * typecheck_multidim_array_access ( AstNode base_type,
AstNode **  indices,
size_t  index_count,
ArenaAllocator arena 
)

◆ typecheck_os_stmt()

bool typecheck_os_stmt ( AstNode node,
Scope scope,
ArenaAllocator arena 
)

◆ typecheck_program_multipass()

bool typecheck_program_multipass ( AstNode program,
Scope global_scope,
ArenaAllocator arena 
)

Three-pass typechecking for modules to handle forward references.

This allows modules to be declared and used in any order by:

  • Pass 1: Registering all module scopes (creates namespaces)
  • Pass 2: Processing all @use statements (resolves imports)
  • Pass 3: Typechecking module bodies (validates code)
Parameters
programAST_PROGRAM node containing all modules
global_scopeGlobal scope to register modules in
arenaArena allocator for memory management
Returns
true if all passes succeed, false on any error

◆ typecheck_return_decl()

bool typecheck_return_decl ( AstNode node,
Scope scope,
ArenaAllocator arena 
)

◆ typecheck_sizeof_expr()

AstNode * typecheck_sizeof_expr ( AstNode expr,
Scope scope,
ArenaAllocator arena 
)

◆ typecheck_spread_decl()

bool typecheck_spread_decl ( AstNode spread,
Scope scope,
ArenaAllocator arena,
const char *  child_name,
GrowableArray seen_names,
AstNode ***  member_types,
const char ***  member_names,
size_t *  member_count 
)

◆ typecheck_statement()

bool typecheck_statement ( AstNode stmt,
Scope scope,
ArenaAllocator arena 
)

◆ typecheck_struct_decl()

bool typecheck_struct_decl ( AstNode node,
Scope scope,
ArenaAllocator arena 
)

◆ typecheck_struct_expr()

AstNode * typecheck_struct_expr ( AstNode expr,
Scope scope,
ArenaAllocator arena 
)

◆ typecheck_struct_expr_internal()

AstNode * typecheck_struct_expr_internal ( AstNode expr,
Scope scope,
ArenaAllocator arena,
AstNode expected_type 
)

◆ typecheck_switch_stmt()

bool typecheck_switch_stmt ( AstNode node,
Scope scope,
ArenaAllocator arena 
)

◆ typecheck_syscall_expr()

AstNode * typecheck_syscall_expr ( AstNode expr,
Scope scope,
ArenaAllocator arena 
)

Type check a syscall expression.

Syscall requires:

  • First argument: syscall number (int)
  • Remaining arguments: syscall parameters (typically int or pointer types)

Returns: int (the return value from the syscall)

◆ typecheck_system_expr()

AstNode * typecheck_system_expr ( AstNode expr,
Scope scope,
ArenaAllocator arena 
)

◆ typecheck_unary_expr()

AstNode * typecheck_unary_expr ( AstNode expr,
Scope scope,
ArenaAllocator arena 
)

◆ typecheck_use_stmt()

bool typecheck_use_stmt ( AstNode node,
Scope current_scope,
Scope global_scope,
ArenaAllocator arena 
)

◆ typecheck_var_decl()

bool typecheck_var_decl ( AstNode node,
Scope scope,
ArenaAllocator arena 
)

◆ typecheck_while_loop_decl()

bool typecheck_while_loop_decl ( AstNode node,
Scope scope,
ArenaAllocator arena 
)

◆ types_match()

TypeMatchResult types_match ( AstNode type1,
AstNode type2 
)

◆ validate_array_initializer()

bool validate_array_initializer ( AstNode declared_type,
AstNode initializer,
Scope scope,
ArenaAllocator arena 
)

◆ validate_array_type()

bool validate_array_type ( AstNode array_type,
Scope scope,
ArenaAllocator arena 
)

Variable Documentation

◆ g_arena

ArenaAllocator* g_arena
extern

◆ g_file_path

const char* g_file_path
extern

◆ g_token_count

int g_token_count
extern

◆ g_tokens

Token* g_tokens
extern