fix:
authoryu.dongliang <18588496441@163.com>
Sat, 10 Jun 2023 08:53:56 +0000 (16:53 +0800)
committeryu.dongliang <18588496441@163.com>
Sat, 10 Jun 2023 08:53:59 +0000 (16:53 +0800)
1, const local var print error,
2, break / continue in do while.

core/scf_operator_handler_3ac.c
examples/const_local.c [new file with mode: 0644]
parse/scf_dfa_util.h
parse/scf_dfa_var.c
parse/scf_operator_handler_semantic.c

index e102e6d4f6ce8de5fecbc0124c5172f7f7cada07..034b10540e34b8c609add3d2b12afb7c31ae19b7 100644 (file)
@@ -591,15 +591,17 @@ static int _scf_op_break(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, void*
 
        scf_node_t* n = (scf_node_t*)ast->current_block;
 
-       while (n && (SCF_OP_WHILE != n->type && SCF_OP_FOR != n->type)) {
+       while (n
+                       && SCF_OP_WHILE  != n->type
+                       && SCF_OP_REPEAT != n->type
+                       && SCF_OP_FOR    != n->type)
                n = n->parent;
-       }
 
        if (!n) {
                scf_loge("\n");
                return -1;
        }
-       assert(SCF_OP_WHILE == n->type || SCF_OP_FOR == n->type);
+       assert(SCF_OP_WHILE == n->type || SCF_OP_FOR == n->type || SCF_OP_REPEAT == n->type);
 
        scf_node_t* parent = n->parent;
        assert(parent);
@@ -618,15 +620,17 @@ static int _scf_op_continue(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, vo
 
        scf_node_t* n = (scf_node_t*)ast->current_block;
 
-       while (n && (SCF_OP_WHILE != n->type && SCF_OP_FOR != n->type)) {
+       while (n
+                       && SCF_OP_WHILE  != n->type
+                       && SCF_OP_REPEAT != n->type
+                       && SCF_OP_FOR    != n->type)
                n = n->parent;
-       }
 
        if (!n) {
                scf_loge("\n");
                return -1;
        }
-       assert(SCF_OP_WHILE == n->type || SCF_OP_FOR == n->type);
+       assert(SCF_OP_WHILE == n->type || SCF_OP_FOR == n->type || SCF_OP_REPEAT == n->type);
 
        scf_3ac_code_t* branch = scf_branch_ops_code(SCF_OP_GOTO, NULL, NULL);
 
diff --git a/examples/const_local.c b/examples/const_local.c
new file mode 100644 (file)
index 0000000..6ddf9e4
--- /dev/null
@@ -0,0 +1,10 @@
+int printf(const char* fmt, ...);
+
+int main()
+{
+       const int i = 123;
+
+       printf("%d\n", i);
+
+       return 0;
+}
index 9149960b7f789583c9eb490be610cc7cf30dc725..b4868a6fb802df4730acd0f91424f6209067cdf5 100644 (file)
@@ -235,6 +235,34 @@ static inline int scf_dfa_is_end_if(scf_dfa_t* dfa, void* word)
        return SCF_LEX_WORD_KEY_END_IF == w->type;
 }
 
+static inline int scf_dfa_is_continue(scf_dfa_t* dfa, void* word)
+{
+       scf_lex_word_t* w = word;
+
+       return SCF_LEX_WORD_KEY_CONTINUE == w->type;
+}
+
+static inline int scf_dfa_is_break(scf_dfa_t* dfa, void* word)
+{
+       scf_lex_word_t* w = word;
+
+       return SCF_LEX_WORD_KEY_BREAK == w->type;
+}
+
+static inline int scf_dfa_is_return(scf_dfa_t* dfa, void* word)
+{
+       scf_lex_word_t* w = word;
+
+       return SCF_LEX_WORD_KEY_RETURN == w->type;
+}
+
+static inline int scf_dfa_is_exit(scf_dfa_t* dfa, void* word)
+{
+       scf_lex_word_t* w = word;
+
+       return SCF_LEX_WORD_KEY_EXIT == w->type;
+}
+
 static inline int scf_dfa_is_while(scf_dfa_t* dfa, void* word)
 {
        scf_lex_word_t* w = word;
index f979ed7cfa8de3c6d9950c104a0e19970d906eb6..c7d634cb89c767b84a22f6f3e07967b5d0c1a6b8 100644 (file)
@@ -178,7 +178,8 @@ static int _var_init_expr(scf_dfa_t* dfa, dfa_parse_data_t* d, int semi_flag)
 
        d->expr_local_flag--;
 
-       if (d->current_var->global_flag) {
+       if (d->current_var->global_flag
+                       || (d->current_var->const_flag && 0 == d->current_var->nb_pointers + d->current_var->nb_dimentions)) {
 
                scf_logw("d->expr: %p, d->current_var: %p, global_flag: %d\n",
                                d->expr, d->current_var, d->current_var->global_flag);
index d39748c6eabac74e6414080ad43085e105f26095..96351776d724948d6a48c9db2e429fb54921cb99 100644 (file)
@@ -1169,15 +1169,18 @@ static int _scf_op_semantic_break(scf_ast_t* ast, scf_node_t** nodes, int nb_nod
 
        scf_node_t* n = (scf_node_t*)ast->current_block;
 
-       while (n && (SCF_OP_WHILE != n->type && SCF_OP_FOR != n->type)) {
+       while (n
+                       && SCF_OP_WHILE  != n->type
+                       && SCF_OP_REPEAT != n->type
+                       && SCF_OP_FOR    != n->type)
                n = n->parent;
-       }
 
        if (!n) {
                scf_loge("\n");
                return -1;
        }
-       assert(SCF_OP_WHILE == n->type || SCF_OP_FOR == n->type);
+
+       assert(SCF_OP_WHILE == n->type || SCF_OP_FOR == n->type || SCF_OP_REPEAT == n->type);
 
        if (!n->parent) {
                scf_loge("\n");