SCF_OP_DEREFERENCE, // * pointer dereference
SCF_OP_ARRAY_INDEX, // [] array index
+ SCF_OP_Q_MASK, // ?
+ SCF_OP_COLON, // :
+
SCF_OP_POINTER, // -> struct member
SCF_OP_DOT, // . dot
dn->node = (scf_node_t*)node;
#if 0
- if (SCF_OP_CALL == type) {
+ if (SCF_OP_Q_MASK == type) {
scf_logw("dn: %#lx, dn->type: %d", 0xffff & (uintptr_t)dn, dn->type);
if (var) {
printf(", var: %#lx, var->type: %d", 0xffff & (uintptr_t)var, var->type);
if (SCF_OP_LOGIC_AND == node->type
|| SCF_OP_LOGIC_OR == node->type
+ || SCF_OP_Q_MASK == node->type
|| SCF_OP_INC == node->type
|| SCF_OP_DEC == node->type
|| SCF_OP_INC_POST == node->type
|| SCF_OP_DEC_POST == node->type
|| SCF_OP_ADDRESS_OF == node->type) {
+
if (dn->var == _scf_operand_get(node))
return 1;
-
return 0;
}
return scf_node_add_child(parent, child);
assert(parent->nb_nodes >= 1);
+
+ if (SCF_OP_COLON == child->type && parent->nb_nodes > 1) {
+ if (SCF_OP_Q_MASK != parent->type)
+ return -EINVAL;
+
+ scf_node_t* right = parent->nodes[1];
+
+ if (SCF_OP_Q_MASK == right->type
+ && right->nb_nodes > 1
+ && SCF_OP_COLON == right->nodes[1]->type) {
+
+ parent->nodes[1] = child;
+ child->parent = parent;
+
+ return scf_node_add_child(child, right);
+ }
+ }
+
return __expr_node_add_node(&(parent->nodes[parent->nb_nodes - 1]), child);
}
{"&&", NULL, SCF_OP_LOGIC_AND, 9, 2, SCF_OP_ASSOCIATIVITY_LEFT},
{"||", NULL, SCF_OP_LOGIC_OR, 9, 2, SCF_OP_ASSOCIATIVITY_LEFT},
- {"=", "a", SCF_OP_ASSIGN, 10, 2, SCF_OP_ASSOCIATIVITY_RIGHT},
- {"+=", "add_", SCF_OP_ADD_ASSIGN, 10, 2, SCF_OP_ASSOCIATIVITY_RIGHT},
- {"-=", "sub_", SCF_OP_SUB_ASSIGN, 10, 2, SCF_OP_ASSOCIATIVITY_RIGHT},
- {"*=", "mul_", SCF_OP_MUL_ASSIGN, 10, 2, SCF_OP_ASSOCIATIVITY_RIGHT},
- {"/=", "div_", SCF_OP_DIV_ASSIGN, 10, 2, SCF_OP_ASSOCIATIVITY_RIGHT},
- {"%=", "mod_", SCF_OP_MOD_ASSIGN, 10, 2, SCF_OP_ASSOCIATIVITY_RIGHT},
- {"<<=", NULL, SCF_OP_SHL_ASSIGN, 10, 2, SCF_OP_ASSOCIATIVITY_RIGHT},
+ {"?", NULL, SCF_OP_Q_MASK, 10, 2, SCF_OP_ASSOCIATIVITY_RIGHT},
+ {":", NULL, SCF_OP_COLON, 10, 2, SCF_OP_ASSOCIATIVITY_RIGHT},
+
+ {"=", "a", SCF_OP_ASSIGN, 11, 2, SCF_OP_ASSOCIATIVITY_RIGHT},
+ {"+=", "add_", SCF_OP_ADD_ASSIGN, 11, 2, SCF_OP_ASSOCIATIVITY_RIGHT},
+ {"-=", "sub_", SCF_OP_SUB_ASSIGN, 11, 2, SCF_OP_ASSOCIATIVITY_RIGHT},
+ {"*=", "mul_", SCF_OP_MUL_ASSIGN, 11, 2, SCF_OP_ASSOCIATIVITY_RIGHT},
+ {"/=", "div_", SCF_OP_DIV_ASSIGN, 11, 2, SCF_OP_ASSOCIATIVITY_RIGHT},
+ {"%=", "mod_", SCF_OP_MOD_ASSIGN, 11, 2, SCF_OP_ASSOCIATIVITY_RIGHT},
+ {"<<=", NULL, SCF_OP_SHL_ASSIGN, 11, 2, SCF_OP_ASSOCIATIVITY_RIGHT},
{">>=", NULL, SCF_OP_SHR_ASSIGN, 10, 2, SCF_OP_ASSOCIATIVITY_RIGHT},
- {"&=", "and_", SCF_OP_AND_ASSIGN, 10, 2, SCF_OP_ASSOCIATIVITY_RIGHT},
- {"|=", "or_", SCF_OP_OR_ASSIGN, 10, 2, SCF_OP_ASSOCIATIVITY_RIGHT},
+ {"&=", "and_", SCF_OP_AND_ASSIGN, 11, 2, SCF_OP_ASSOCIATIVITY_RIGHT},
+ {"|=", "or_", SCF_OP_OR_ASSIGN, 11, 2, SCF_OP_ASSOCIATIVITY_RIGHT},
{"{}", NULL, SCF_OP_BLOCK, 15, -1, SCF_OP_ASSOCIATIVITY_LEFT},
{"return", NULL, SCF_OP_RETURN, 15, -1, SCF_OP_ASSOCIATIVITY_LEFT},
static int _scf_op_node(scf_ast_t* ast, scf_node_t* node, scf_handler_data_t* d)
{
+ if (0 == node->nb_nodes) {
+ if (scf_type_is_var(node->type) || node->split_flag)
+ return 0;
+ }
+
scf_operator_t* op = node->op;
if (!op) {
op = scf_find_base_operator_by_type(node->type);
if (!op) {
- scf_loge("\n");
+ scf_loge("node->type: %d\n", node->type);
return -1;
}
}
return 0;
}
+static int _scf_op_colon(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, void* data)
+{
+ return 0;
+}
+
+static int _scf_op_q_mask(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, void* data)
+{
+ assert(2 == nb_nodes);
+
+ scf_handler_data_t* d = data;
+
+ scf_variable_t* v0 = _scf_operand_get(nodes[0]);
+ scf_expr_t* e = nodes[0];
+ scf_node_t* colon = nodes[1];
+ scf_node_t* parent = e->parent;
+
+ int ret = scf_node_add_child(parent, colon->nodes[1]);
+ if (ret < 0)
+ return ret;
+
+ parent->nodes[1] = colon->nodes[0];
+ colon->nodes[0]->parent = parent;
+ colon->nodes[0] = NULL;
+ colon->nodes[1] = NULL;
+
+ scf_node_free(colon);
+ colon = NULL;
+
+ _scf_operand_get(parent)->tmp_flag = 1;
+
+ int jmp_op = _scf_op_cond(ast, e, d);
+ if (jmp_op < 0) {
+ scf_loge("\n");
+ return -1;
+ }
+
+ scf_3ac_operand_t* dst;
+ scf_3ac_code_t* jmp_else = scf_3ac_jmp_code(jmp_op, NULL);
+ scf_3ac_code_t* jmp_endif = NULL;
+ scf_list_t* l;
+
+ scf_list_add_tail(d->_3ac_list_head, &jmp_else->list);
+
+ int i;
+ for (i = 1; i < 3; i++) {
+ scf_node_t* node = nodes[i];
+
+ if (_scf_op_node(ast, node, d) < 0) {
+ scf_loge("\n");
+ return -1;
+ }
+
+ ret = _scf_3ac_code_2(d->_3ac_list_head, SCF_OP_ASSIGN, parent, node);
+ if (ret < 0)
+ return ret;
+
+ if (1 == i) {
+ jmp_endif = scf_3ac_jmp_code(SCF_OP_GOTO, NULL);
+ scf_list_add_tail(d->_3ac_list_head, &jmp_endif->list);
+
+ l = scf_list_tail(d->_3ac_list_head);
+ dst = jmp_else->dsts->data[0];
+ dst->code = scf_list_data(l, scf_3ac_code_t, list);
+ }
+ }
+
+ ret = scf_vector_add(d->branch_ops->_breaks, jmp_else);
+ if (ret < 0)
+ return ret;
+
+ if (jmp_endif) {
+ l = scf_list_tail(d->_3ac_list_head);
+ dst = jmp_endif->dsts->data[0];
+ dst->code = scf_list_data(l, scf_3ac_code_t, list);
+
+ ret = scf_vector_add(d->branch_ops->_breaks, jmp_endif);
+ if (ret < 0)
+ return ret;
+ }
+
+ return 0;
+}
+
static int _scf_op_if(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, void* data)
{
if (2 != nb_nodes && 3 != nb_nodes) {
[SCF_OP_LOGIC_AND] = _scf_op_logic_and,
[SCF_OP_LOGIC_OR ] = _scf_op_logic_or,
+ [SCF_OP_Q_MASK ] = _scf_op_q_mask,
+ [SCF_OP_COLON ] = _scf_op_colon,
+
[SCF_OP_ASSIGN ] = _scf_op_assign,
[SCF_OP_ADD_ASSIGN] = _scf_op_add_assign,
[SCF_OP_SUB_ASSIGN] = _scf_op_sub_assign,
--- /dev/null
+int printf(const char* fmt, ...);
+
+int main(int argc, char* argv[])
+{
+ int i = argc > 1 ? 1 : 0;
+
+ printf("argv[%d]: %s\n", i, argv[i]);
+ return 0;
+}
switch (w1->type) {
case SCF_LEX_WORD_KEY_INCLUDE:
- case SCF_LEX_WORD_KEY_IF:
- case SCF_LEX_WORD_KEY_ELIF:
- case SCF_LEX_WORD_KEY_ELSE:
case SCF_LEX_WORD_KEY_ENDIF:
-
scf_lex_push_word(lex, w1);
*pword = w;
return 0;
break;
+ case SCF_LEX_WORD_KEY_IF:
+ case SCF_LEX_WORD_KEY_ELIF:
+ ret = __parse_macro_if(lex);
+ break;
+
+ case SCF_LEX_WORD_KEY_ELSE:
+ ret = __parse_macro_else(lex);
+ break;
+
case SCF_LEX_WORD_KEY_IFNDEF:
ret = __parse_macro_ifdef(lex, 0);
break;
int __parse_macro_define(scf_lex_t* lex, int def_flag);
int __parse_macro_ifdef (scf_lex_t* lex, int def_flag);
+int __parse_macro_if (scf_lex_t* lex);
+int __parse_macro_else (scf_lex_t* lex);
int _lex_number_base_16(scf_lex_t* lex, scf_lex_word_t** pword, scf_string_t* s);
int _lex_number_base_10(scf_lex_t* lex, scf_lex_word_t** pword, scf_string_t* s);
return 0;
}
-int __parse_macro_ifdef(scf_lex_t* lex, int def_flag)
+static int __do_macro_if(scf_lex_t* lex, int flag)
{
- scf_lex_word_t** pp;
- scf_lex_word_t* w = NULL;
- scf_macro_t* m;
-
- int ret = __lex_pop_word(lex, &w);
- if (ret < 0)
- return ret;
-
- if (!scf_lex_is_identity(w)) {
- scf_loge("macro '%s' should be an identity, file: %s, line: %d\n", w->text->data, w->file->data, w->line);
- scf_lex_word_free(w);
- return -EINVAL;
- }
-
- ret = __macro_drop_to_LF(lex);
- if (ret < 0)
- return ret;
-
- int found = 0;
- if (lex->macros && __find_macro(lex, w))
- found = 1;
-
- scf_logw("macro '%s', found: %d, def_flag: %d, file: %s, line: %d\n",
- w->text->data, found, def_flag, w->file->data, w->line);
-
scf_lex_word_t* h = NULL;
scf_lex_word_t* w1 = NULL;
scf_lex_word_t* w2 = NULL;
+ int ret;
- if (found != def_flag) {
+ if (!flag) {
ret = __macro_drop_to(lex, &w1, &w2);
if (ret < 0)
return ret;
return 0;
}
+int __parse_macro_if(scf_lex_t* lex)
+{
+ int ret = __macro_if_expr(lex);
+ if (ret < 0)
+ return ret;
+
+ return __do_macro_if(lex, ret);
+}
+
+int __parse_macro_else(scf_lex_t* lex)
+{
+ int ret = __macro_drop_to_LF(lex);
+ if (ret < 0)
+ return ret;
+
+ return __do_macro_if(lex, 1);
+}
+
+int __parse_macro_ifdef(scf_lex_t* lex, int def_flag)
+{
+ scf_lex_word_t* w = NULL;
+ scf_macro_t* m;
+
+ int ret = __lex_pop_word(lex, &w);
+ if (ret < 0)
+ return ret;
+
+ if (!scf_lex_is_identity(w)) {
+ scf_loge("macro '%s' should be an identity, file: %s, line: %d\n", w->text->data, w->file->data, w->line);
+ scf_lex_word_free(w);
+ return -EINVAL;
+ }
+
+ ret = __macro_drop_to_LF(lex);
+ if (ret < 0)
+ return ret;
+
+ int found = 0;
+ if (lex->macros && __find_macro(lex, w))
+ found = 1;
+
+ scf_logw("macro '%s', found: %d, def_flag: %d, file: %s, line: %d\n",
+ w->text->data, found, def_flag, w->file->data, w->line);
+
+ return __do_macro_if(lex, found == def_flag);
+}
+
static int __fill_macro_argv(scf_lex_t* lex, scf_macro_t* m, scf_lex_word_t* use, scf_vector_t* argv)
{
scf_lex_word_t** pp;
goto error;
if (SCF_LEX_WORD_LF == w->type) {
- scf_lex_push_word(lex, w);
+ scf_lex_word_free(w);
w = NULL;
break;
}
CFILES += scf_dfa.c
CFILES += scf_dfa_parse.c
-CFILES += scf_dfa_macro.c
CFILES += scf_dfa_include.c
CFILES += scf_dfa_call.c
SCF_DFA_GET_MODULE_NODE(dfa, expr, entry, expr);
SCF_DFA_GET_MODULE_NODE(dfa, type, entry, type);
- SCF_DFA_GET_MODULE_NODE(dfa, macro, hash, macro);
-
SCF_DFA_GET_MODULE_NODE(dfa, if, _if, _if);
SCF_DFA_GET_MODULE_NODE(dfa, while, _while, _while);
SCF_DFA_GET_MODULE_NODE(dfa, do, _do, _do);
scf_dfa_node_add_child(entry, expr);
scf_dfa_node_add_child(entry, type);
- scf_dfa_node_add_child(entry, macro);
-
scf_dfa_node_add_child(entry, _if);
scf_dfa_node_add_child(entry, _while);
scf_dfa_node_add_child(entry, _do);
static int _dfa_init_syntax_block(scf_dfa_t* dfa)
{
- SCF_DFA_GET_MODULE_NODE(dfa, block, entry, entry);
- SCF_DFA_GET_MODULE_NODE(dfa, block, end, end);
+ SCF_DFA_GET_MODULE_NODE(dfa, block, entry, entry);
+ SCF_DFA_GET_MODULE_NODE(dfa, block, end, end);
+ SCF_DFA_GET_MODULE_NODE(dfa, expr, number, number);
scf_dfa_node_add_child(entry, end);
scf_dfa_node_add_child(end, entry);
int i;
- for (i = 0; i < entry->childs->size; i++) {
- scf_dfa_node_t* n = entry->childs->data[i];
+ for (i = 0; i < number->childs->size; i++) {
+ scf_dfa_node_t* n = number->childs->data[i];
scf_logd("n->name: %s\n", n->name);
}
dfa_identity_t* id = scf_stack_top(d->current_identities);
scf_variable_t* v;
- if (SCF_LEX_WORD_STAR == w->type) {
+ if (id && id->identity) {
+
+ switch (w->type) {
+ case SCF_LEX_WORD_STAR:
+ case SCF_LEX_WORD_COLON:
- if (id && id->identity) {
+ v = scf_block_find_variable(parse->ast->current_block, id->identity->text->data);
+ if (!v) {
+ scf_logw("'%s' not var\n", id->identity->text->data);
- v = scf_block_find_variable(parse->ast->current_block, id->identity->text->data);
- if (!v) {
- scf_logw("'%s' not var\n", id->identity->text->data);
+ if (d->expr) {
+ scf_expr_free(d->expr);
+ d->expr = NULL;
+ }
- if (d->expr) {
- scf_expr_free(d->expr);
- d->expr = NULL;
+ return SCF_DFA_NEXT_SYNTAX;
}
- return SCF_DFA_NEXT_SYNTAX;
- }
- }
- }
+ break;
+ };
- if (id && id->identity) {
if (_expr_add_var(parse, d) < 0)
return SCF_DFA_ERROR;
}
static int _dfa_init_module_include(scf_dfa_t* dfa)
{
+ SCF_DFA_MODULE_NODE(dfa, include, hash, scf_dfa_is_hash, scf_dfa_action_next);
SCF_DFA_MODULE_NODE(dfa, include, include, scf_dfa_is_include, _include_action_include);
SCF_DFA_MODULE_NODE(dfa, include, path, scf_dfa_is_const_string, _include_action_path);
SCF_DFA_MODULE_NODE(dfa, include, LF, scf_dfa_is_LF, _include_action_LF);
static int _dfa_init_syntax_include(scf_dfa_t* dfa)
{
+ SCF_DFA_GET_MODULE_NODE(dfa, include, hash, hash);
SCF_DFA_GET_MODULE_NODE(dfa, include, include, include);
SCF_DFA_GET_MODULE_NODE(dfa, include, path, path);
SCF_DFA_GET_MODULE_NODE(dfa, include, LF, LF);
- SCF_DFA_GET_MODULE_NODE(dfa, macro, hash, hash);
+ scf_vector_add(dfa->syntaxes, hash);
scf_dfa_node_add_child(hash, include);
scf_dfa_node_add_child(include, path);
+++ /dev/null
-#include"scf_dfa.h"
-#include"scf_dfa_util.h"
-#include"scf_parse.h"
-
-extern scf_dfa_module_t dfa_module_macro;
-
-
-static int __macro_do_if_else(scf_lex_t* lex, scf_lex_word_t* w, int flag)
-{
- scf_lex_word_t* h = NULL;
- scf_lex_word_t* w1 = NULL;
- scf_lex_word_t* w2 = NULL;
-
- int ret = __macro_drop_to_LF(lex);
- if (ret < 0) {
- scf_loge("'#endif' NOT found for '#%s' in file: %s, line: %d\n", w->text->data, w->file->data, w->line);
- return ret;
- }
-
- if (!flag) {
- ret = __macro_drop_to(lex, &w1, &w2);
- if (ret < 0)
- return ret;
-
- if (SCF_LEX_WORD_KEY_ENDIF == w2->type) {
- scf_lex_word_free(w2);
- scf_lex_word_free(w1);
-
- return __macro_drop_to_LF(lex);
- }
-
- scf_lex_push_word(lex, w2);
- scf_lex_push_word(lex, w1);
- return SCF_DFA_OK;
- }
-
- ret = __macro_pop_to(lex, &h, &w1, &w2);
- if (ret < 0) {
- scf_slist_clear(h, scf_lex_word_t, next, scf_lex_word_free);
- return ret;
- }
-
- int type = w2->type;
-
- scf_lex_word_free(w2);
- scf_lex_word_free(w1);
- w1 = NULL;
- w2 = NULL;
-
- while (SCF_LEX_WORD_KEY_ENDIF != type) {
-
- ret = __macro_drop_to(lex, &w1, &w2);
- if (ret < 0) {
- scf_slist_clear(h, scf_lex_word_t, next, scf_lex_word_free);
- return ret;
- }
-
- type = w2->type;
-
- scf_lex_word_free(w2);
- scf_lex_word_free(w1);
- w1 = NULL;
- w2 = NULL;
- }
-
- ret = __macro_drop_to_LF(lex);
- if (ret < 0) {
- scf_slist_clear(h, scf_lex_word_t, next, scf_lex_word_free);
- return ret;
- }
-
- while (h) {
- w1 = h;
- h = h->next;
-
- scf_lex_push_word(lex, w1);
- }
-
- return SCF_DFA_OK;
-}
-
-static int _macro_action_if(scf_dfa_t* dfa, scf_vector_t* words, void* data)
-{
- scf_parse_t* parse = dfa->priv;
- dfa_data_t* d = data;
- scf_lex_word_t* w = words->data[words->size - 1];
-
- int flag = __macro_if_expr(parse->lex);
- if (flag < 0)
- return flag;
-
- return __macro_do_if_else(parse->lex, w, flag);
-}
-
-static int _macro_action_else(scf_dfa_t* dfa, scf_vector_t* words, void* data)
-{
- scf_parse_t* parse = dfa->priv;
- scf_lex_word_t* w = words->data[words->size - 1];
-
- return __macro_do_if_else(parse->lex, w, 1);
-}
-
-static int _dfa_init_module_macro(scf_dfa_t* dfa)
-{
- SCF_DFA_MODULE_NODE(dfa, macro, hash, scf_dfa_is_hash, scf_dfa_action_next);
- SCF_DFA_MODULE_NODE(dfa, macro, _if, scf_dfa_is_if, _macro_action_if);
- SCF_DFA_MODULE_NODE(dfa, macro, _elif, scf_dfa_is_elif, _macro_action_if);
- SCF_DFA_MODULE_NODE(dfa, macro, _else, scf_dfa_is_else, _macro_action_else);
-
- return SCF_DFA_OK;
-}
-
-static int _dfa_init_syntax_macro(scf_dfa_t* dfa)
-{
- SCF_DFA_GET_MODULE_NODE(dfa, macro, hash, hash);
- SCF_DFA_GET_MODULE_NODE(dfa, macro, _if, _if);
- SCF_DFA_GET_MODULE_NODE(dfa, macro, _elif, _elif);
- SCF_DFA_GET_MODULE_NODE(dfa, macro, _else, _else);
-
- scf_vector_add(dfa->syntaxes, hash);
-
- scf_dfa_node_add_child(hash, _if);
- scf_dfa_node_add_child(hash, _elif);
- scf_dfa_node_add_child(hash, _else);
- return 0;
-}
-
-scf_dfa_module_t dfa_module_macro =
-{
- .name = "macro",
- .init_module = _dfa_init_module_macro,
- .init_syntax = _dfa_init_syntax_macro,
-};
#include"scf_dfa.h"
#include"scf_parse.h"
-extern scf_dfa_module_t dfa_module_macro;
extern scf_dfa_module_t dfa_module_include;
extern scf_dfa_module_t dfa_module_identity;
scf_dfa_module_t* dfa_modules[] =
{
- &dfa_module_macro,
&dfa_module_include,
&dfa_module_identity,
return _scf_op_const_binary(ast, nodes, nb_nodes, data);
}
+static int _scf_op_const_q_mask(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, void* data)
+{
+ assert(2 == nb_nodes);
+
+ scf_variable_t* v0 = _scf_operand_get(nodes[0]);
+ scf_node_t* colon = nodes[1];
+ scf_node_t* q_mask = colon ->parent;
+ scf_node_t* parent = q_mask->parent;
+
+ assert(v0);
+
+ if (scf_variable_const_integer(v0)) {
+ int i;
+ int j;
+
+ for (i = 0; i < parent->nb_nodes; i++) {
+ if (q_mask == parent->nodes[i])
+ break;
+ }
+ assert(i < parent->nb_nodes);
+
+ j = !!scf_zero_extend(v0->data.u64, v0->size);
+
+ colon ->nodes[j]->parent = parent;
+ parent->nodes[i] = colon->nodes[j];
+ colon ->nodes[j] = NULL;
+
+ scf_node_free(q_mask);
+ q_mask = NULL;
+ }
+
+ return 0;
+}
+
+static int _scf_op_const_colon(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, void* data)
+{
+ return 0;
+}
+
static int _scf_op_const_va_start(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, void* data)
{
return 0;
[SCF_OP_LOGIC_AND ] = _scf_op_const_logic_and,
[SCF_OP_LOGIC_OR ] = _scf_op_const_logic_or,
+ [SCF_OP_Q_MASK ] = _scf_op_const_q_mask,
+ [SCF_OP_COLON ] = _scf_op_const_colon,
+
[SCF_OP_ASSIGN ] = _scf_op_const_assign,
[SCF_OP_ADD_ASSIGN ] = _scf_op_const_add_assign,
[SCF_OP_SUB_ASSIGN ] = _scf_op_const_sub_assign,
{
scf_handler_data_t* d = data;
- scf_variable_t* v0 = _scf_operand_get(nodes[0]);
- scf_variable_t* v1 = _scf_operand_get(nodes[1]);
- scf_node_t* parent = nodes[0]->parent;
- scf_lex_word_t* w = parent->w;
-
- scf_type_t* t;
- scf_variable_t* r;
+ scf_node_t* parent = nodes[0]->parent;
+ scf_variable_t* v0 = _scf_operand_get(nodes[0]);
+ scf_variable_t* v1 = _scf_operand_get(nodes[1]);
+ scf_lex_word_t* w = parent->w;
+ scf_variable_t* r;
+ scf_type_t* t;
assert(v0);
assert(v1);
return _scf_op_semantic_binary_interger(ast, nodes, nb_nodes, data);
}
+static int _scf_op_semantic_q_mask(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, void* data)
+{
+ assert(2 == nb_nodes);
+
+ scf_handler_data_t* d = data;
+
+ scf_type_t* t = NULL;
+ scf_variable_t* v0 = _scf_operand_get(nodes[0]);
+ scf_variable_t* v1 = _scf_operand_get(nodes[1]);
+
+ if (!scf_variable_integer(v0)) {
+ scf_loge("\n");
+ return -EINVAL;
+ }
+
+ int ret = scf_ast_find_type_type(&t, ast, v1->type);
+ if (ret < 0)
+ return ret;
+
+ scf_variable_t* r = SCF_VAR_ALLOC_BY_TYPE(nodes[0]->parent->w, t, v1->const_flag, v1->nb_pointers, v1->func_ptr);
+ if (!r)
+ return -ENOMEM;
+
+ *d->pret = r;
+ return 0;
+}
+
+static int _scf_op_semantic_colon(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, void* data)
+{
+ assert(2 == nb_nodes);
+
+ scf_handler_data_t* d = data;
+
+ scf_node_t* parent = nodes[0]->parent;
+ scf_variable_t* v0 = _scf_operand_get(nodes[0]);
+ scf_variable_t* v1 = _scf_operand_get(nodes[1]);
+ scf_lex_word_t* w = parent->w;
+ scf_type_t* t = NULL;
+
+ if (!scf_variable_same_type(v0, v1)) {
+
+ int ret = _semantic_do_type_cast(ast, nodes, nb_nodes, data);
+ if (ret < 0) {
+ scf_loge("semantic do type cast failed, line: %d\n", parent->w->line);
+ return ret;
+ }
+ }
+
+ v0 = _scf_operand_get(nodes[0]);
+
+ int ret = scf_ast_find_type_type(&t, ast, v0->type);
+ if (ret < 0)
+ return ret;
+
+ scf_variable_t* r = SCF_VAR_ALLOC_BY_TYPE(w, t, 0, v0->nb_pointers, v0->func_ptr);
+ if (!r)
+ return -ENOMEM;
+
+ *d->pret = r;
+ return 0;
+}
+
static int _scf_op_semantic_va_start(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, void* data)
{
if (2 != nb_nodes) {
scf_loge("\n");
return -1;
}
+
return 0;
}
[SCF_OP_LOGIC_AND ] = _scf_op_semantic_logic_and,
[SCF_OP_LOGIC_OR ] = _scf_op_semantic_logic_or,
+ [SCF_OP_Q_MASK ] = _scf_op_semantic_q_mask,
+ [SCF_OP_COLON ] = _scf_op_semantic_colon,
+
[SCF_OP_ASSIGN ] = _scf_op_semantic_assign,
[SCF_OP_ADD_ASSIGN ] = _scf_op_semantic_add_assign,
[SCF_OP_SUB_ASSIGN ] = _scf_op_semantic_sub_assign,