1010#include "common.h"
1111#include "value.h"
1212
13- <<<<<<< HEAD
1413// --- Forward Declarations (CRITICAL) ---
15- // These allow the structs to reference each other before full definition.
16- == = == ==
14+ typedef struct Expr Expr ;
15+ typedef struct Stmt Stmt ;
16+ typedef struct ExprList ExprList ;
17+ typedef struct StmtList StmtList ;
18+ typedef struct SwitchCase SwitchCase ;
19+ typedef struct SwitchCaseList SwitchCaseList ;
20+ typedef struct DictPair DictPair ;
21+ typedef struct DictPairList DictPairList ;
22+ typedef struct StringList StringList ;
23+
1724// --- Type System for Static Typing ---
1825typedef enum {
1926 TYPE_UNKNOWN = 0 ,
@@ -32,23 +39,10 @@ typedef struct TypeInfo {
3239
3340 // For functions
3441 struct TypeInfo * returnType ;
35- struct TypeInfo * paramTypes ; // Array or linked list? Let's use array for simplicity if fixed size, or pointer to array.
36- // For simplicity in C without templates, let's use a pointer to a dynamically allocated array of TypeInfos.
42+ struct TypeInfo * paramTypes ;
3743 int paramCount ;
3844} TypeInfo ;
3945
40- // Forward declarations
41- >>>>>>> feature /opcode - tests
42- typedef struct Expr Expr ;
43- typedef struct Stmt Stmt ;
44- typedef struct ExprList ExprList ;
45- typedef struct StmtList StmtList ;
46- typedef struct SwitchCase SwitchCase ;
47- typedef struct SwitchCaseList SwitchCaseList ;
48- typedef struct DictPair DictPair ;
49- typedef struct DictPairList DictPairList ;
50- typedef struct StringList StringList ;
51-
5246// --- Node Types ---
5347
5448typedef enum {
@@ -208,7 +202,7 @@ typedef struct {
208202// --- Main Expression Struct ---
209203struct Expr {
210204 ExprType type ;
211- TypeInfo inferredType ; // [NEW] For Type Checker
205+ TypeInfo inferredType ;
212206 int line ;
213207 int column ;
214208 union {
@@ -239,15 +233,15 @@ typedef struct {
239233typedef struct {
240234 char * name ;
241235 Expr * initializer ;
242- TypeInfo type ; // [NEW] Explicit type declaration
236+ TypeInfo type ;
243237 bool is_const ;
244238} VarDeclStmt ;
245239
246240typedef struct {
247241 char * name ;
248242 StringList * params ;
249243 StmtList * body ;
250- TypeInfo returnType ; // [NEW]
244+ TypeInfo returnType ;
251245} FuncDeclStmt ;
252246
253247typedef struct {
@@ -367,17 +361,37 @@ Stmt *createReturnStmt(Expr *value, int line, int column);
367361Stmt * createBlockStmt (StmtList * statements , int line , int column );
368362Stmt * createBreakStmt (int line , int column );
369363Stmt * createContinueStmt (int line , int column );
370- <<<<<<< HEAD
371364Stmt * createSwitchStmt (Expr * value , SwitchCaseList * cases , StmtList * def , int line , int column );
372365Stmt * createTryCatchStmt (StmtList * try_blk , const char * catch_var , StmtList * catch_blk , StmtList * finally_blk , int line , int column );
373- == == == =
374- Stmt * createSwitchStmt (Expr * value , SwitchCaseList * cases , StmtList * def ,
375- int line , int column );
376- Stmt * createTryCatchStmt (StmtList * try_blk , const char * catch_var ,
377- StmtList * catch_blk , StmtList * finally_blk , int line ,
378- int column );
379366Stmt * createPrintStmt (Expr * expression , int line , int column );
380- >>>>>>> feature /opcode - tests
367+
368+ // List Management
369+ ExprList * createExprList ();
370+ void appendExpr (ExprList * list , Expr * expr );
371+ void freeExprList (ExprList * list );
372+
373+ StmtList * createStmtList ();
374+ void appendStmt (StmtList * list , Stmt * stmt );
375+ void freeStmtList (StmtList * list );
376+
377+ StringList * createStringList ();
378+ void appendString (StringList * list , const char * str );
379+ void freeStringList (StringList * list );
380+
381+ DictPairList * createDictPairList ();
382+ void appendDictPair (DictPairList * list , Expr * key , Expr * value );
383+ void freeDictPairList (DictPairList * list );
384+
385+ SwitchCaseList * createSwitchCaseList ();
386+ void appendSwitchCase (SwitchCaseList * list , Expr * value , StmtList * statements );
387+ void freeSwitchCaseList (SwitchCaseList * list );
388+
389+ // Memory Management
390+ void freeExpr (Expr * expr );
391+ void freeStmt (Stmt * stmt );
392+
393+ #endif // PROX_AST_H
394+
381395
382396// List Management
383397ExprList * createExprList ();
0 commit comments