8create_identifier_node(
const char* identifier)
11 if(is_number(identifier))
12 identifier_node->
token = NUMBER;
14 identifier_node->
token = IDENTIFIER;
15 astnode_set_buffer(identifier,identifier_node);
16 return identifier_node;
19create_type_qualifier(
const char* tqual)
21 if(!tqual)
return NULL;
23 astnode_set_buffer(tqual,tqual_identifier);
25 return type_qualifier;
28create_type_qualifiers(
const char* tqual)
31 return type_qualifiers;
34create_tspec(
const char* tspec_str)
37 astnode_set_buffer(tspec_str,tspec_identifier);
42create_type_declaration_with_qualifiers(
const ASTNode* qualifiers,
const char* tspec)
45 if(qualifiers && tspec)
46 return astnode_create(
NODE_UNKNOWN,astnode_dup(qualifiers,NULL),create_tspec(tspec));
48 return astnode_create(
NODE_UNKNOWN,create_tspec(tspec),NULL);
49 return astnode_create(
NODE_UNKNOWN,astnode_dup(qualifiers,NULL),NULL);
53create_type_declaration(
const char* tqual,
const char* tspec)
57 return astnode_create(
NODE_UNKNOWN,create_type_qualifiers(tqual),create_tspec(tspec));
59 return astnode_create(
NODE_UNKNOWN,create_tspec(tspec),NULL);
60 return astnode_create(
NODE_UNKNOWN,create_type_qualifiers(tqual),NULL);
64create_declaration(
const char* identifier,
const char* type,
const char* tqual)
66 ASTNode* type_decl = (type == NULL && tqual == NULL) ? NULL : create_type_declaration(tqual, type);
72create_binary_op_expr(
const char* op)
75 res->
token = BINARY_OP;
76 astnode_set_buffer(op,res);
83 astnode_set_prefix(
"?", res);
84 astnode_set_prefix(
": ",res->
rhs);
92 astnode_dup(conditional,NULL),
93 create_choose_node(astnode_dup(lhs_value,NULL),astnode_dup(rhs_value,NULL))
97create_binary_expression(
ASTNode* expression ,
ASTNode* unary_expression,
const char* op)
101 create_binary_op_expr(op),
109create_assign_op(
const char* op)
112 astnode_set_buffer(op,res);
113 res->
token = ASSIGNOP;
118create_assignment_body(
const ASTNode* assign_expr,
const char* op)
120 ASTNode* expression_list = astnode_create(
NODE_UNKNOWN,astnode_dup(assign_expr,NULL),NULL);
122 astnode_dup(create_assign_op(op),NULL),
123 astnode_dup(expression_list,NULL)
128create_basic_statement(
const ASTNode* statement)
131 basic_statement ->
token = BASIC_STATEMENT;
133 res->
token = STATEMENT;
137create_variable_definition(
const ASTNode* lhs)
140 astnode_set_postfix(
";",res);
144create_assignment(
const ASTNode* lhs,
const ASTNode* assign_expr,
const char* op)
147 return create_basic_statement(create_variable_definition
150 astnode_dup(lhs,NULL),
151 create_assignment_body(assign_expr,op)
155static inline ASTNode* create_arr_initializer(
const ASTNode* elems)
158 astnode_set_prefix(
"{",arr_initializer);
159 astnode_set_postfix(
"}",arr_initializer);
160 return arr_initializer;
162static inline ASTNode* create_struct_initializer(
const ASTNode* elems)
165 astnode_set_prefix(
"{",arr_initializer);
166 astnode_set_postfix(
"}",arr_initializer);
167 return arr_initializer;
169static inline ASTNode* create_const_declaration(
const ASTNode* rhs,
const char* name,
const ASTNode* type_declaration)
174 astnode_sprintf(var_identifier,
"%s",name);
175 var_identifier->
token = IDENTIFIER;
178 ASTNode* var_definitions = astnode_create(
NODE_ASSIGN_LIST,astnode_dup(type_declaration,NULL),assignment_list);
181 astnode_set_postfix(
";",var_definitions);
182 return var_definitions;
@ NODE_ASSIGNMENT
Definition ast.h:84
@ NODE_TSPEC
Definition ast.h:73
@ NODE_ASSIGN_LIST
Definition ast.h:94
@ NODE_ARRAY_INITIALIZER
Definition ast.h:79
@ NODE_TERNARY_EXPRESSION
Definition ast.h:104
@ NODE_DECLARATION
Definition ast.h:72
@ NODE_BINARY_EXPRESSION
Definition ast.h:103
@ NODE_VARIABLE_ID
Definition ast.h:78
@ NODE_NO_OUT
Definition ast.h:96
@ NODE_TQUAL
Definition ast.h:74
@ NODE_UNKNOWN
Definition ast.h:64
@ NODE_STRUCT_INITIALIZER
Definition ast.h:88
struct astnode_s * rhs
Definition ast.h:149
int token
Definition ast.h:156