@@ -30,86 +30,86 @@ extern "C"
3030 /** @brief Abstract Syntax Tree node kind */
3131 typedef enum enum_ps_ast_node_kind
3232 {
33- PS_AST_PROGRAM , /** @brief Block : PROGRAM */
34- PS_AST_PROCEDURE , /** @brief Block : PROCEDURE */
35- PS_AST_FUNCTION , /** @brief Block : FUNCTION */
36- PS_AST_UNIT , /** @brief Block : UNIT */
37- PS_AST_STATEMENT_LIST , /** @brief Statement : List of statements */
38- PS_AST_ASSIGNMENT , /** @brief Statement : Assignment */
39- PS_AST_IF , /** @brief Statement : IF */
40- PS_AST_WHILE , /** @brief Statement : WHILE */
41- PS_AST_REPEAT , /** @brief Statement : REPEAT */
42- PS_AST_FOR , /** @brief Statement : FOR */
43- PS_AST_PROCEDURE_CALL , /** @brief Statement : PROCEDURE call */
44- PS_AST_UNARY_OPERATION , /** @brief Expression : Unary operation */
45- PS_AST_BINARY_OPERATION , /** @brief Expression : Binary operation */
46- PS_AST_FUNCTION_CALL , /** @brief Expression : FUNCTION call */
47- PS_AST_VALUE , /** @brief Expression : Value: integer, real, string, boolean, ... */
48- PS_AST_VARIABLE_SIMPLE , /** @brief Expression : Simple variable (or constant) being accessed */
49- PS_AST_VARIABLE_ARRAY , /** @brief Expression : Array element being accessed */
50- PS_AST_LVALUE_SIMPLE , /** @brief Lvalue : Simple variable being written to */
51- PS_AST_LVALUE_ARRAY , /** @brief Lvalue : Array element being written to */
33+ PS_AST_PROGRAM , /** @brief BLOCK : PROGRAM */
34+ PS_AST_PROCEDURE , /** @brief BLOCK : PROCEDURE */
35+ PS_AST_FUNCTION , /** @brief BLOCK : FUNCTION */
36+ PS_AST_UNIT , /** @brief BLOCK : UNIT */
37+ PS_AST_STATEMENT_LIST , /** @brief STATEMENT : List of statements */
38+ PS_AST_ASSIGNMENT , /** @brief STATEMENT : Assignment */
39+ PS_AST_IF , /** @brief STATEMENT : IF */
40+ PS_AST_WHILE , /** @brief STATEMENT : WHILE */
41+ PS_AST_REPEAT , /** @brief STATEMENT : REPEAT */
42+ PS_AST_FOR , /** @brief STATEMENT : FOR */
43+ PS_AST_PROCEDURE_CALL , /** @brief STATEMENT : PROCEDURE call */
44+ PS_AST_UNARY_OPERATION , /** @brief EXPRESSION : Unary operation */
45+ PS_AST_BINARY_OPERATION , /** @brief EXPRESSION : Binary operation */
46+ PS_AST_FUNCTION_CALL , /** @brief EXPRESSION : FUNCTION call */
47+ PS_AST_VALUE , /** @brief EXPRESSION : Value: integer, real, string, boolean, ... */
48+ PS_AST_VARIABLE_SIMPLE , /** @brief EXPRESSION : Simple variable (or constant) being accessed */
49+ PS_AST_VARIABLE_ARRAY , /** @brief EXPRESSION : Array element being accessed */
50+ PS_AST_LVALUE_SIMPLE , /** @brief LVALUE : Simple variable being written to */
51+ PS_AST_LVALUE_ARRAY , /** @brief LVALUE : Array element being written to */
5252 } __attribute__((__packed__ )) ps_ast_node_kind ;
5353
54- #define PS_AST_NODE_COMMON_FIELDS \
55- ps_ast_node_group group; /** @brief Node group */ \
56- ps_ast_node_kind kind ; /** @brief Node kind */ \
57- uint16_t line ; /** @brief Source code line number for error reporting, 0 if unknown */ \
54+ #define PS_AST_NODE_COMMON \
55+ ps_ast_node_group group; /** @brief Node group */ \
56+ ps_ast_node_kind kind ; /** @brief Node kind */ \
57+ uint16_t line ; /** @brief Source code line number for error reporting, 0 if unknown */ \
5858 uint16_t column ; /** @brief Source code column number for error reporting, 0 if unknown */
5959
6060 /** @brief Abstract Syntax Tree node */
6161 typedef struct s_ps_ast_node
6262 {
63- PS_AST_NODE_COMMON_FIELDS
63+ PS_AST_NODE_COMMON
6464 } ps_ast_node ;
6565
6666 /** @brief Block is a program, procedure, function or unit */
6767 /** @details Units may be separated as they are special cases with interface and implementation */
6868 typedef struct s_ps_ast_block
6969 {
70- PS_AST_NODE_COMMON_FIELDS
71- ps_identifier name ; /** @brief Every block has a name */
72- size_t n_vars ; /** @brief Number of variables to allocate at startup */
73- ps_symbol_table * symbols ; /** @brief Constants, types, variables, procedures and functions */
74- ps_ast_node * statement_list ; /** @brief Statements in this block */
75- ps_formal_signature * signature ; /** @brief Only for procedures and functions, empty otherwise */
76- ps_symbol * result_type ; /** @brief Only for functions, NULL otherwise */
77- size_t n_executables ; /** @brief 1 for PS_AST_PROCEDURE and PS_AST_FUNCTION */
78- ps_ast_node * * executables ; /** @brief declarations of procedures and functions */
70+ PS_AST_NODE_COMMON
71+ ps_identifier name ; /** @brief Every block has a name */
72+ size_t n_vars ; /** @brief Number of variables to allocate at startup */
73+ ps_symbol_table * symbols ; /** @brief Constants, types, variables, procedures and functions */
74+ size_t n_executables ; /** @brief exactly 1 for procedure and function, 0 or more otherwise */
75+ ps_ast_node * * executables ; /** @brief declarations of procedures and functions */
76+ ps_ast_statement_list * statement_list ; /** @brief Statements in this block */
77+ ps_formal_signature * signature ; /** @brief Only for procedures and functions, empty otherwise */
78+ ps_symbol * result_type ; /** @brief Only for functions, NULL otherwise */
7979 } ps_ast_block ;
8080
8181 typedef struct s_ps_ast_statement_list
8282 {
83- PS_AST_NODE_COMMON_FIELDS
83+ PS_AST_NODE_COMMON
8484 size_t count ; /** @brief Number of statements */
8585 ps_ast_node * * statements ; /** @brief NULL if no statements */
8686 } ps_ast_statement_list ;
8787
8888 typedef struct s_ps_ast_if
8989 {
90- PS_AST_NODE_COMMON_FIELDS
90+ PS_AST_NODE_COMMON
9191 ps_ast_node * condition ; /** @brief If condition, must be a boolean expression */
9292 ps_ast_statement_list * then_branch ; /** @brief Statements to execute if condition is true, can be empty */
9393 ps_ast_statement_list * else_branch ; /** @brief Statements to execute if condition is false, can be empty */
9494 } ps_ast_if ;
9595
9696 typedef struct s_ps_ast_while
9797 {
98- PS_AST_NODE_COMMON_FIELDS
98+ PS_AST_NODE_COMMON
9999 ps_ast_node * condition ; /** @brief Loop while condition is true */
100100 ps_ast_statement_list * body ; /** @brief Statements to execute while condition is true */
101101 } ps_ast_while ;
102102
103103 typedef struct s_ps_ast_repeat
104104 {
105- PS_AST_NODE_COMMON_FIELDS
105+ PS_AST_NODE_COMMON
106106 ps_ast_statement_list * body ; /** @brief Statements to execute at least once */
107107 ps_ast_node * condition ; /** @brief Loop until condition is true */
108108 } ps_ast_repeat ;
109109
110110 typedef struct s_ps_ast_for
111111 {
112- PS_AST_NODE_COMMON_FIELDS
112+ PS_AST_NODE_COMMON
113113 ps_ast_node * variable ; /** @brief Loop variable */
114114 ps_ast_node * start ; /** @brief Start value */
115115 ps_ast_node * end ; /** @brief End value */
@@ -119,7 +119,7 @@ extern "C"
119119
120120 typedef struct s_ps_ast_call
121121 {
122- PS_AST_NODE_COMMON_FIELDS
122+ PS_AST_NODE_COMMON
123123 ps_symbol * executable ; /** @brief procedure of function being called */
124124 size_t n_args ; /** @brief number of arguments, 0 if no arguments */
125125 ps_ast_node_argument * args ; /** @brief arguments, NULL if no arguments */
@@ -136,46 +136,46 @@ extern "C"
136136
137137 typedef struct s_ps_ast_assignment
138138 {
139- PS_AST_NODE_COMMON_FIELDS
139+ PS_AST_NODE_COMMON
140140 ps_ast_node * lvalue ; /** @brief variable being assigned to */
141141 ps_ast_node * expression ; /** @brief expression to assign to variable */
142142 } ps_ast_assignment ;
143143
144144 /** @brief Expression: literal value */
145145 typedef struct s_ps_ast_value
146146 {
147- PS_AST_NODE_COMMON_FIELDS
147+ PS_AST_NODE_COMMON
148148 ps_value value ;
149149 } ps_ast_value ;
150150
151151 /** @brief Variable or Lvalue: simple variable */
152152 /** @example I, Total, ... */
153153 typedef struct s_ps_ast_variable_simple
154154 {
155- PS_AST_NODE_COMMON_FIELDS
155+ PS_AST_NODE_COMMON
156156 ps_symbol * variable ; /** @brief Symbol being referenced */
157157 } ps_ast_variable_simple ;
158158
159159 /** @brief Variable or Lvalue: array */
160160 /** @example A[I], A[I, J, K], ... */
161161 typedef struct s_ps_ast_variable_array
162162 {
163- PS_AST_NODE_COMMON_FIELDS
163+ PS_AST_NODE_COMMON
164164 ps_symbol * variable ; /** @brief Symbol being referenced */
165165 size_t n_indexes ; /** @brief For array access, 0 if not an array */
166166 ps_ast_node * * indexes ; /** @brief For array access, NULL if not an array */
167167 } ps_ast_variable_array ;
168168
169169 typedef struct s_ps_ast_unary_operation
170170 {
171- PS_AST_NODE_COMMON_FIELDS
171+ PS_AST_NODE_COMMON
172172 ps_operator_unary operator ;
173173 ps_ast_node * operand ;
174174 } ps_ast_unary_operation ;
175175
176176 typedef struct s_ps_ast_binary_operation
177177 {
178- PS_AST_NODE_COMMON_FIELDS
178+ PS_AST_NODE_COMMON
179179 ps_operator_binary operator ; /** @brief Binary operator */
180180 ps_ast_node * left ; /** @brief Left operand */
181181 ps_ast_node * right ; /** @brief Right operand */
@@ -200,7 +200,7 @@ extern "C"
200200 // clang-format on
201201
202202 /** @brief Create a new AST node of the given kind */
203- ps_ast_node * ps_ast_create_node (ps_ast_node_group group , ps_ast_node_kind kind , uint16_t line , uint16_t column );
203+ ps_ast_node * ps_ast_create_node (ps_ast_node_group group , ps_ast_node_kind kind , uint16_t line , uint16_t column , size_t size );
204204
205205 ps_ast_node * ps_ast_create_block (uint16_t line , uint16_t column , ps_ast_node_kind kind , char * name );
206206 ps_ast_node * ps_ast_create_statement_list (uint16_t line , uint16_t column , size_t count );
0 commit comments