support simple macro define, rename some long struct name
authoryu.dongliang <18588496441@163.com>
Thu, 26 Sep 2024 07:07:21 +0000 (15:07 +0800)
committeryu.dongliang <18588496441@163.com>
Thu, 26 Sep 2024 07:07:21 +0000 (15:07 +0800)
61 files changed:
core/scf_core_types.h
core/scf_lex_word.c
core/scf_lex_word.h
elf/scf_dwarf.c
elf/scf_dwarf.h [new file with mode: 0644]
elf/scf_dwarf_abbrev.c
elf/scf_dwarf_info.c
elf/scf_dwarf_line.c
examples/auto_gc_0.c
examples/complex.c
examples/list_test.c
examples/macro.c [new file with mode: 0644]
examples/mat.c
examples/recursive_pointer.c
examples/ret2_err.c
examples/str.c
examples/string.c
lex/scf_lex.c
lex/scf_lex.h
lex/scf_lex_util.c
lib/scf_complex.c
parse/Makefile
parse/main.c
parse/scf_dfa.c
parse/scf_dfa_async.c
parse/scf_dfa_block.c
parse/scf_dfa_break.c
parse/scf_dfa_call.c
parse/scf_dfa_class.c
parse/scf_dfa_container.c
parse/scf_dfa_continue.c
parse/scf_dfa_create.c
parse/scf_dfa_do.c
parse/scf_dfa_enum.c
parse/scf_dfa_expr.c
parse/scf_dfa_for.c
parse/scf_dfa_function.c
parse/scf_dfa_goto.c
parse/scf_dfa_identity.c
parse/scf_dfa_if.c
parse/scf_dfa_include.c
parse/scf_dfa_init_data.c
parse/scf_dfa_label.c
parse/scf_dfa_macro.c [new file with mode: 0644]
parse/scf_dfa_operator.c
parse/scf_dfa_parse.c
parse/scf_dfa_return.c
parse/scf_dfa_sizeof.c
parse/scf_dfa_switch.c
parse/scf_dfa_type.c
parse/scf_dfa_union.c
parse/scf_dfa_util.h
parse/scf_dfa_va_arg.c
parse/scf_dfa_var.c
parse/scf_dfa_while.c
parse/scf_parse.c
parse/scf_parse.h
util/scf_list.h
util/scf_rbtree.h
util/scf_string.c
util/scf_vector.h

index ba80cbdea31db3dc059e2afa129ceebce0dfe869..f7429600e0c1f68692e8883f3c4bc3c631a98426 100644 (file)
@@ -322,4 +322,3 @@ static int scf_type_is_setcc(int type)
 }
 
 #endif
-
index 3802900fa0e8dba55a5c986827ea198c1a5c5a1a..e320aef4a2f131d53db3455f00bf7c15dafaf49b 100644 (file)
@@ -2,34 +2,48 @@
 
 scf_lex_word_t*        scf_lex_word_alloc(scf_string_t* file, int line, int pos, int type)
 {
-       assert(file);
+       if (!file)
+               return NULL;
 
        scf_lex_word_t* w = calloc(1, sizeof(scf_lex_word_t));
-       assert(w);
+       if (!w)
+               return NULL;
 
        w->file = scf_string_clone(file);
-       assert(w->file);
+       if (!w->file) {
+               free(w);
+               return NULL;
+       }
 
        w->type = type;
        w->line = line;
-       w->pos = pos;
+       w->pos  = pos;
        return w;
 }
 
 scf_lex_word_t*        scf_lex_word_clone(scf_lex_word_t* w)
 {
+       if (!w)
+               return NULL;
+
        scf_lex_word_t* w1 = calloc(1, sizeof(scf_lex_word_t));
-       assert(w1);
+       if (!w1)
+               return NULL;
 
-       scf_list_init(&w1->list);
        w1->type = w->type;
 
        switch (w->type) {
                case SCF_LEX_WORD_CONST_CHAR:
                        w1->data.u32 = w->data.u32;
                        break;
+
                case SCF_LEX_WORD_CONST_STRING:
+
                        w1->data.s = scf_string_clone(w->data.s);
+                       if (!w1->data.s) {
+                               free(w1);
+                               return NULL;
+                       }
                        break;
 
                case SCF_LEX_WORD_CONST_INT:
@@ -55,27 +69,76 @@ scf_lex_word_t*     scf_lex_word_clone(scf_lex_word_t* w)
                        break;
        };
 
-       w1->text = scf_string_clone(w->text);
-       w1->file = scf_string_clone(w->file);
-       w1->line = w->line;
-       w1->pos = w->pos;
+       if (w->text) {
+               w1->text = scf_string_clone(w->text);
+
+               if (!w1->text) {
+                       scf_lex_word_free(w1);
+                       return NULL;
+               }
+       }
 
+       if (w->file) {
+               w1->file = scf_string_clone(w->file);
+
+               if (!w1->file) {
+                       scf_lex_word_free(w1);
+                       return NULL;
+               }
+       }
+
+       w1->line = w->line;
+       w1->pos  = w->pos;
        return w1;
 }
 
 void scf_lex_word_free(scf_lex_word_t* w)
 {
-       assert(w);
+       if (w) {
+               if (SCF_LEX_WORD_CONST_STRING == w->type)
+                       scf_string_free(w->data.s);
+
+               if (w->text)
+                       scf_string_free(w->text);
+
+               if (w->file)
+                       scf_string_free(w->file);
 
-       if (SCF_LEX_WORD_CONST_STRING == w->type)
-               scf_string_free(w->data.s);
+               free(w);
+       }
+}
+
+scf_macro_t* scf_macro_alloc(scf_lex_word_t* w)
+{
+       if (!w)
+               return NULL;
 
-       if (w->text)
-               scf_string_free(w->text);
-       if (w->file)
-               scf_string_free(w->file);
+       scf_macro_t* m = calloc(1, sizeof(scf_macro_t));
+       if (!m)
+               return NULL;
 
-       free(w);
-       w = NULL;
+       m->w    = w;
+       m->refs = 1;
+       return m;
 }
 
+void scf_macro_free(scf_macro_t* m)
+{
+       if (m) {
+               if (--m->refs > 0)
+                       return;
+
+               assert(0 == m->refs);
+
+               scf_lex_word_free(m->w);
+
+               if (m->argv) {
+                       scf_vector_clear(m->argv, ( void (*)(void*) ) scf_lex_word_free);
+                       scf_vector_free (m->argv);
+               }
+
+               scf_slist_clear(m->text_list, scf_lex_word_t, next, scf_lex_word_free);
+
+               free(m);
+       }
+}
index 24a92ed261ef547da3d569c60e7d7ca000e8b61c..85ddb3ca193692f0f797d2f6465444673d72ed9b 100644 (file)
@@ -4,6 +4,10 @@
 #include"scf_string.h"
 #include"scf_list.h"
 
+typedef struct scf_lex_word_s   scf_lex_word_t;
+typedef struct scf_complex_s    scf_complex_t;
+typedef struct scf_macro_s      scf_macro_t;
+
 enum scf_lex_words
 {
        SCF_LEX_WORD_PLUS = 0,          // +
@@ -66,11 +70,15 @@ enum scf_lex_words
        SCF_LEX_WORD_RANGE,         // ..  range
        SCF_LEX_WORD_VAR_ARGS,      // ... variable args
 
-       SCF_LEX_WORD_LB,                        // { left brace
-       SCF_LEX_WORD_RB,                        // } right brace
+       SCF_LEX_WORD_LB,            // { left brace
+       SCF_LEX_WORD_RB,            // } right brace
+
+       SCF_LEX_WORD_LF,            // '\n', line feed, LF
+       SCF_LEX_WORD_HASH,          // #  hash
+       SCF_LEX_WORD_HASH2,         // ## hash2
 
-       SCF_LEX_WORD_COMMA,                     // , comma
-       SCF_LEX_WORD_SEMICOLON,         // ;
+       SCF_LEX_WORD_COMMA,         // , comma
+       SCF_LEX_WORD_SEMICOLON,     // ;
        SCF_LEX_WORD_COLON,                     // : colon
        SCF_LEX_WORD_SPACE,                     // ' ' space
 
@@ -160,19 +168,30 @@ enum scf_lex_words
        SCF_LEX_WORD_CONST_I64,
        SCF_LEX_WORD_CONST_U64,
 
-       // identity
        SCF_LEX_WORD_ID, // identity, start of _, a-z, A-Z, may include 0-9
 };
 
-typedef struct {
+struct scf_complex_s
+{
        float real;
        float imag;
-} scf_complex_t;
+};
 
-typedef struct {
-       scf_list_t              list;   // manage list, all words in this list, FIFO
+struct scf_macro_s
+{
+       int              refs;
+
+       scf_lex_word_t*  w;
+       scf_vector_t*    argv;
+
+       scf_lex_word_t*  text_list;
+};
+
+struct scf_lex_word_s
+{
+       scf_lex_word_t*  next;
+       int              type;
 
-       int                             type;
        union {
                int32_t         i;    // value for <= int32_t
                uint32_t        u32;  // value for <= uint32_t
@@ -189,8 +208,7 @@ typedef struct {
        scf_string_t*   file;   // original code file name
        int                             line;   // line in the code file above  
        int                             pos;    // position in the line above
-
-} scf_lex_word_t;
+};
 
 static inline int scf_lex_is_identity(scf_lex_word_t* w)
 {
@@ -212,7 +230,10 @@ static inline int scf_lex_is_base_type(scf_lex_word_t* w)
        return SCF_LEX_WORD_KEY_CHAR <= w->type && SCF_LEX_WORD_KEY_VOID >= w->type;
 }
 
-scf_lex_word_t*  scf_lex_word_alloc(scf_string_t* file, int line, int pos, int type);
+scf_macro_t*     scf_macro_alloc(scf_lex_word_t* w);
+void             scf_macro_free (scf_macro_t*    m);
+
+scf_lex_word_t*  scf_lex_word_alloc(scf_string_t*   file, int line, int pos, int type);
 scf_lex_word_t*  scf_lex_word_clone(scf_lex_word_t* w);
 void             scf_lex_word_free (scf_lex_word_t* w);
 
index de4179ed809db86716fbd82fe6a10c874afadb91..9768f612ef23624957fa6f77b2a7059c5b1fc71b 100644 (file)
@@ -1,4 +1,4 @@
-#include"scf_dwarf_def.h"
+#include"scf_dwarf.h"
 #include"scf_leb128.h"
 
 static scf_dwarf_abbrev_attribute_t abbrev_cu[] =
@@ -224,7 +224,7 @@ int scf_dwarf_abbrev_add_cu(scf_vector_t* abbrevs)
        return scf_dwarf_abbrev_add_subprogram(abbrevs);
 }
 
-int scf_dwarf_debug_encode(scf_dwarf_debug_t* debug)
+int scf_dwarf_debug_encode(scf_dwarf_t* debug)
 {
        if (0 == debug->infos->size)
                return 0;
@@ -335,9 +335,9 @@ int scf_dwarf_debug_encode(scf_dwarf_debug_t* debug)
        return 0;
 }
 
-scf_dwarf_debug_t* scf_dwarf_debug_alloc()
+scf_dwarf_t* scf_dwarf_debug_alloc()
 {
-       scf_dwarf_debug_t* debug = calloc(1, sizeof(scf_dwarf_debug_t));
+       scf_dwarf_t* debug = calloc(1, sizeof(scf_dwarf_t));
        if (!debug)
                return NULL;
 
@@ -423,7 +423,7 @@ scf_dwarf_debug_t* scf_dwarf_debug_alloc()
        return debug;
 }
 
-void scf_dwarf_debug_free (scf_dwarf_debug_t* debug)
+void scf_dwarf_debug_free (scf_dwarf_t* debug)
 {
        if (debug) {
                if (debug->base_types)
@@ -465,4 +465,3 @@ void scf_dwarf_debug_free (scf_dwarf_debug_t* debug)
                free(debug);
        }
 }
-
diff --git a/elf/scf_dwarf.h b/elf/scf_dwarf.h
new file mode 100644 (file)
index 0000000..08675bc
--- /dev/null
@@ -0,0 +1,444 @@
+#ifndef SCF_DWARF_H
+#define SCF_DWARF_H
+
+#include"scf_list.h"
+#include"scf_vector.h"
+#include"scf_string.h"
+
+typedef int8_t    scf_dwarf_sbyte_t;
+typedef uint8_t   scf_dwarf_ubyte_t;
+typedef uint16_t  scf_dwarf_uhalf_t;
+typedef int32_t   scf_dwarf_sword_t;
+typedef uint32_t  scf_dwarf_uword_t;
+
+typedef struct    scf_dwarf_line_machine_s        scf_dwarf_line_machine_t;
+typedef struct    scf_dwarf_line_prologue_s       scf_dwarf_line_prologue_t;
+typedef struct    scf_dwarf_line_filename_s       scf_dwarf_line_filename_t;
+typedef struct    scf_dwarf_line_result_s         scf_dwarf_line_result_t;
+
+typedef struct    scf_dwarf_abbrev_declaration_s  scf_dwarf_abbrev_declaration_t;
+typedef struct    scf_dwarf_abbrev_attribute_s    scf_dwarf_abbrev_attribute_t;
+
+typedef struct    scf_dwarf_info_header_s         scf_dwarf_info_header_t;
+typedef struct    scf_dwarf_info_entry_s          scf_dwarf_info_entry_t;
+typedef struct    scf_dwarf_info_attr_s           scf_dwarf_info_attr_t;
+typedef struct    scf_dwarf_attr_block_s          scf_dwarf_attr_block_t;
+typedef struct    scf_dwarf_attr_ref_s            scf_dwarf_attr_ref_t;
+
+typedef struct    scf_dwarf_s                     scf_dwarf_t;
+
+// dwarf line standard opcodes
+#define DW_LNS_copy              1
+#define DW_LNS_advance_pc        2
+#define DW_LNS_advance_line      3
+#define DW_LNS_set_file          4
+#define DW_LNS_set_column        5
+#define DW_LNS_negate_stmt       6
+#define DW_LNS_set_basic_block   7
+#define DW_LNS_const_add_pc      8
+#define DW_LNS_fixed_advance_pc  9
+
+// dwarf line extended opcodes
+#define DW_LNE_end_sequence      1
+#define DW_LNE_set_address       2
+#define DW_LNE_define_file       3
+
+// dwarf tags
+#define DW_TAG_array_type             0x01
+#define DW_TAG_class_type             0x02
+#define DW_TAG_entry_point            0x03
+#define DW_TAG_enumeration_type       0x04
+#define DW_TAG_formal_parameter       0x05
+
+#define DW_TAG_imported_declaration   0x08
+
+#define DW_TAG_label                  0x0a
+#define DW_TAG_lexical_block          0x0b
+
+#define DW_TAG_member                 0x0d
+
+#define DW_TAG_pointer_type           0x0f
+
+#define DW_TAG_reference_type         0x10
+#define DW_TAG_compile_unit           0x11
+#define DW_TAG_string_type            0x12
+#define DW_TAG_structure_type         0x13
+
+#define DW_TAG_subroutine_type        0x15
+#define DW_TAG_typedef                0x16
+#define DW_TAG_union_type             0x17
+#define DW_TAG_unspecified_parameters 0x18
+#define DW_TAG_variant                0x19
+#define DW_TAG_common_block           0x1a
+#define DW_TAG_common_inclusion       0x1b
+#define DW_TAG_inheritance            0x1c
+#define DW_TAG_inlined_subroutine     0x1d
+#define DW_TAG_module                 0x1e
+#define DW_TAG_ptr_to_member_type     0x1f
+
+#define DW_TAG_set_type               0x20
+#define DW_TAG_subrange_type          0x21
+#define DW_TAG_with_stmt              0x22
+#define DW_TAG_access_declaration     0x23
+#define DW_TAG_base_type              0x24
+#define DW_TAG_catch_block            0x25
+#define DW_TAG_const_type             0x26
+#define DW_TAG_constant               0x27
+#define DW_TAG_enumerator             0x28
+#define DW_TAG_file_type              0x29
+#define DW_TAG_friend                 0x2a
+#define DW_TAG_namelist               0x2b
+#define DW_TAG_namelist_item          0x2c
+#define DW_TAG_packed_type            0x2d
+#define DW_TAG_subprogram             0x2e
+#define DW_TAG_template_type_param    0x2f
+
+#define DW_TAG_template_value_param   0x30
+#define DW_TAG_thrown_type            0x31
+#define DW_TAG_try_block              0x32
+#define DW_TAG_variant_part           0x33
+#define DW_TAG_variable               0x34
+#define DW_TAG_volatile_type          0x35
+#define DW_TAG_dwarf_procedure        0x36
+#define DW_TAG_restrict_type          0x37
+#define DW_TAG_interface_type         0x38
+#define DW_TAG_namespace              0x39
+#define DW_TAG_imported_module        0x3a
+#define DW_TAG_unspecified_type       0x3b
+#define DW_TAG_partial_unit           0x3c
+#define DW_TAG_imported_unit          0x3d
+
+#define DW_TAG_condition              0x3f
+#define DW_TAG_shared_type            0x40
+#define DW_TAG_type_unit              0x41
+#define DW_TAG_rvalue_reference_type  0x42
+#define DW_TAG_template_alias         0x43
+#define DW_TAG_lo_user                0x4080
+#define DW_TAG_hi_user                0xffff
+
+#define DW_CHILDREN_no                0
+#define DW_CHILDREN_yes               1
+
+// dwarf attributes
+#define DW_AT_sibling                 0x01
+#define DW_AT_location                0x02
+#define DW_AT_name                    0x03
+
+#define DW_AT_ordering                0x09
+
+#define DW_AT_byte_size               0x0b
+#define DW_AT_bit_offset              0x0c
+#define DW_AT_bit_size                0x0d
+
+#define DW_AT_stmt_list               0x10
+#define DW_AT_low_pc                  0x11
+#define DW_AT_high_pc                 0x12
+#define DW_AT_language                0x13
+
+#define DW_AT_discr                   0x15
+#define DW_AT_discr_value             0x16
+#define DW_AT_visibility              0x17
+#define DW_AT_import                  0x18
+#define DW_AT_string_length           0x19
+#define DW_AT_common_reference        0x1a
+#define DW_AT_comp_dir                0x1b
+#define DW_AT_const_value             0x1c
+#define DW_AT_containing_type         0x1d
+#define DW_AT_default_value           0x1e
+
+#define DW_AT_inline                  0x20
+#define DW_AT_is_optional             0x21
+#define DW_AT_lower_bound             0x22
+
+#define DW_AT_producer                0x25
+
+#define DW_AT_prototyped              0x27
+
+#define DW_AT_return_addr             0x2a
+#define DW_AT_start_scope             0x2c
+#define DW_AT_stride_size             0x2e
+#define DW_AT_upper_bound             0x2f
+
+#define DW_AT_abstract_origin         0x31
+#define DW_AT_accessibility           0x32
+#define DW_AT_address_class           0x33
+#define DW_AT_artificial              0x34
+#define DW_AT_base_types              0x35
+#define DW_AT_calling_convention      0x36
+#define DW_AT_count                   0x37
+#define DW_AT_data_member_location    0x38
+#define DW_AT_decl_column             0x39
+#define DW_AT_decl_file               0x3a
+#define DW_AT_decl_line               0x3b
+#define DW_AT_declaration             0x3c
+#define DW_AT_discr_list              0x3d
+#define DW_AT_encoding                0x3e
+#define DW_AT_external                0x3f
+#define DW_AT_frame_base              0x40
+#define DW_AT_friend                  0x41
+#define DW_AT_identifier_case         0x42
+#define DW_AT_macro_info              0x43
+#define DW_AT_namelist_item           0x44
+#define DW_AT_priority                0x45
+#define DW_AT_segment                 0x46
+#define DW_AT_specification           0x47
+#define DW_AT_static_link             0x48
+#define DW_AT_type                    0x49
+#define DW_AT_use_location            0x4a
+#define DW_AT_variable_parameter      0x4b
+#define DW_AT_virtuality              0x4c
+#define DW_AT_vtable_elem_location    0x4d
+
+#define DW_AT_lo_user                 0x2000
+#define DW_AT_GNU_all_call_sites      0x2117
+#define DW_AT_hi_user                 0x3fff
+
+#define DW_ATE_address                0x1
+#define DW_ATE_boolean                0x2
+#define DW_ATE_complex_float          0x3
+#define DW_ATE_float                  0x4
+#define DW_ATE_signed                 0x5
+#define DW_ATE_signed_char            0x6
+#define DW_ATE_unsigned               0x7
+#define DW_ATE_unsigned_char          0x8
+#define DW_ATE_lo_user                0x80
+#define DW_ATE_hi_user                0xff
+
+// dwarf forms
+#define DW_FORM_addr                  0x01
+#define DW_FORM_block2                0x03
+#define DW_FORM_block4                0x04
+#define DW_FORM_data2                 0x05
+#define DW_FORM_data4                 0x06
+#define DW_FORM_data8                 0x07
+#define DW_FORM_string                0x08
+#define DW_FORM_block                 0x09
+#define DW_FORM_block1                0x0a
+#define DW_FORM_data1                 0x0b
+#define DW_FORM_flag                  0x0c
+#define DW_FORM_sdata                 0x0d
+#define DW_FORM_strp                  0x0e
+#define DW_FORM_udata                 0x0f
+#define DW_FORM_ref_addr              0x10
+#define DW_FORM_ref1                  0x11
+#define DW_FORM_ref2                  0x12
+#define DW_FORM_ref4                  0x13
+#define DW_FORM_ref8                  0x14
+#define DW_FORM_ref_udata             0x15
+#define DW_FORM_indirect              0x16
+#define DW_FORM_sec_offset            0x17
+#define DW_FORM_exprloc               0x18
+#define DW_FORM_flag_present          0x19
+#define DW_FORM_ref_sig8              0x20
+
+#define DW_OP_fbreg                   0x91
+#define DW_OP_call_frame_cfa          0x9c
+
+struct scf_dwarf_info_header_s
+{
+       scf_dwarf_uword_t  length;
+       scf_dwarf_uhalf_t  version;
+       scf_dwarf_uword_t  offset;
+       scf_dwarf_ubyte_t  address_size;
+};
+
+struct scf_dwarf_info_entry_s
+{
+       scf_dwarf_uword_t  code;
+
+       uint64_t           cu_byte_offset;
+
+       scf_vector_t*      attributes;
+
+       int                type;
+       int                nb_pointers;
+};
+
+struct scf_dwarf_attr_ref_s
+{
+       scf_dwarf_info_attr_t*  iattr;
+
+       scf_dwarf_info_entry_t* ie;
+       scf_dwarf_info_entry_t* ref_entry;
+
+       uint64_t                offset;
+       size_t                  size;
+};
+
+struct scf_dwarf_info_attr_s
+{
+       scf_dwarf_uword_t       name;
+       scf_dwarf_uword_t       form;
+
+       scf_dwarf_info_entry_t* ref_entry;
+
+       uintptr_t               block_ref;
+       uint64_t                block_ref8;
+
+       union {
+               scf_dwarf_uword_t   block_length;
+
+               uintptr_t           address;
+               uint8_t             const1;
+               uint16_t            const2;
+               uint32_t            const4;
+               uint64_t            const8;
+               scf_dwarf_sword_t   sdata;
+               scf_dwarf_uword_t   udata;
+
+               scf_dwarf_ubyte_t   flag;
+
+               scf_dwarf_uword_t   lineptr;
+               scf_dwarf_uword_t   exprloc;
+
+               uintptr_t           ref;
+               uint64_t            ref8;
+
+               scf_dwarf_uword_t   str_offset;
+       };
+
+       scf_string_t*           data;
+};
+
+struct scf_dwarf_abbrev_attribute_s
+{
+       scf_dwarf_uword_t  name;
+       scf_dwarf_uword_t  form;
+};
+
+struct scf_dwarf_abbrev_declaration_s
+{
+       scf_dwarf_uword_t  code;
+       scf_dwarf_uword_t  tag;
+       scf_dwarf_ubyte_t  has_children;
+
+       scf_vector_t*      attributes;
+
+       scf_vector_t*      childs;
+
+       scf_dwarf_abbrev_declaration_t* parent;
+
+       uint32_t           visited_flag:1;
+};
+
+struct scf_dwarf_line_result_s
+{
+       uintptr_t          address;
+
+       scf_string_t*      file_name;
+       scf_dwarf_uword_t  line;
+       scf_dwarf_uword_t  column;
+
+       scf_dwarf_ubyte_t  is_stmt     :1;
+       scf_dwarf_ubyte_t  basic_block :1;
+       scf_dwarf_ubyte_t  end_sequence:1;
+};
+
+struct scf_dwarf_line_filename_s
+{
+       scf_dwarf_ubyte_t* name;
+       scf_dwarf_uword_t  dir_index;
+       scf_dwarf_uword_t  time_modified;
+       scf_dwarf_uword_t  length;
+};
+
+struct scf_dwarf_line_prologue_s
+{
+       scf_dwarf_uword_t      total_length;
+       scf_dwarf_uhalf_t      version;
+       scf_dwarf_uword_t      prologue_length;
+
+       scf_dwarf_ubyte_t      minimum_instruction_length;
+
+       scf_dwarf_ubyte_t      default_is_stmt;
+
+       scf_dwarf_sbyte_t      line_base;
+       scf_dwarf_ubyte_t      line_range;
+
+       scf_dwarf_ubyte_t      opcode_base;
+       scf_dwarf_ubyte_t*     standard_opcode_lengths;
+    scf_dwarf_ubyte_t*     include_directories;
+    scf_vector_t*          file_names;
+};
+
+struct scf_dwarf_line_machine_s
+{
+       // registers
+       uintptr_t           address;
+
+       scf_dwarf_uword_t   file;
+       scf_dwarf_uword_t   line;
+       scf_dwarf_uword_t   column;
+
+       scf_dwarf_ubyte_t   is_stmt     :1;
+       scf_dwarf_ubyte_t   basic_block :1;
+       scf_dwarf_ubyte_t   end_sequence:1;
+
+       scf_dwarf_line_prologue_t* prologue;
+};
+
+struct scf_dwarf_s
+{
+       char*               arch;
+
+       scf_vector_t*       base_types;
+       scf_vector_t*       struct_types;
+
+       scf_vector_t*       lines;
+       scf_vector_t*       infos;
+       scf_vector_t*       abbrevs;
+       scf_string_t*       str;
+
+       scf_string_t*       debug_line;
+       scf_string_t*       debug_info;
+       scf_string_t*       debug_abbrev;
+
+       scf_vector_t*       line_relas;
+       scf_vector_t*       info_relas;
+       scf_vector_t*       file_names;
+};
+
+scf_dwarf_t*  scf_dwarf_debug_alloc();
+void          scf_dwarf_debug_free  (scf_dwarf_t* debug);
+int           scf_dwarf_debug_encode(scf_dwarf_t* debug);
+
+int scf_dwarf_abbrev_add_cu (scf_vector_t* abbrevs);
+int scf_dwarf_abbrev_add_var(scf_vector_t* abbrevs);
+
+int scf_dwarf_abbrev_add_subprogram  (scf_vector_t* abbrevs);
+int scf_dwarf_abbrev_add_struct_type (scf_vector_t* abbrevs);
+int scf_dwarf_abbrev_add_member_var  (scf_vector_t* abbrevs);
+int scf_dwarf_abbrev_add_base_type   (scf_vector_t* abbrevs);
+int scf_dwarf_abbrev_add_pointer_type(scf_vector_t* abbrevs);
+
+scf_dwarf_info_entry_t*    scf_dwarf_info_entry_alloc();
+void                       scf_dwarf_info_entry_free(scf_dwarf_info_entry_t* ie);
+void                       scf_dwarf_info_attr_free (scf_dwarf_info_attr_t* attr);
+int                        scf_dwarf_info_fill_attr (scf_dwarf_info_attr_t* iattr, uint8_t* data, size_t len);
+
+scf_dwarf_line_machine_t*  scf_dwarf_line_machine_alloc();
+void                       scf_dwarf_line_machine_print(scf_dwarf_line_machine_t* lm);
+int                        scf_dwarf_line_machine_fill (scf_dwarf_line_machine_t* lm, scf_vector_t* file_names);
+void                       scf_dwarf_line_machine_free (scf_dwarf_line_machine_t* lm);
+void                       scf_dwarf_line_filename_free(scf_dwarf_line_filename_t* f);
+
+scf_dwarf_abbrev_declaration_t*  scf_dwarf_abbrev_declaration_alloc();
+void                             scf_dwarf_abbrev_declaration_free(scf_dwarf_abbrev_declaration_t* d);
+
+int scf_dwarf_line_decode(                    scf_dwarf_line_machine_t* lm, scf_vector_t* line_results, const char*   debug_line, size_t debug_line_size);
+int scf_dwarf_line_encode(scf_dwarf_t* debug, scf_dwarf_line_machine_t* lm, scf_vector_t* line_results, scf_string_t* debug_line);
+
+int scf_dwarf_abbrev_decode(scf_vector_t* abbrev_results, const char*   debug_abbrev, size_t debug_abbrev_size);
+int scf_dwarf_abbrev_encode(scf_vector_t* abbrev_results, scf_string_t* debug_abbrev);
+
+int scf_dwarf_info_decode(scf_vector_t* infos, scf_vector_t* abbrevs, scf_string_t* debug_str, const char*   debug_info, size_t debug_info_size, scf_dwarf_info_header_t* header);
+int scf_dwarf_info_encode(scf_dwarf_t* debug, scf_dwarf_info_header_t* header);
+
+void scf_dwarf_abbrev_print(scf_vector_t* abbrev_results);
+void scf_dwarf_info_print  (scf_vector_t* infos);
+
+const char* scf_dwarf_find_tag (const uint32_t type);
+const char* scf_dwarf_find_form(const uint32_t type);
+const char* scf_dwarf_find_attribute(const uint32_t type);
+
+#endif
index 5a44e5c25e78e493e4579c3dedb47ae15ac143a1..93b26b064a675975cebcb9101635a107f8dec993 100644 (file)
@@ -1,4 +1,4 @@
-#include"scf_dwarf_def.h"
+#include"scf_dwarf.h"
 #include"scf_leb128.h"
 
 typedef struct {
index b270d169c29e8117cad9223925eeb89cedc94d21..76bf924719e00c13353a3cd24a3a3d21b9b509a0 100644 (file)
@@ -1,4 +1,4 @@
-#include"scf_dwarf_def.h"
+#include"scf_dwarf.h"
 #include"scf_leb128.h"
 #include"scf_native.h"
 #include"scf_elf.h"
@@ -291,7 +291,7 @@ int scf_dwarf_info_decode(scf_vector_t* infos, scf_vector_t* abbrevs, scf_string
        return 0;
 }
 
-static int _add_rela_common(scf_dwarf_debug_t* debug, const char* sym, uint64_t offset, int type, int addend)
+static int _add_rela_common(scf_dwarf_t* debug, const char* sym, uint64_t offset, int type, int addend)
 {
        scf_rela_t* rela = calloc(1, sizeof(scf_rela_t));
        if (!rela)
@@ -350,7 +350,7 @@ static int _add_rela_common(scf_dwarf_debug_t* debug, const char* sym, uint64_t
        return 0;
 }
 
-static int _add_rela_subprogram(scf_dwarf_debug_t* debug, scf_dwarf_info_entry_t* ie, uint64_t offset, int type)
+static int _add_rela_subprogram(scf_dwarf_t* debug, scf_dwarf_info_entry_t* ie, uint64_t offset, int type)
 {
        scf_dwarf_info_attr_t* iattr = NULL;
 
@@ -368,7 +368,7 @@ static int _add_rela_subprogram(scf_dwarf_debug_t* debug, scf_dwarf_info_entry_t
        return _add_rela_common(debug, iattr->data->data, offset, type, 0);
 }
 
-int scf_dwarf_info_encode(scf_dwarf_debug_t* debug, scf_dwarf_info_header_t* header)
+int scf_dwarf_info_encode(scf_dwarf_t* debug, scf_dwarf_info_header_t* header)
 {
        if (!debug || !header) {
                scf_loge("\n");
@@ -845,4 +845,3 @@ void scf_dwarf_info_print(scf_vector_t* infos)
                }
        }
 }
-
index a59ec108570659111937f869a8b42f66b593cc0f..15a5aa8f55f40a10312bf2049cb607f8860106b3 100644 (file)
@@ -1,4 +1,4 @@
-#include"scf_dwarf_def.h"
+#include"scf_dwarf.h"
 #include"scf_leb128.h"
 #include"scf_native.h"
 #include"scf_elf.h"
@@ -542,7 +542,7 @@ int scf_dwarf_line_decode(scf_dwarf_line_machine_t* lm, scf_vector_t* line_resul
        return 0;
 }
 
-int scf_dwarf_line_encode(scf_dwarf_debug_t* debug, scf_dwarf_line_machine_t* lm, scf_vector_t* line_results, scf_string_t* debug_line)
+int scf_dwarf_line_encode(scf_dwarf_t* debug, scf_dwarf_line_machine_t* lm, scf_vector_t* line_results, scf_string_t* debug_line)
 {
        if (!debug || !lm || !line_results || !debug_line)
                return -EINVAL;
index 96a6ffc44046dabb55e9c7c17a04df181791a702..76c0e9b448819d6d844f8dea87b008ea3d14efe2 100644 (file)
@@ -1,4 +1,4 @@
-include "../lib/scf_capi.c";
+#include "../lib/scf_capi.c"
 
 int* f()
 {
index 611e02b984f9bf679c220275daae37c058d4a793..0eb87764715c0b1ec3996e5d95a933c35d008720 100644 (file)
@@ -1,5 +1,5 @@
-include "../lib/scf_capi.c";
-include "../lib/scf_complex.c";
+#include "../lib/scf_capi.c"
+#include "../lib/scf_complex.c"
 
 int main()
 {
index f5d179cdaf253d9f2e1bcfbb60c266b4816baab7..7d5985b59b17800c491dda3c62654bfa72fc8bad 100644 (file)
@@ -1,5 +1,5 @@
-include "../lib/scf_list.c";
-include "../lib/scf_capi.c";
+#include "../lib/scf_list.c"
+#include "../lib/scf_capi.c"
 
 struct Data
 {
diff --git a/examples/macro.c b/examples/macro.c
new file mode 100644 (file)
index 0000000..a931386
--- /dev/null
@@ -0,0 +1,10 @@
+
+int printf(const char* fmt, ...);
+
+#define ABC 1111 
+
+int main()
+{
+       printf("ABC: %d\n", ABC);
+       return 0;
+}
index 4c5241c4578983641feb7e0245818076a3887835..fb99a1c2f09d9e4823e63cd726d74f2e5942dcae 100644 (file)
@@ -1,5 +1,5 @@
 
-include "../lib/scf_capi.c";
+#include"../lib/scf_capi.c"
 
 const int    MAT_TYPE_NONE   = 0;
 const int    MAT_TYPE_U8     = 1;
index 2434b410bb6af9215412c2cfdc4dd4609a7be198..83ae6bc9508a5a5fc7ba1580431fa85bd49a7d39 100644 (file)
@@ -1,4 +1,4 @@
-include "../lib/scf_capi.c";
+#include "../lib/scf_capi.c"
 
 int f(int** t0, int **t1);
 
index ee00f0d086b02f0fee84db86afc4e82311aa7e9a..cdc12ce94bf4b0ea3da42799d2982858ec312259 100644 (file)
@@ -1,5 +1,5 @@
 
-include "../lib/scf_capi.c";
+#include "../lib/scf_capi.c"
 
 struct str
 {
index f204d7212863886547a460d8802b05dc328bffa4..335b19b9fface1882473ee0695c39e0a149a0e27 100644 (file)
@@ -1,5 +1,5 @@
 
-include "../lib/scf_capi.c";
+#include "../lib/scf_capi.c"
 
 struct str
 {
@@ -39,4 +39,3 @@ int main()
        printf("%s\n", p0->data);
        return 0;
 }
-
index 81b522b0ce468f00198b64f06d10840162360dac..081733eaf904510d3ab6564c4c71190b13c71bae 100644 (file)
@@ -1,4 +1,4 @@
-include "../lib/scf_capi.c";
+#include "../lib/scf_capi.c"
 
 struct string
 {
index adda7005f5605111db65bd596663bac58ded1e01..42fff046f1a1e4a45730cf2a4a8d97c6a5713958 100644 (file)
@@ -66,6 +66,7 @@ static scf_key_word_t  key_words[] =
        {"async",     SCF_LEX_WORD_KEY_ASYNC},
 
        {"include",   SCF_LEX_WORD_KEY_INCLUDE},
+       {"define",    SCF_LEX_WORD_KEY_DEFINE},
 
        {"enum",      SCF_LEX_WORD_KEY_ENUM},
        {"union",     SCF_LEX_WORD_KEY_UNION},
@@ -114,10 +115,6 @@ int        scf_lex_open(scf_lex_t** plex, const char* path)
        if (!lex)
                return -ENOMEM;
 
-       scf_list_init(&lex->word_list_head);
-
-       lex->char_list_head = NULL;
-
        lex->fp = fopen(path, "r");
        if (!lex->fp) {
                char cwd[4096];
@@ -144,18 +141,28 @@ int       scf_lex_open(scf_lex_t** plex, const char* path)
 int scf_lex_close(scf_lex_t* lex)
 {
        if (lex) {
-               scf_list_clear(&lex->word_list_head, scf_lex_word_t, list, scf_lex_word_free);
+               scf_slist_clear(lex->char_list, scf_char_t,     next, free);
+               scf_slist_clear(lex->word_list, scf_lex_word_t, next, scf_lex_word_free);
+
+               if (lex->macros) {
+                       scf_vector_clear(lex->macros, ( void (*)(void*) )scf_macro_free);
+                       scf_vector_free (lex->macros);
+               }
 
+               scf_string_free(lex->file);
+
+               fclose(lex->fp);
                free(lex);
        }
        return 0;
 }
 
-int scf_lex_push_word(scf_lex_t* lex, scf_lex_word_t* word)
+void scf_lex_push_word(scf_lex_t* lex, scf_lex_word_t* w)
 {
-       if (lex && word)
-               scf_list_add_front(&lex->word_list_head, &word->list);
-       return 0;
+       if (lex && w) {
+               w->next        = lex->word_list;
+               lex->word_list = w;
+       }
 }
 
 static int _lex_plus(scf_lex_t* lex, scf_lex_word_t** pword, scf_char_t* c0)
@@ -613,28 +620,87 @@ static int _lex_string(scf_lex_t* lex, scf_lex_word_t** pword, scf_char_t* c0)
        }
 }
 
-int scf_lex_pop_word(scf_lex_t* lex, scf_lex_word_t** pword)
+static int _lex_macro(scf_lex_t* lex)
 {
-       if (!lex || !lex->fp || !pword)
-               return -EINVAL;
+       scf_char_t*  h  =  NULL;
+       scf_char_t** pp = &h;
+       scf_char_t*  c;
+       scf_char_t*  c2;
+
+       while (1) {
+               c = _lex_pop_char(lex);
+               if (!c) {
+                       scf_slist_clear(h, scf_char_t, next, free);
+                       return -1;
+               }
+
+               *pp =  c;
+               pp  = &c->next;
+
+               if (EOF == c->c)
+                       break;
+
+               if ('\n' == c->c) {
+                       c->flag = SCF_UTF8_LF;
+                       break;
+               }
+
+               if ('\\' == c->c) {
+
+                       c2 = _lex_pop_char(lex);
+                       if (!c2) {
+                               scf_slist_clear(h, scf_char_t, next, free);
+                               return -1;
+                       }
 
+                       *pp =  c2;
+                       pp  = &c2->next;
+
+                       if (EOF == c2->c)
+                               break;
+
+                       if ('\n' == c2->c)
+                               c->c = ' ';
+               }
+       }
+
+       *pp = lex->char_list;
+       lex->char_list = h;
+       return 0;
+}
+
+static int __lex_pop_word(scf_lex_t* lex, scf_lex_word_t** pword)
+{
        scf_list_t*             l = NULL;
        scf_char_t*     c = NULL;
        scf_lex_word_t* w = NULL;
 
-       if (!scf_list_empty(&lex->word_list_head)) {
-               l = scf_list_head(&lex->word_list_head);
-               w = scf_list_data(l, scf_lex_word_t, list);
+       if (lex->word_list) {
+               w              = lex->word_list;
+               lex->word_list = w->next;
 
-               scf_list_del(&w->list);
                *pword = w;
                return 0;
        }
 
        c = _lex_pop_char(lex);
 
-       while  ('\n' == c->c || '\r' == c->c || '\t' == c->c || ' ' == c->c) {
+       while ('\n' == c->c || '\r' == c->c || '\t' == c->c || ' ' == c->c) {
+
                if ('\n' == c->c) {
+                       if (SCF_UTF8_LF == c->flag) {
+                               w       = scf_lex_word_alloc(lex->file, lex->nb_lines, lex->pos, SCF_LEX_WORD_LF);
+                               w->text = scf_string_cstr("LF");
+                               *pword  = w;
+
+                               lex->nb_lines++;
+                               lex->pos = 0;
+
+                               free(c);
+                               c = NULL;
+                               return 0;
+                       }
+
                        lex->nb_lines++;
                        lex->pos = 0;
                } else
@@ -696,7 +762,7 @@ int scf_lex_pop_word(scf_lex_t* lex, scf_lex_word_t** pword)
                                }
                        }
 
-                       return scf_lex_pop_word(lex, pword);
+                       return __lex_pop_word(lex, pword);
 
                } else if ('*' == c2->c) {
                        free(c);
@@ -736,7 +802,7 @@ int scf_lex_pop_word(scf_lex_t* lex, scf_lex_word_t** pword)
                                }
                        }
 
-                       return scf_lex_pop_word(lex, pword);
+                       return __lex_pop_word(lex, pword);
 
                } else {
                        _lex_push_char(lex, c2);
@@ -838,6 +904,7 @@ int scf_lex_pop_word(scf_lex_t* lex, scf_lex_word_t** pword)
 
        if ('\"' == c->c) {
                scf_lex_word_t* w0 = NULL;
+               scf_lex_word_t* w1 = NULL;
 
                int ret = _lex_string(lex, &w0, c);
                if (ret < 0) {
@@ -846,9 +913,7 @@ int scf_lex_pop_word(scf_lex_t* lex, scf_lex_word_t** pword)
                }
 
                while (1) {
-                       scf_lex_word_t* w1 = NULL;
-
-                       ret = scf_lex_pop_word(lex, &w1);
+                       ret = __lex_pop_word(lex, &w1);
                        if (ret < 0) {
                                scf_lex_word_free(w0);
                                *pword = NULL;
@@ -888,6 +953,312 @@ int scf_lex_pop_word(scf_lex_t* lex, scf_lex_word_t** pword)
                return _lex_identity(lex, pword, c);
        }
 
+       if ('#' == c->c) {
+               w = scf_lex_word_alloc(lex->file, lex->nb_lines, lex->pos, SCF_LEX_WORD_HASH);
+
+               free(c);
+               c = _lex_pop_char(lex);
+
+               if ('#' == c->c) {
+                       w->type = SCF_LEX_WORD_HASH2;
+                       w->text = scf_string_cstr("##");
+
+                       lex->pos += 2;
+                       free(c);
+               } else {
+                       w->text = scf_string_cstr("#");
+
+                       lex->pos++;
+                       _lex_push_char(lex, c);
+               }
+
+               c = NULL;
+               *pword = w;
+               return _lex_macro(lex);
+       }
+
        scf_loge("unknown char: %c, utf: %#x, in file: %s, line: %d\n", c->c, c->c, lex->file->data, lex->nb_lines);
        return -1;
 }
+
+static int __parse_macro_argv(scf_lex_t* lex, scf_macro_t* m)
+{
+       scf_lex_word_t* w = NULL;
+       scf_lex_word_t* w2;
+
+       int comma = 0;
+       int id    = 0;
+
+       while (1) {
+               int ret = __lex_pop_word(lex, &w);
+               if (ret < 0)
+                       return ret;
+
+               if (!comma) {
+                       if (SCF_LEX_WORD_RP == w->type) {
+                               scf_lex_word_free(w);
+                               break;
+                       }
+
+                       if (SCF_LEX_WORD_COMMA == w->type) {
+                               scf_lex_word_free(w);
+                               w = NULL;
+
+                               if (!id) {
+                                       scf_loge("an identity is needed before ',' in file: %s, line: %d\n", w->file->data, w->line);
+                                       return -1;
+                               }
+
+                               id    = 0;
+                               comma = 1;
+                               continue;
+                       }
+               }
+
+               if (!scf_lex_is_identity(w)) {
+                       scf_loge("macro arg '%s' should be an identity, file: %s, line: %d\n", w->text->data, w->file->data, w->line);
+                       scf_lex_word_free(w);
+                       return -1;
+               }
+
+               if (id) {
+                       scf_loge("',' is needed before macro arg '%s', file: %s, line: %d\n", w->text->data, w->file->data, w->line);
+                       scf_lex_word_free(w);
+                       return -1;
+               }
+
+               int i;
+               for (i = 0; i < m->argv->size; i++) {
+                       w2 =        m->argv->data[i];
+
+                       if (!scf_string_cmp(w2->text, w->text)) {
+                               scf_loge("macro has same args '%s', file: %s, line: %d\n", w->text->data, w->file->data, w->line);
+                               scf_lex_word_free(w);
+                               return -1;
+                       }
+               }
+
+               ret = scf_vector_add(m->argv, w);
+               if (ret < 0) {
+                       scf_lex_word_free(w);
+                       return ret;
+               }
+               w = NULL;
+
+               id    = 1;
+               comma = 0;
+       }
+
+       return 0;
+}
+
+static int __parse_macro_define(scf_lex_t* lex, scf_lex_word_t* w0, scf_lex_word_t* w1)
+{
+       scf_lex_word_t** pp;
+       scf_lex_word_t*  w = NULL;
+       scf_macro_t*     m;
+       scf_macro_t*     m0;
+
+       scf_lex_word_free(w0);
+       scf_lex_word_free(w1);
+       w0 = NULL;
+       w1 = NULL;
+
+       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 -1;
+       }
+
+       m = scf_macro_alloc(w);
+       if (!m) {
+               scf_lex_word_free(w);
+               return -ENOMEM;
+       }
+
+       w   = NULL;
+       ret = __lex_pop_word(lex, &w);
+       if (ret < 0) {
+               scf_macro_free(m);
+               return ret;
+       }
+
+       pp = &m->text_list;
+
+       if (SCF_LEX_WORD_LP == w->type) {
+               scf_lex_word_free(w);
+               w = NULL;
+
+               m->argv = scf_vector_alloc();
+               if (!m->argv) {
+                       scf_macro_free(m);
+                       return -ENOMEM;
+               }
+
+               ret = __parse_macro_argv(lex, m);
+               if (ret < 0) {
+                       scf_macro_free(m);
+                       return ret;
+               }
+       } else {
+               *pp =  w;
+               pp  = &w->next;
+               w   = NULL;
+       }
+
+       while (1) {
+               ret = __lex_pop_word(lex, &w);
+               if (ret < 0) {
+                       scf_macro_free(m);
+                       return ret;
+               }
+
+               if (SCF_LEX_WORD_LF == w->type) {
+                       scf_lex_word_free(w);
+                       w = NULL;
+                       break;
+               }
+
+               *pp =  w;
+               pp  = &w->next;
+               w   = NULL;
+       }
+
+       if (!lex->macros) {
+               lex->macros = scf_vector_alloc();
+               if (!lex->macros)
+                       return -ENOMEM;
+
+       } else {
+               int i;
+               for (i = lex->macros->size - 1; i >= 0; i--) {
+                       m0 = lex->macros->data[i];
+
+                       if (!scf_string_cmp(m->w->text, m0->w->text)) {
+                               scf_logw("macro '%s' defined before in file: %s, line: %d\n",
+                                               m0->w->text->data, m0->w->file->data, m0->w->line);
+                               break;
+                       }
+               }
+       }
+
+       ret = scf_vector_add(lex->macros, m);
+       if (ret < 0) {
+               scf_macro_free(m);
+               return ret;
+       }
+
+       return 0;
+}
+
+static int __parse_macro(scf_lex_t* lex, scf_lex_word_t** pword, scf_lex_word_t* w0)
+{
+       scf_lex_word_t* w1 = NULL;
+
+       int ret = __lex_pop_word(lex, &w1);
+       if (ret < 0) {
+               scf_lex_word_free(w0);
+               return ret;
+       }
+
+       switch (w1->type) {
+
+               case SCF_LEX_WORD_KEY_INCLUDE:
+
+                       scf_lex_push_word(lex, w1);
+                       *pword = w0;
+                       return 0;
+
+                       break;
+               case SCF_LEX_WORD_KEY_DEFINE:
+
+                       ret = __parse_macro_define(lex, w0, w1);
+                       if (ret < 0)
+                               return ret;
+                       break;
+
+               default:
+                       scf_loge("unknown macro '%s', file: %s, line: %d\n", w1->text->data, w1->file->data, w1->line);
+
+                       scf_lex_word_free(w0);
+                       scf_lex_word_free(w1);
+                       return -1;
+                       break;
+       };
+
+       return scf_lex_pop_word(lex, pword);
+}
+
+static int __use_macro(scf_lex_t* lex, scf_lex_word_t** pword, scf_lex_word_t* w)
+{
+       scf_lex_word_t** pp;
+       scf_lex_word_t*  p;
+       scf_lex_word_t*  h;
+       scf_macro_t*     m;
+
+       if (!lex->macros) {
+               *pword = w;
+               return 0;
+       }
+
+       int i;
+       for (i = lex->macros->size - 1; i >= 0; i--) {
+               m  = lex->macros->data[i];
+
+               if (!scf_string_cmp(m->w->text, w->text))
+                       break;
+       }
+
+       if (i < 0) {
+               *pword = w;
+               return 0;
+       }
+
+       scf_lex_word_free(w);
+       w = NULL;
+
+       h  = NULL;
+       pp = &h;
+       for (p = m->text_list; p; p = p->next) {
+
+               w  = scf_lex_word_clone(p);
+               if (!w) {
+                       scf_slist_clear(h, scf_lex_word_t, next, scf_lex_word_free);
+                       return -ENOMEM;
+               }
+
+               *pp =  w;
+               pp  = &w->next;
+       }
+
+       *pp            = lex->word_list;
+       lex->word_list = h;
+
+       return scf_lex_pop_word(lex, pword);
+}
+
+int scf_lex_pop_word(scf_lex_t* lex, scf_lex_word_t** pword)
+{
+       if (!lex || !lex->fp || !pword)
+               return -EINVAL;
+
+       scf_lex_word_t* w = NULL;
+
+       int ret = __lex_pop_word(lex, &w);
+       if (ret < 0)
+               return ret;
+
+       if (SCF_LEX_WORD_HASH == w->type)
+               return __parse_macro(lex, pword, w);
+
+       //use macro to identity
+       if (scf_lex_is_identity(w))
+               return __use_macro(lex, pword, w);
+
+       *pword = w;
+       return 0;
+}
index 9d42928bf06c57f0af931fe190064b0bb3275649..bdcf53926e7982800c65fe7fb461bf0fa45b25bf 100644 (file)
@@ -4,6 +4,7 @@
 #include"scf_lex_word.h"
 
 typedef struct scf_char_s  scf_char_t;
+typedef struct scf_lex_s   scf_lex_t;
 
 typedef struct {
        char*   text;
@@ -16,6 +17,7 @@ typedef struct {
 } scf_escape_char_t;
 
 #define SCF_UTF8_MAX 6
+#define SCF_UTF8_LF  1
 struct scf_char_s
 {
        scf_char_t*     next;
@@ -23,29 +25,35 @@ struct scf_char_s
 
        int             len;
        uint8_t         utf8[SCF_UTF8_MAX];
+       uint8_t         flag;
 };
 
-typedef struct {
-       scf_list_t      word_list_head; // word list head
-       scf_char_t*     char_list_head; // temp char list head
+struct scf_lex_s
+{
+       scf_lex_t*      next;
+
+       scf_lex_word_t* word_list;
+       scf_char_t*     char_list;
+
+       scf_vector_t*   macros;
 
        FILE*           fp; // file pointer to the code
 
        scf_string_t*   file; // original code file name
        int             nb_lines;
        int             pos;
-} scf_lex_t;
+};
 
 
 scf_char_t*  _lex_pop_char (scf_lex_t* lex);
 void         _lex_push_char(scf_lex_t* lex, scf_char_t* c);
 
 
-int    scf_lex_open (scf_lex_t** plex, const char* path);
-int scf_lex_close(scf_lex_t*   lex);
+int     scf_lex_open (scf_lex_t** plex, const char* path);
+int  scf_lex_close(scf_lex_t*   lex);
 
-int scf_lex_push_word(scf_lex_t* lex, scf_lex_word_t*   word);
-int scf_lex_pop_word (scf_lex_t* lex, scf_lex_word_t** pword);
+void scf_lex_push_word(scf_lex_t* lex, scf_lex_word_t*   word);
+int  scf_lex_pop_word (scf_lex_t* lex, scf_lex_word_t** pword);
 
 
 int _lex_number_base_16(scf_lex_t* lex, scf_lex_word_t** pword, scf_string_t* s);
index 14ff78d69e18e46e90a0209d8404df32048bc84b..5a6e5899d21b9f2426e760f03c14249f6487641b 100644 (file)
@@ -7,15 +7,16 @@ scf_char_t* _lex_pop_char(scf_lex_t* lex)
 
        scf_char_t* c;
 
-       if (lex->char_list_head) {
-               c                   = lex->char_list_head;
-               lex->char_list_head = c->next;
+       if (lex->char_list) {
+               c              = lex->char_list;
+               lex->char_list = c->next;
                return c;
        }
 
        c = malloc(sizeof(scf_char_t));
        if (!c)
                return NULL;
+       c->next = NULL;
 
        int ret = fgetc(lex->fp);
        if (EOF == ret) {
@@ -82,8 +83,8 @@ void _lex_push_char(scf_lex_t* lex, scf_char_t* c)
        assert(lex);
        assert(c);
 
-       c->next             = lex->char_list_head;
-       lex->char_list_head = c;
+       c->next        = lex->char_list;
+       lex->char_list = c;
 }
 
 int _lex_op1_ll1(scf_lex_t* lex, scf_lex_word_t** pword, scf_char_t* c0, int type0)
index 430b6006e1dc6a531cae4854da754a0a695aa2c7..86ac0e6ea623a7a5284db4d2b1f12192070864b6 100644 (file)
@@ -1,5 +1,4 @@
-
-include "../lib/scf_capi.c";
+#include "../lib/scf_capi.c"
 
 struct complex
 {
index b3c380fd59afbd30bacaf5d48b1ff573488ca437..d793978a46234489392b23f92783e0e08f224f49 100644 (file)
@@ -118,13 +118,14 @@ CFILES += ../core/scf_optimizer_group.c
 CFILES += ../core/scf_optimizer_generate_loads_saves.c
 
 CFILES += ../core/scf_ast.c
-
 CFILES += ../core/scf_calculate.c
 
 CFILES += scf_dfa.c
 CFILES += scf_dfa_parse.c
 
+CFILES += scf_dfa_macro.c
 CFILES += scf_dfa_include.c
+
 CFILES += scf_dfa_call.c
 CFILES += scf_dfa_create.c
 CFILES += scf_dfa_sizeof.c
index cd3a7d128d25ce23819f375f228911af116f378c..c96968ec7ace6718a5df0e0eba8138f75863eb6a 100644 (file)
@@ -211,7 +211,7 @@ int main(int argc, char* argv[])
                }
        }
 
-       char* obj  = "1.elf";
+       char* obj  = "1.o";
        char* exec = "1.out";
 
        if (out) {
index 96b773c70052e49456f877286af8d1896a01488b..2c14d165a9fd74aea9e4f5977625bc2d1197a1e0 100644 (file)
@@ -299,7 +299,7 @@ static int _scf_dfa_node_parse_word(scf_dfa_t* dfa, scf_dfa_node_t* node, scf_ve
        int             ret = SCF_DFA_NEXT_WORD;
        scf_lex_word_t* w   = words->data[words->size - 1];
 
-       scf_logi("\033[33m%s->action(), w: %s, position: %d,%d\033[0m\n", node->name, w->text->data, w->line, w->pos);
+       scf_logi("\033[32m%s->action(), w: %s, position: %d,%d\033[0m\n", node->name, w->text->data, w->line, w->pos);
 
        if (node->action) {
 
@@ -320,13 +320,13 @@ static int _scf_dfa_node_parse_word(scf_dfa_t* dfa, scf_dfa_node_t* node, scf_ve
 #if 1
        scf_dfa_hook_t* h = dfa->hooks[SCF_DFA_HOOK_POST];
        while (h) {
-               scf_logd("\033[32m post hook: %s\033[0m\n", h->node->name);
+               scf_logd("\033[34m post hook: %s\033[0m\n", h->node->name);
                h = h->next;
        }
 
        h = dfa->hooks[SCF_DFA_HOOK_END];
        while (h) {
-               scf_logd("\033[32m end hook: %s\033[0m\n", h->node->name);
+               scf_logd("\033[36m end hook: %s\033[0m\n", h->node->name);
                h = h->next;
        }
        printf("\n");
@@ -339,14 +339,14 @@ static int _scf_dfa_node_parse_word(scf_dfa_t* dfa, scf_dfa_node_t* node, scf_ve
                scf_dfa_clear_hooks(&(dfa->hooks[SCF_DFA_HOOK_POST]), hook->next);
                hook = NULL;
 
-               scf_logi("\033[32m post hook: %s->action()\033[0m\n", hook_node->name);
+               scf_logi("\033[36m post hook: %s->action()\033[0m\n", hook_node->name);
 
                if (hook_node != node && hook_node->action) {
 
                        ret = hook_node->action(dfa, words, data);
 
                        if (SCF_DFA_SWITCH_TO == ret) {
-                               scf_logi("\033[31m post hook: switch to %s->%s\033[0m\n", node->name, hook_node->name);
+                               scf_logi("\033[36m post hook: switch to %s->%s\033[0m\n", node->name, hook_node->name);
 
                                node = hook_node;
                                ret = SCF_DFA_NEXT_WORD;
@@ -366,7 +366,7 @@ static int _scf_dfa_node_parse_word(scf_dfa_t* dfa, scf_dfa_node_t* node, scf_ve
                        free(hook);
                        hook = NULL;
 
-                       scf_logi("\033[32m end hook: %s->action()\033[0m\n", hook_node->name);
+                       scf_logi("\033[34m end hook: %s->action()\033[0m\n", hook_node->name);
 
                        if (!hook_node->action)
                                continue;
@@ -377,7 +377,7 @@ static int _scf_dfa_node_parse_word(scf_dfa_t* dfa, scf_dfa_node_t* node, scf_ve
                                continue;
 
                        if (SCF_DFA_SWITCH_TO == ret) {
-                               scf_logi("\033[31m end hook: switch to %s->%s\033[0m\n\n", node->name, hook_node->name);
+                               scf_logi("\033[34m end hook: switch to %s->%s\033[0m\n\n", node->name, hook_node->name);
 
                                node = hook_node;
                                ret  = SCF_DFA_NEXT_WORD;
index 703a02622c0bf8136a334eacb6fdfb39a257ed8f..d6a826da7d6376d118725ae926cde1060d443a82 100644 (file)
@@ -14,7 +14,7 @@ static int _async_is_async(scf_dfa_t* dfa, void* word)
 static int _async_action_async(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = data;
+       dfa_data_t*       d     = data;
        scf_lex_word_t*   w     = words->data[words->size - 1];
 
        if (d->expr) {
@@ -33,8 +33,8 @@ static int _async_action_async(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _async_action_semicolon(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = data;
+       scf_parse_t*  parse = dfa->priv;
+       dfa_data_t*   d     = data;
 
        if (!d->expr) {
                scf_loge("\n");
@@ -122,7 +122,6 @@ static int _dfa_init_syntax_async(scf_dfa_t* dfa)
        scf_dfa_node_add_child(async, expr);
        scf_dfa_node_add_child(expr,  semicolon);
 
-       scf_logi("\n");
        return 0;
 }
 
@@ -132,4 +131,3 @@ scf_dfa_module_t dfa_module_async =
        .init_module = _dfa_init_module_async,
        .init_syntax = _dfa_init_syntax_async,
 };
-
index 2ed9bc18bece8529250a107346d07509c5514654..50b6432909119288c8769e66ce7a1613b1c66741 100644 (file)
@@ -19,7 +19,7 @@ typedef struct {
 static int _block_action_entry(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*      parse     = dfa->priv;
-       dfa_parse_data_t* d         = data;
+       dfa_data_t* d         = data;
        scf_stack_t*      s         = d->module_datas[dfa_module_block.index];
        dfa_block_data_t* bd        = scf_stack_top(s);
 
@@ -34,10 +34,9 @@ static int _block_action_entry(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
                scf_stack_push(s, bd);
 
-               scf_logi("\033[31m new bd: %p, s->size: %d\033[0m\n", bd, s->size);
-       } else {
-               scf_logi("\033[31m new bd: %p, s->size: %d\033[0m\n", bd, s->size);
-       }
+               scf_logi("new bd: %p, s->size: %d\n", bd, s->size);
+       } else
+               scf_logi("new bd: %p, s->size: %d\n", bd, s->size);
 
        return words->size > 0 ? SCF_DFA_CONTINUE : SCF_DFA_NEXT_WORD;
 }
@@ -45,12 +44,12 @@ static int _block_action_entry(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 static int _block_action_end(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*      parse     = dfa->priv;
-       dfa_parse_data_t* d         = data;
+       dfa_data_t* d         = data;
        scf_stack_t*      s         = d->module_datas[dfa_module_block.index];
        dfa_block_data_t* bd        = scf_stack_top(s);
 
        if (bd->nb_rbs < bd->nb_lbs) {
-               scf_logi("\033[31m end bd: %p, bd->nb_lbs: %d, bd->nb_rbs: %d, s->size: %d\033[0m\n",
+               scf_logi("end bd: %p, bd->nb_lbs: %d, bd->nb_rbs: %d, s->size: %d\n",
                                bd, bd->nb_lbs, bd->nb_rbs, s->size);
 
                SCF_DFA_PUSH_HOOK(scf_dfa_find_node(dfa, "block_end"), SCF_DFA_HOOK_END);
@@ -64,7 +63,7 @@ static int _block_action_end(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
        scf_stack_pop(s);
 
-       scf_logi("\033[31m end bd: %p, bd->nb_lbs: %d, bd->nb_rbs: %d, s->size: %d\033[0m\n",
+       scf_logi("end bd: %p, bd->nb_lbs: %d, bd->nb_rbs: %d, s->size: %d\n",
                        bd, bd->nb_lbs, bd->nb_rbs, s->size);
 
        free(bd);
@@ -76,7 +75,7 @@ static int _block_action_end(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 static int _block_action_lb(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = data;
+       dfa_data_t* d     = data;
        scf_lex_word_t*   w     = words->data[words->size - 1];
        scf_stack_t*      s     = d->module_datas[dfa_module_block.index];
 
@@ -102,7 +101,7 @@ static int _block_action_lb(scf_dfa_t* dfa, scf_vector_t* words, void* data)
        bd->nb_lbs++;
        scf_stack_push(s, bd);
 
-       scf_logi("\033[31m new bd: %p, s->size: %d\033[0m\n", bd, s->size);
+       scf_logi("new bd: %p, s->size: %d\n", bd, s->size);
 
        return SCF_DFA_NEXT_WORD;
 }
@@ -110,14 +109,14 @@ static int _block_action_lb(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 static int _block_action_rb(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = data;
+       dfa_data_t* d     = data;
        scf_lex_word_t*   w     = words->data[words->size - 1];
        scf_stack_t*      s     = d->module_datas[dfa_module_block.index];
        dfa_block_data_t* bd    = scf_stack_top(s);
 
        bd->nb_rbs++;
 
-       scf_logi("\033[31m bd: %p, bd->nb_lbs: %d, bd->nb_rbs: %d, s->size: %d\033[0m\n",
+       scf_logi("bd: %p, bd->nb_lbs: %d, bd->nb_rbs: %d, s->size: %d\n",
                        bd, bd->nb_lbs, bd->nb_rbs, s->size);
 
        assert(bd->nb_lbs == bd->nb_rbs);
@@ -143,6 +142,8 @@ static int _dfa_init_module_block(scf_dfa_t* dfa)
        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);
@@ -171,6 +172,8 @@ static int _dfa_init_module_block(scf_dfa_t* dfa)
        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);
@@ -188,7 +191,7 @@ static int _dfa_init_module_block(scf_dfa_t* dfa)
 
 
        scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = parse->dfa_data;
+       dfa_data_t* d     = parse->dfa_data;
        scf_stack_t*      s     = d->module_datas[dfa_module_block.index];
 
        assert(!s);
@@ -206,7 +209,7 @@ static int _dfa_init_module_block(scf_dfa_t* dfa)
 static int _dfa_fini_module_block(scf_dfa_t* dfa)
 {
        scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = parse->dfa_data;
+       dfa_data_t* d     = parse->dfa_data;
        scf_stack_t*      s     = d->module_datas[dfa_module_block.index];
 
        if (s) {
index 8ad7970cda4bfa52db9211f42eaabb5bda614c6c..1bab3933adbb372ed9e77a5b20da90d54213ec0b 100644 (file)
@@ -13,9 +13,9 @@ static int _break_is_break(scf_dfa_t* dfa, void* word)
 
 static int _break_action_break(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*      parse  = dfa->priv;
-       dfa_parse_data_t* d      = data;
-       scf_lex_word_t*   w      = words->data[words->size - 1];
+       scf_parse_t*     parse  = dfa->priv;
+       dfa_data_t*      d      = data;
+       scf_lex_word_t*  w      = words->data[words->size - 1];
 
        scf_node_t*       _break = scf_node_alloc(w, SCF_OP_BREAK, NULL);
        if (!_break) {
@@ -50,8 +50,6 @@ static int _dfa_init_syntax_break(scf_dfa_t* dfa)
        SCF_DFA_GET_MODULE_NODE(dfa, break,   _break,       _break);
 
        scf_dfa_node_add_child(_break, semicolon);
-
-       printf("%s(),%d\n\n", __func__, __LINE__);
        return 0;
 }
 
@@ -61,4 +59,3 @@ scf_dfa_module_t dfa_module_break =
        .init_module = _dfa_init_module_break,
        .init_syntax = _dfa_init_syntax_break,
 };
-
index d3565796958be11c229d93fa8071bf8f4b464b5d..ad27a5df2cc3648e5b71db31f26ef9f7bb7f4dd8 100644 (file)
@@ -20,9 +20,9 @@ typedef struct {
 
 static int _call_action_lp_stat(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       dfa_parse_data_t*  d     = data;
-       scf_stack_t*       s     = d->module_datas[dfa_module_call.index];
-       dfa_call_data_t*   cd    = scf_stack_top(s);
+       dfa_data_t*       d  = data;
+       scf_stack_t*      s  = d->module_datas[dfa_module_call.index];
+       dfa_call_data_t*  cd = scf_stack_top(s);
 
        if (!cd) {
                scf_loge("\n");
@@ -39,19 +39,19 @@ static int _call_action_lp_stat(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _call_action_lp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*       parse     = dfa->priv;
-       dfa_parse_data_t*  d         = data;
-       scf_lex_word_t*    w1        = words->data[words->size - 1];
-       scf_stack_t*       s         = d->module_datas[dfa_module_call.index];
-       scf_function_t*    f         = NULL;
-       dfa_call_data_t*   cd        = NULL;
+       scf_parse_t*      parse     = dfa->priv;
+       dfa_data_t*       d         = data;
+       scf_lex_word_t*   w1        = words->data[words->size - 1];
+       scf_stack_t*      s         = d->module_datas[dfa_module_call.index];
+       scf_function_t*   f         = NULL;
+       dfa_call_data_t*  cd        = NULL;
 
-       scf_variable_t*    var_pf    = NULL;
-       scf_node_t*        node_pf   = NULL;
-       scf_type_t*        pt        = NULL;
+       scf_variable_t*   var_pf    = NULL;
+       scf_node_t*       node_pf   = NULL;
+       scf_type_t*       pt        = NULL;
 
-       scf_node_t*        node_call = NULL;
-       scf_operator_t*    op        = scf_find_base_operator_by_type(SCF_OP_CALL);
+       scf_node_t*       node_call = NULL;
+       scf_operator_t*   op        = scf_find_base_operator_by_type(SCF_OP_CALL);
 
        if (scf_ast_find_type_type(&pt, parse->ast, SCF_FUNCTION_PTR) < 0)
                return SCF_DFA_ERROR;
@@ -146,12 +146,12 @@ static int _call_action_rp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
                return SCF_DFA_ERROR;
        }
 
-       scf_parse_t*       parse = dfa->priv;
-       dfa_parse_data_t*  d     = data;
-       scf_lex_word_t*    w     = words->data[words->size - 1];
-       scf_stack_t*       s     = d->module_datas[dfa_module_call.index];
+       scf_parse_t*      parse = dfa->priv;
+       dfa_data_t*       d     = data;
+       scf_lex_word_t*   w     = words->data[words->size - 1];
+       scf_stack_t*      s     = d->module_datas[dfa_module_call.index];
+       dfa_call_data_t*  cd    = scf_stack_top(s);
 
-       dfa_call_data_t*   cd    = scf_stack_top(s);
        if (!cd) {
                scf_loge("\n");
                return SCF_DFA_ERROR;
@@ -219,7 +219,7 @@ static int _call_action_comma(scf_dfa_t* dfa, scf_vector_t* words, void* data)
        }
 
        scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = data;
+       dfa_data_t*       d     = data;
        scf_lex_word_t*   w     = words->data[words->size - 1];
        scf_stack_t*      s     = d->module_datas[dfa_module_call.index];
 
@@ -255,9 +255,9 @@ static int _dfa_init_module_call(scf_dfa_t* dfa)
 
        SCF_DFA_MODULE_NODE(dfa, call, comma,    scf_dfa_is_comma, _call_action_comma);
 
-       scf_parse_t*       parse = dfa->priv;
-       dfa_parse_data_t*  d     = parse->dfa_data;
-       scf_stack_t*       s     = d->module_datas[dfa_module_call.index];
+       scf_parse_t*  parse = dfa->priv;
+       dfa_data_t*   d     = parse->dfa_data;
+       scf_stack_t*  s     = d->module_datas[dfa_module_call.index];
 
        assert(!s);
 
@@ -274,9 +274,9 @@ static int _dfa_init_module_call(scf_dfa_t* dfa)
 
 static int _dfa_fini_module_call(scf_dfa_t* dfa)
 {
-       scf_parse_t*       parse = dfa->priv;
-       dfa_parse_data_t*  d     = parse->dfa_data;
-       scf_stack_t*       s     = d->module_datas[dfa_module_call.index];
+       scf_parse_t*  parse = dfa->priv;
+       dfa_data_t*   d     = parse->dfa_data;
+       scf_stack_t*  s     = d->module_datas[dfa_module_call.index];
 
        if (s) {
                scf_stack_free(s);
@@ -289,15 +289,15 @@ static int _dfa_fini_module_call(scf_dfa_t* dfa)
 
 static int _dfa_init_syntax_call(scf_dfa_t* dfa)
 {
-       SCF_DFA_GET_MODULE_NODE(dfa, call, lp,              lp);
-       SCF_DFA_GET_MODULE_NODE(dfa, call, rp,              rp);
-       SCF_DFA_GET_MODULE_NODE(dfa, call, comma,           comma);
+       SCF_DFA_GET_MODULE_NODE(dfa, call,   lp,       lp);
+       SCF_DFA_GET_MODULE_NODE(dfa, call,   rp,       rp);
+       SCF_DFA_GET_MODULE_NODE(dfa, call,   comma,    comma);
 
-       SCF_DFA_GET_MODULE_NODE(dfa, expr, entry,           expr);
+       SCF_DFA_GET_MODULE_NODE(dfa, expr,   entry,    expr);
 
-       SCF_DFA_GET_MODULE_NODE(dfa, create,    create,   create);
-       SCF_DFA_GET_MODULE_NODE(dfa, create,    identity, create_id);
-       SCF_DFA_GET_MODULE_NODE(dfa, create,    rp,       create_rp);
+       SCF_DFA_GET_MODULE_NODE(dfa, create, create,   create);
+       SCF_DFA_GET_MODULE_NODE(dfa, create, identity, create_id);
+       SCF_DFA_GET_MODULE_NODE(dfa, create, rp,       create_rp);
 
        // no args
        scf_dfa_node_add_child(lp,       rp);
@@ -317,7 +317,6 @@ static int _dfa_init_syntax_call(scf_dfa_t* dfa)
        scf_dfa_node_add_child(comma,    expr);
        scf_dfa_node_add_child(expr,     rp);
 
-       scf_logi("\n");
        return 0;
 }
 
@@ -329,4 +328,3 @@ scf_dfa_module_t dfa_module_call =
 
        .fini_module = _dfa_fini_module_call,
 };
-
index 21b0f07f6779441e4e54326e80a1d27968f764ac..9531048bb220c4f710b109c138e06200a6e0ba5b 100644 (file)
@@ -27,7 +27,7 @@ static int _class_is_class(scf_dfa_t* dfa, void* word)
 static int _class_action_identity(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*          parse = dfa->priv;
-       dfa_parse_data_t*     d     = data;
+       dfa_data_t*           d     = data;
        class_module_data_t*  md    = d->module_datas[dfa_module_class.index];
        scf_lex_word_t*       w     = words->data[words->size - 1];
 
@@ -54,7 +54,7 @@ static int _class_action_identity(scf_dfa_t* dfa, scf_vector_t* words, void* dat
        md->parent_block     = parse->ast->current_block;
        SCF_DFA_PUSH_HOOK(scf_dfa_find_node(dfa, "class_end"), SCF_DFA_HOOK_END);
 
-       printf("\033[31m%s(), %d, t: %p, t->type: %d\033[0m\n", __func__, __LINE__, t, t->type);
+       scf_logi("\033[31m t: %p, t->type: %d\033[0m\n", t, t->type);
 
        return SCF_DFA_NEXT_WORD;
 }
@@ -62,7 +62,7 @@ static int _class_action_identity(scf_dfa_t* dfa, scf_vector_t* words, void* dat
 static int _class_action_lb(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*          parse = dfa->priv;
-       dfa_parse_data_t*     d     = data;
+       dfa_data_t*           d     = data;
        class_module_data_t*  md    = d->module_datas[dfa_module_class.index];
        scf_lex_word_t*       w     = words->data[words->size - 1];
 
@@ -122,8 +122,7 @@ static int _class_calculate_size(scf_dfa_t* dfa, scf_type_t* s)
 
                        for (j = 0; j < v->nb_dimentions; j++) {
                                if (v->dimentions[j] < 0) {
-
-                                       printf("%s(), %d, error: v: '%s'\n", __func__, __LINE__, v->w->text->data);
+                                       scf_loge("v: '%s'\n", v->w->text->data);
                                        return SCF_DFA_ERROR;
                                }
 
@@ -136,20 +135,20 @@ static int _class_calculate_size(scf_dfa_t* dfa, scf_type_t* s)
                        size = v->offset + v->size;
                }
 
-               printf("%s(), %d, class '%s', member: '%s', offset: %d, size: %d, v->dim: %d, v->capacity: %d\n", __func__, __LINE__,
+               scf_logi("class '%s', member: '%s', offset: %d, size: %d, v->dim: %d, v->capacity: %d\n",
                                s->name->data, v->w->text->data, v->offset, v->size, v->nb_dimentions, v->capacity);
        }
        s->size = size;
        s->node.define_flag = 1;
 
-       printf("%s(), %d, class '%s', size: %d\n", __func__, __LINE__, s->name->data, s->size);
+       scf_logi("class '%s', size: %d\n", s->name->data, s->size);
        return 0;
 }
 
 static int _class_action_rb(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*          parse = dfa->priv;
-       dfa_parse_data_t*     d     = data;
+       dfa_data_t*           d     = data;
        class_module_data_t*  md    = d->module_datas[dfa_module_class.index];
 
        if (_class_calculate_size(dfa, md->current_class) < 0) {
@@ -170,7 +169,7 @@ static int _class_action_semicolon(scf_dfa_t* dfa, scf_vector_t* words, void* da
 static int _class_action_end(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*          parse = dfa->priv;
-       dfa_parse_data_t*     d     = data;
+       dfa_data_t*           d     = data;
        class_module_data_t*  md    = d->module_datas[dfa_module_class.index];
 
        if (md->nb_rbs == md->nb_lbs) {
@@ -204,16 +203,14 @@ static int _dfa_init_module_class(scf_dfa_t* dfa)
        SCF_DFA_MODULE_NODE(dfa, class, end,       scf_dfa_is_entry,     _class_action_end);
 
        scf_parse_t*          parse = dfa->priv;
-       dfa_parse_data_t*     d     = parse->dfa_data;
+       dfa_data_t*           d     = parse->dfa_data;
        class_module_data_t*  md    = d->module_datas[dfa_module_class.index];
 
        assert(!md);
 
        md = calloc(1, sizeof(class_module_data_t));
-       if (!md) {
-               printf("%s(),%d, error: \n", __func__, __LINE__);
+       if (!md)
                return SCF_DFA_ERROR;
-       }
 
        d->module_datas[dfa_module_class.index] = md;
 
@@ -223,7 +220,7 @@ static int _dfa_init_module_class(scf_dfa_t* dfa)
 static int _dfa_fini_module_class(scf_dfa_t* dfa)
 {
        scf_parse_t*          parse = dfa->priv;
-       dfa_parse_data_t*     d     = parse->dfa_data;
+       dfa_data_t*           d     = parse->dfa_data;
        class_module_data_t*  md    = d->module_datas[dfa_module_class.index];
 
        if (md) {
@@ -266,7 +263,6 @@ static int _dfa_init_syntax_class(scf_dfa_t* dfa)
        scf_dfa_node_add_child(end,       member);
        scf_dfa_node_add_child(end,       rb);
 
-       printf("%s(),%d\n\n", __func__, __LINE__);
        return 0;
 }
 
@@ -278,4 +274,3 @@ scf_dfa_module_t dfa_module_class =
 
        .fini_module = _dfa_fini_module_class,
 };
-
index d7583fbd4a7902d6a0c6f8ac83c77f9d81144e29..5a2ac2b7ba69a21f245488acc5fb2409fc28062b 100644 (file)
@@ -18,7 +18,7 @@ typedef struct {
 
 static int _container_action_lp_stat(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       dfa_parse_data_t*     d  = data;
+       dfa_data_t*           d  = data;
        scf_stack_t*          s  = d->module_datas[dfa_module_container.index];
        dfa_container_data_t* cd = scf_stack_top(s);
 
@@ -37,7 +37,7 @@ static int _container_action_lp_stat(scf_dfa_t* dfa, scf_vector_t* words, void*
 static int _container_action_container(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*          parse = dfa->priv;
-       dfa_parse_data_t*     d     = data;
+       dfa_data_t*           d     = data;
        scf_lex_word_t*       w     = words->data[words->size - 1];
        scf_stack_t*          s     = d->module_datas[dfa_module_container.index];
 
@@ -78,7 +78,7 @@ static int _container_action_lp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 static int _container_action_comma(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*          parse = dfa->priv;
-       dfa_parse_data_t*     d     = data;
+       dfa_data_t*           d     = data;
        scf_lex_word_t*       w     = words->data[words->size - 1];
        scf_stack_t*          s     = d->module_datas[dfa_module_container.index];
        dfa_container_data_t* cd    = scf_stack_top(s);
@@ -161,7 +161,7 @@ static int _container_action_comma(scf_dfa_t* dfa, scf_vector_t* words, void* da
 static int _container_action_rp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*          parse = dfa->priv;
-       dfa_parse_data_t*     d     = data;
+       dfa_data_t*           d     = data;
        scf_lex_word_t*       w     = words->data[words->size - 1];
        scf_stack_t*          s     = d->module_datas[dfa_module_container.index];
        dfa_container_data_t* cd    = scf_stack_top(s);
@@ -245,9 +245,9 @@ static int _dfa_init_module_container(scf_dfa_t* dfa)
        SCF_DFA_MODULE_NODE(dfa, container, lp_stat,   scf_dfa_is_lp,        _container_action_lp_stat);
        SCF_DFA_MODULE_NODE(dfa, container, comma,     scf_dfa_is_comma,     _container_action_comma);
 
-       scf_parse_t*       parse = dfa->priv;
-       dfa_parse_data_t*  d     = parse->dfa_data;
-       scf_stack_t*       s     = d->module_datas[dfa_module_container.index];
+       scf_parse_t*  parse = dfa->priv;
+       dfa_data_t*   d     = parse->dfa_data;
+       scf_stack_t*  s     = d->module_datas[dfa_module_container.index];
 
        assert(!s);
 
@@ -264,9 +264,9 @@ static int _dfa_init_module_container(scf_dfa_t* dfa)
 
 static int _dfa_fini_module_container(scf_dfa_t* dfa)
 {
-       scf_parse_t*       parse = dfa->priv;
-       dfa_parse_data_t*  d     = parse->dfa_data;
-       scf_stack_t*       s     = d->module_datas[dfa_module_container.index];
+       scf_parse_t*  parse = dfa->priv;
+       dfa_data_t*   d     = parse->dfa_data;
+       scf_stack_t*  s     = d->module_datas[dfa_module_container.index];
 
        if (s) {
                scf_stack_free(s);
@@ -301,7 +301,6 @@ static int _dfa_init_syntax_container(scf_dfa_t* dfa)
        scf_dfa_node_add_child(comma,     identity);
        scf_dfa_node_add_child(identity,  rp);
 
-       scf_logi("\n");
        return 0;
 }
 
index 1a87c00d11a2edf2a95f07f8b1f6dd322ac1a02d..28c47b9463031e549ab34515ab47b86348a1afda 100644 (file)
@@ -13,9 +13,9 @@ static int _continue_is_continue(scf_dfa_t* dfa, void* word)
 
 static int _continue_action_continue(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*      parse  = dfa->priv;
-       dfa_parse_data_t* d      = data;
-       scf_lex_word_t*   w      = words->data[words->size - 1];
+       scf_parse_t*     parse  = dfa->priv;
+       dfa_data_t*      d      = data;
+       scf_lex_word_t*  w      = words->data[words->size - 1];
 
        scf_node_t*       _continue = scf_node_alloc(w, SCF_OP_CONTINUE, NULL);
        if (!_continue) {
@@ -50,8 +50,6 @@ static int _dfa_init_syntax_continue(scf_dfa_t* dfa)
        SCF_DFA_GET_MODULE_NODE(dfa, continue,   _continue, _continue);
 
        scf_dfa_node_add_child(_continue, semicolon);
-
-       scf_logi("\n");
        return 0;
 }
 
@@ -61,4 +59,3 @@ scf_dfa_module_t dfa_module_continue =
        .init_module = _dfa_init_module_continue,
        .init_syntax = _dfa_init_syntax_continue,
 };
-
index cf71e8a63438386c51349e8b88296f89f08a61f8..6496de4fa280c0f86f3aa112bc5b991f95547aaa 100644 (file)
@@ -18,16 +18,16 @@ typedef struct {
 
 static int _create_is_create(scf_dfa_t* dfa, void* word)
 {
-       scf_lex_word_t* w     = word;
+       scf_lex_word_t* w = word;
 
        return SCF_LEX_WORD_KEY_CREATE == w->type;
 }
 
 static int _create_action_lp_stat(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       dfa_parse_data_t*     d     = data;
-       scf_stack_t*          s     = d->module_datas[dfa_module_create.index];
-       create_module_data_t* md    = d->module_datas[dfa_module_create.index];
+       dfa_data_t*           d  = data;
+       scf_stack_t*          s  = d->module_datas[dfa_module_create.index];
+       create_module_data_t* md = d->module_datas[dfa_module_create.index];
 
        md->nb_lps++;
 
@@ -39,7 +39,7 @@ static int _create_action_lp_stat(scf_dfa_t* dfa, scf_vector_t* words, void* dat
 static int _create_action_create(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*          parse = dfa->priv;
-       dfa_parse_data_t*     d     = data;
+       dfa_data_t*           d     = data;
        scf_lex_word_t*       w     = words->data[words->size - 1];
        create_module_data_t* md    = d->module_datas[dfa_module_create.index];
 
@@ -59,7 +59,7 @@ static int _create_action_create(scf_dfa_t* dfa, scf_vector_t* words, void* data
 static int _create_action_identity(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*          parse = dfa->priv;
-       dfa_parse_data_t*     d     = data;
+       dfa_data_t*           d     = data;
        scf_lex_word_t*       w     = words->data[words->size - 1];
        create_module_data_t* md    = d->module_datas[dfa_module_create.index];
 
@@ -107,7 +107,7 @@ static int _create_action_identity(scf_dfa_t* dfa, scf_vector_t* words, void* da
 static int _create_action_lp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*          parse = dfa->priv;
-       dfa_parse_data_t*     d     = data;
+       dfa_data_t*           d     = data;
        scf_lex_word_t*       w     = words->data[words->size - 1];
        create_module_data_t* md    = d->module_datas[dfa_module_create.index];
 
@@ -126,7 +126,7 @@ static int _create_action_lp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 static int _create_action_rp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*          parse = dfa->priv;
-       dfa_parse_data_t*     d     = data;
+       dfa_data_t*           d     = data;
        scf_lex_word_t*       w     = words->data[words->size - 1];
        create_module_data_t* md    = d->module_datas[dfa_module_create.index];
 
@@ -169,7 +169,7 @@ static int _create_action_rp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 static int _create_action_comma(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*          parse = dfa->priv;
-       dfa_parse_data_t*     d     = data;
+       dfa_data_t*           d     = data;
        scf_lex_word_t*       w     = words->data[words->size - 1];
        create_module_data_t* md    = d->module_datas[dfa_module_create.index];
 
@@ -199,7 +199,7 @@ static int _dfa_init_module_create(scf_dfa_t* dfa)
        SCF_DFA_MODULE_NODE(dfa, create, comma,     scf_dfa_is_comma,     _create_action_comma);
 
        scf_parse_t*       parse = dfa->priv;
-       dfa_parse_data_t*  d     = parse->dfa_data;
+       dfa_data_t*  d     = parse->dfa_data;
        create_module_data_t* md    = d->module_datas[dfa_module_create.index];
 
        assert(!md);
@@ -217,8 +217,8 @@ static int _dfa_init_module_create(scf_dfa_t* dfa)
 
 static int _dfa_fini_module_create(scf_dfa_t* dfa)
 {
-       scf_parse_t*       parse = dfa->priv;
-       dfa_parse_data_t*  d     = parse->dfa_data;
+       scf_parse_t*          parse = dfa->priv;
+       dfa_data_t*           d     = parse->dfa_data;
        create_module_data_t* md    = d->module_datas[dfa_module_create.index];
 
        if (md) {
@@ -250,7 +250,6 @@ static int _dfa_init_syntax_create(scf_dfa_t* dfa)
        scf_dfa_node_add_child(comma,    expr);
        scf_dfa_node_add_child(expr,     rp);
 
-       scf_logi("\n");
        return 0;
 }
 
index 13d3e92b1ac694beb21f0a7b6002d19842770fd6..172c9d92871b2b5ede82b9946e174ed60ecec380 100644 (file)
@@ -19,13 +19,13 @@ typedef struct {
 
 static int _do_action_do(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = data;
-       scf_lex_word_t*   w     = words->data[words->size - 1];
-       scf_stack_t*      s     = d->module_datas[dfa_module_do.index];
-       scf_block_t*      b     = NULL;
+       scf_parse_t*     parse = dfa->priv;
+       dfa_data_t*      d     = data;
+       scf_lex_word_t*  w     = words->data[words->size - 1];
+       scf_stack_t*     s     = d->module_datas[dfa_module_do.index];
+       scf_block_t*     b     = NULL;
+       scf_node_t*     _do    = scf_node_alloc(w, SCF_OP_DO, NULL);
 
-       scf_node_t* _do = scf_node_alloc(w, SCF_OP_DO, NULL);
        if (!_do) {
                scf_loge("node alloc failed\n");
                return SCF_DFA_ERROR;
@@ -66,8 +66,8 @@ static int _do_action_while(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _do_action_lp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*       parse = dfa->priv;
-       dfa_parse_data_t*  d     = data;
+       scf_parse_t*  parse = dfa->priv;
+       dfa_data_t*   d     = data;
 
        assert(!d->expr);
        d->expr_local_flag = 1;
@@ -80,9 +80,9 @@ static int _do_action_lp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _do_action_lp_stat(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       dfa_parse_data_t*  d  = data;
-       scf_stack_t*       s  = d->module_datas[dfa_module_do.index];
-       dfa_do_data_t*     dd = scf_stack_top(s);
+       dfa_data_t*     d  = data;
+       scf_stack_t*    s  = d->module_datas[dfa_module_do.index];
+       dfa_do_data_t*  dd = scf_stack_top(s);
 
        SCF_DFA_PUSH_HOOK(scf_dfa_find_node(dfa, "do_lp_stat"), SCF_DFA_HOOK_POST);
 
@@ -93,11 +93,11 @@ static int _do_action_lp_stat(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _do_action_rp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*       parse = dfa->priv;
-       dfa_parse_data_t*  d     = data;
-       scf_lex_word_t*    w     = words->data[words->size - 1];
-       scf_stack_t*       s     = d->module_datas[dfa_module_do.index];
-       dfa_do_data_t*     dd    = scf_stack_top(s);
+       scf_parse_t*     parse = dfa->priv;
+       dfa_data_t*      d     = data;
+       scf_lex_word_t*  w     = words->data[words->size - 1];
+       scf_stack_t*     s     = d->module_datas[dfa_module_do.index];
+       dfa_do_data_t*   dd    = scf_stack_top(s);
 
        if (!d->expr) {
                scf_loge("\n");
@@ -126,10 +126,10 @@ static int _do_action_rp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _do_action_semicolon(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*       parse = dfa->priv;
-       dfa_parse_data_t*  d     = data;
-       scf_stack_t*       s     = d->module_datas[dfa_module_do.index];
-       dfa_do_data_t*     dd    = scf_stack_pop(s);
+       scf_parse_t*    parse = dfa->priv;
+       dfa_data_t*     d     = data;
+       scf_stack_t*    s     = d->module_datas[dfa_module_do.index];
+       dfa_do_data_t*  dd    = scf_stack_pop(s);
 
        assert(parse->ast->current_block == dd->parent_block);
 
@@ -156,9 +156,9 @@ static int _dfa_init_module_do(scf_dfa_t* dfa)
        SCF_DFA_MODULE_NODE(dfa, do, _do,       scf_dfa_is_do,        _do_action_do);
        SCF_DFA_MODULE_NODE(dfa, do, _while,    scf_dfa_is_while,     _do_action_while);
 
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = parse->dfa_data;
-       scf_stack_t*      s     = d->module_datas[dfa_module_do.index];
+       scf_parse_t*  parse = dfa->priv;
+       dfa_data_t*   d     = parse->dfa_data;
+       scf_stack_t*  s     = d->module_datas[dfa_module_do.index];
 
        assert(!s);
 
@@ -175,9 +175,9 @@ static int _dfa_init_module_do(scf_dfa_t* dfa)
 
 static int _dfa_fini_module_do(scf_dfa_t* dfa)
 {
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = parse->dfa_data;
-       scf_stack_t*      s     = d->module_datas[dfa_module_do.index];
+       scf_parse_t*  parse = dfa->priv;
+       dfa_data_t*   d     = parse->dfa_data;
+       scf_stack_t*  s     = d->module_datas[dfa_module_do.index];
 
        if (s) {
                scf_stack_free(s);
@@ -211,7 +211,6 @@ static int _dfa_init_syntax_do(scf_dfa_t* dfa)
        scf_dfa_node_add_child(expr,     rp);
        scf_dfa_node_add_child(rp,       semicolon);
 
-       scf_logi("\n");
        return 0;
 }
 
index a8fd9f8cf9f0ee751c1027dde78c48e27459df16..7ab4727bac85ce4164328483c1c37da2326dffe6 100644 (file)
@@ -20,7 +20,7 @@ typedef struct {
 static int _enum_action_type(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*         parse = dfa->priv;
-       dfa_parse_data_t*    d     = data;
+       dfa_data_t*          d     = data;
        enum_module_data_t*  md    = d->module_datas[dfa_module_enum.index];
        scf_lex_word_t*      w     = words->data[words->size - 1];
 
@@ -50,7 +50,7 @@ static int _enum_action_type(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 static int _enum_action_lb(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*         parse = dfa->priv;
-       dfa_parse_data_t*    d     = data;
+       dfa_data_t*          d     = data;
        enum_module_data_t*  md    = d->module_datas[dfa_module_enum.index];
        scf_lex_word_t*      w     = words->data[words->size - 1];
        scf_type_t*          t     = NULL;
@@ -89,7 +89,7 @@ static int _enum_action_lb(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 static int _enum_action_var(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*         parse = dfa->priv;
-       dfa_parse_data_t*    d     = data;
+       dfa_data_t*          d     = data;
        enum_module_data_t*  md    = d->module_datas[dfa_module_enum.index];
        scf_lex_word_t*      w     = words->data[words->size - 1];
 
@@ -144,7 +144,7 @@ static int _enum_action_var(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 static int _enum_action_assign(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*         parse = dfa->priv;
-       dfa_parse_data_t*    d     = data;
+       dfa_data_t*          d     = data;
        enum_module_data_t*  md    = d->module_datas[dfa_module_enum.index];
        scf_lex_word_t*      w     = words->data[words->size - 1];
 
@@ -164,7 +164,7 @@ static int _enum_action_assign(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 static int _enum_action_comma(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*         parse = dfa->priv;
-       dfa_parse_data_t*    d     = data;
+       dfa_data_t*          d     = data;
        enum_module_data_t*  md    = d->module_datas[dfa_module_enum.index];
        scf_lex_word_t*      w     = words->data[words->size - 1];
        scf_variable_t*      r     = NULL;
@@ -200,8 +200,8 @@ static int _enum_action_comma(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _enum_action_rb(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*          parse = dfa->priv;
-       dfa_parse_data_t*     d     = data;
+       scf_parse_t*         parse = dfa->priv;
+       dfa_data_t*          d     = data;
        enum_module_data_t*  md    = d->module_datas[dfa_module_enum.index];
        scf_lex_word_t*      w     = words->data[words->size - 1];
        scf_variable_t*      r     = NULL;
@@ -253,7 +253,7 @@ static int _enum_action_rb(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 static int _enum_action_semicolon(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*         parse = dfa->priv;
-       dfa_parse_data_t*    d     = data;
+       dfa_data_t*          d     = data;
        enum_module_data_t*  md    = d->module_datas[dfa_module_enum.index];
        scf_lex_word_t*      w     = words->data[words->size - 1];
 
@@ -293,7 +293,7 @@ static int _dfa_init_module_enum(scf_dfa_t* dfa)
        SCF_DFA_MODULE_NODE(dfa, enum, comma,     scf_dfa_is_comma,     _enum_action_comma);
 
        scf_parse_t*         parse = dfa->priv;
-       dfa_parse_data_t*    d     = parse->dfa_data;
+       dfa_data_t*          d     = parse->dfa_data;
        enum_module_data_t*  md    = d->module_datas[dfa_module_enum.index];
 
        assert(!md);
@@ -318,8 +318,8 @@ static int _dfa_init_module_enum(scf_dfa_t* dfa)
 
 static int _dfa_fini_module_enum(scf_dfa_t* dfa)
 {
-       scf_parse_t*          parse = dfa->priv;
-       dfa_parse_data_t*     d     = parse->dfa_data;
+       scf_parse_t*         parse = dfa->priv;
+       dfa_data_t*          d     = parse->dfa_data;
        enum_module_data_t*  md    = d->module_datas[dfa_module_enum.index];
 
        if (md) {
@@ -371,7 +371,6 @@ static int _dfa_init_syntax_enum(scf_dfa_t* dfa)
        // end
        scf_dfa_node_add_child(rb,      semicolon);
 
-       scf_logi("\n");
        return 0;
 }
 
index 412bd0773a71288d203ba17918dec52af9019b5e..6bfff2e2b46a7231a7c1863e0afd522582ea7c21 100644 (file)
@@ -18,8 +18,7 @@ int _type_find_type(scf_dfa_t* dfa, dfa_identity_t* id);
 
 static int _expr_is_expr(scf_dfa_t* dfa, void* word)
 {
-       scf_parse_t*    parse = dfa->priv;
-       scf_lex_word_t* w     = word;
+       scf_lex_word_t* w = word;
 
        if (SCF_LEX_WORD_SEMICOLON == w->type
                        || scf_lex_is_operator(w)
@@ -31,15 +30,14 @@ static int _expr_is_expr(scf_dfa_t* dfa, void* word)
 
 static int _expr_is_number(scf_dfa_t* dfa, void* word)
 {
-       scf_lex_word_t* w     = word;
+       scf_lex_word_t* w = word;
 
        return scf_lex_is_const(w);
 }
 
 static int _expr_is_unary_op(scf_dfa_t* dfa, void* word)
 {
-       scf_parse_t*    parse = dfa->priv;
-       scf_lex_word_t* w     = word;
+       scf_lex_word_t* w = word;
 
        if (SCF_LEX_WORD_LS == w->type
                        || SCF_LEX_WORD_RS == w->type
@@ -64,8 +62,7 @@ static int _expr_is_unary_post(scf_dfa_t* dfa, void* word)
 
 static int _expr_is_binary_op(scf_dfa_t* dfa, void* word)
 {
-       scf_parse_t*    parse = dfa->priv;
-       scf_lex_word_t* w     = word;
+       scf_lex_word_t* w = word;
 
        if (SCF_LEX_WORD_LS == w->type
                        || SCF_LEX_WORD_RS == w->type
@@ -79,7 +76,7 @@ static int _expr_is_binary_op(scf_dfa_t* dfa, void* word)
        return 0;
 }
 
-int _expr_add_var(scf_parse_t* parse, dfa_parse_data_t* d)
+int _expr_add_var(scf_parse_t* parse, dfa_data_t* d)
 {
        expr_module_data_t* md   = d->module_datas[dfa_module_expr.index];
        scf_variable_t*     var  = NULL;
@@ -155,8 +152,8 @@ int _expr_add_var(scf_parse_t* parse, dfa_parse_data_t* d)
 
 static int _expr_action_expr(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = data;
+       scf_parse_t*  parse = dfa->priv;
+       dfa_data_t*   d     = data;
 
        if (!d->expr) {
                d->expr = scf_expr_alloc();
@@ -173,9 +170,9 @@ static int _expr_action_expr(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _expr_action_number(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = data;
-       scf_lex_word_t*   w     = words->data[words->size - 1];
+       scf_parse_t*     parse = dfa->priv;
+       dfa_data_t*      d     = data;
+       scf_lex_word_t*  w     = words->data[words->size - 1];
 
        scf_logd("w: %s\n", w->text->data);
 
@@ -279,12 +276,12 @@ static int _expr_action_number(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _expr_action_op(scf_dfa_t* dfa, scf_vector_t* words, void* data, int nb_operands)
 {
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = data;
-       scf_lex_word_t*   w     = words->data[words->size - 1];
+       scf_parse_t*     parse = dfa->priv;
+       dfa_data_t*      d     = data;
+       scf_lex_word_t*  w     = words->data[words->size - 1];
 
-       scf_operator_t*   op;
-       scf_node_t*       node;
+       scf_operator_t*  op;
+       scf_node_t*      node;
 
        op = scf_find_base_operator(w->text->data, nb_operands);
        if (!op) {
@@ -317,20 +314,18 @@ static int _expr_action_binary_op(scf_dfa_t* dfa, scf_vector_t* words, void* dat
        scf_logd("\n");
 
        scf_parse_t*        parse = dfa->priv;
-       dfa_parse_data_t*   d     = data;
+       dfa_data_t*         d     = data;
        scf_lex_word_t*     w     = words->data[words->size - 1];
        expr_module_data_t* md    = d->module_datas[dfa_module_expr.index];
-
        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) {
 
-                       scf_variable_t* var = scf_block_find_variable(parse->ast->current_block,
-                                       id->identity->text->data);
-
-                       if (!var) {
+                       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) {
@@ -366,7 +361,7 @@ static int _expr_action_binary_op(scf_dfa_t* dfa, scf_vector_t* words, void* dat
 static int _expr_action_lp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*        parse = dfa->priv;
-       dfa_parse_data_t*   d     = data;
+       dfa_data_t*         d     = data;
        expr_module_data_t* md    = d->module_datas[dfa_module_expr.index];
 
        scf_expr_t* e = scf_expr_alloc();
@@ -391,9 +386,8 @@ static int _expr_action_lp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 static int _expr_action_rp_cast(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*        parse = dfa->priv;
-       dfa_parse_data_t*   d     = data;
+       dfa_data_t*         d     = data;
        expr_module_data_t* md    = d->module_datas[dfa_module_expr.index];
-
        dfa_identity_t*     id    = scf_stack_top(d->current_identities);
 
        if (!id) {
@@ -480,11 +474,10 @@ static int _expr_action_rp_cast(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _expr_action_rp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*        parse = dfa->priv;
-       dfa_parse_data_t*   d     = data;
-       expr_module_data_t* md    = d->module_datas[dfa_module_expr.index];
-
-       dfa_identity_t*     id    = scf_stack_top(d->current_identities);
+       scf_parse_t*         parse = dfa->priv;
+       dfa_data_t*          d     = data;
+       expr_module_data_t*  md    = d->module_datas[dfa_module_expr.index];
+       dfa_identity_t*      id    = scf_stack_top(d->current_identities);
 
        if (id && id->identity) {
 
@@ -531,12 +524,11 @@ static int _expr_action_rp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _expr_action_unary_post(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];
-       dfa_parse_data_t* d     = data;
-       scf_node_t*       n     = NULL;
-
-       dfa_identity_t*   id    = scf_stack_top(d->current_identities);
+       scf_parse_t*     parse = dfa->priv;
+       scf_lex_word_t*  w     = words->data[words->size - 1];
+       dfa_data_t*      d     = data;
+       scf_node_t*      n     = NULL;
+       dfa_identity_t*  id    = scf_stack_top(d->current_identities);
 
        if (id && id->identity) {
                if (_expr_add_var(parse, d) < 0) {
@@ -569,11 +561,11 @@ static int _expr_action_unary_post(scf_dfa_t* dfa, scf_vector_t* words, void* da
 
 static int _expr_action_ls(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];
-       dfa_parse_data_t*   d     = data;
-       expr_module_data_t* md    = d->module_datas[dfa_module_expr.index];
-       dfa_identity_t*     id    = scf_stack_top(d->current_identities);
+       scf_parse_t*         parse = dfa->priv;
+       scf_lex_word_t*      w     = words->data[words->size - 1];
+       dfa_data_t*          d     = data;
+       expr_module_data_t*  md    = d->module_datas[dfa_module_expr.index];
+       dfa_identity_t*      id    = scf_stack_top(d->current_identities);
 
        if (id && id->identity) {
                if (_expr_add_var(parse, d) < 0) {
@@ -614,11 +606,10 @@ static int _expr_action_ls(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _expr_action_rs(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*        parse = dfa->priv;
-       dfa_parse_data_t*   d     = data;
-       expr_module_data_t* md    = d->module_datas[dfa_module_expr.index];
-
-       dfa_identity_t*     id    = scf_stack_top(d->current_identities);
+       scf_parse_t*         parse = dfa->priv;
+       dfa_data_t*          d     = data;
+       expr_module_data_t*  md    = d->module_datas[dfa_module_expr.index];
+       dfa_identity_t*      id    = scf_stack_top(d->current_identities);
 
        if (id && id->identity) {
                if (_expr_add_var(parse, d) < 0) {
@@ -739,10 +730,9 @@ int _expr_multi_rets(scf_expr_t* e)
        return 0;
 }
 
-static int _expr_fini_expr(scf_parse_t* parse, dfa_parse_data_t* d, int semi_flag)
+static int _expr_fini_expr(scf_parse_t* parse, dfa_data_t* d, int semi_flag)
 {
        expr_module_data_t* md = d->module_datas[dfa_module_expr.index];
-
        dfa_identity_t*     id = scf_stack_top(d->current_identities);
 
        if (id && id->identity) {
@@ -796,8 +786,8 @@ static int _expr_fini_expr(scf_parse_t* parse, dfa_parse_data_t* d, int semi_fla
 
 static int _expr_action_comma(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*        parse = dfa->priv;
-       dfa_parse_data_t*   d     = data;
+       scf_parse_t*  parse = dfa->priv;
+       dfa_data_t*   d     = data;
 
        if (_expr_fini_expr(parse, d, 0) < 0)
                return SCF_DFA_ERROR;
@@ -807,9 +797,9 @@ static int _expr_action_comma(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _expr_action_semicolon(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*        parse = dfa->priv;
-       dfa_parse_data_t*   d     = data;
-       expr_module_data_t* md    = d->module_datas[dfa_module_expr.index];
+       scf_parse_t*         parse = dfa->priv;
+       dfa_data_t*          d     = data;
+       expr_module_data_t*  md    = d->module_datas[dfa_module_expr.index];
 
        if (_expr_fini_expr(parse, d, 1) < 0)
                return SCF_DFA_ERROR;
@@ -835,9 +825,9 @@ static int _dfa_init_module_expr(scf_dfa_t* dfa)
        SCF_DFA_MODULE_NODE(dfa, expr, comma,      scf_dfa_is_comma,     _expr_action_comma);
        SCF_DFA_MODULE_NODE(dfa, expr, semicolon,  scf_dfa_is_semicolon, _expr_action_semicolon);
 
-       scf_parse_t*        parse = dfa->priv;
-       dfa_parse_data_t*   d     = parse->dfa_data;
-       expr_module_data_t* md    = d->module_datas[dfa_module_expr.index];
+       scf_parse_t*         parse = dfa->priv;
+       dfa_data_t*          d     = parse->dfa_data;
+       expr_module_data_t*  md    = d->module_datas[dfa_module_expr.index];
 
        assert(!md);
 
@@ -871,9 +861,9 @@ _ls_exprs:
 
 static int _dfa_fini_module_expr(scf_dfa_t* dfa)
 {
-       scf_parse_t*        parse = dfa->priv;
-       dfa_parse_data_t*   d     = parse->dfa_data;
-       expr_module_data_t* md    = d->module_datas[dfa_module_expr.index];
+       scf_parse_t*         parse = dfa->priv;
+       dfa_data_t*          d     = parse->dfa_data;
+       expr_module_data_t*  md    = d->module_datas[dfa_module_expr.index];
 
        if (md) {
                if (md->ls_exprs)
@@ -1047,7 +1037,6 @@ static int _dfa_init_syntax_expr(scf_dfa_t* dfa)
        scf_dfa_node_add_child(identity,   semicolon);
        scf_dfa_node_add_child(rs,         semicolon);
 
-       scf_logi("\n\n");
        return 0;
 }
 
index 3970233e4f0765688a37ff9a7538ac36daca222f..0258ced94318d85efedf10132aade6f605ad8a2b 100644 (file)
@@ -29,12 +29,12 @@ static int _for_is_end(scf_dfa_t* dfa, void* word)
 
 static int _for_action_for(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = data;
-       scf_lex_word_t*   w     = words->data[words->size - 1];
-       scf_stack_t*      s     = d->module_datas[dfa_module_for.index];
+       scf_parse_t*     parse = dfa->priv;
+       dfa_data_t*      d     = data;
+       scf_lex_word_t*  w     = words->data[words->size - 1];
+       scf_stack_t*     s     = d->module_datas[dfa_module_for.index];
+       scf_node_t*      _for  = scf_node_alloc(w, SCF_OP_FOR, NULL);
 
-       scf_node_t*       _for  = scf_node_alloc(w, SCF_OP_FOR, NULL);
        if (!_for) {
                scf_loge("node alloc failed\n");
                return SCF_DFA_ERROR;
@@ -66,7 +66,7 @@ static int _for_action_for(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 static int _for_action_lp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = data;
+       dfa_data_t*       d     = data;
        scf_lex_word_t*   w     = words->data[words->size - 1];
        scf_stack_t*      s     = d->module_datas[dfa_module_for.index];
        dfa_for_data_t*   fd    = scf_stack_top(s);
@@ -84,9 +84,9 @@ static int _for_action_lp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _for_action_lp_stat(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       dfa_parse_data_t* d  = data;
-       scf_stack_t*      s  = d->module_datas[dfa_module_for.index];
-       dfa_for_data_t*   fd = scf_stack_top(s);
+       dfa_data_t*      d  = data;
+       scf_stack_t*     s  = d->module_datas[dfa_module_for.index];
+       dfa_for_data_t*  fd = scf_stack_top(s);
 
        SCF_DFA_PUSH_HOOK(scf_dfa_find_node(dfa, "for_lp_stat"), SCF_DFA_HOOK_POST);
 
@@ -97,11 +97,11 @@ static int _for_action_lp_stat(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _for_action_comma(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = data;
-       scf_lex_word_t*   w     = words->data[words->size - 1];
-       scf_stack_t*      s     = d->module_datas[dfa_module_for.index];
-       dfa_for_data_t*   fd    = scf_stack_top(s);
+       scf_parse_t*     parse = dfa->priv;
+       dfa_data_t*      d     = data;
+       scf_lex_word_t*  w     = words->data[words->size - 1];
+       scf_stack_t*     s     = d->module_datas[dfa_module_for.index];
+       dfa_for_data_t*  fd    = scf_stack_top(s);
 
        if (!d->expr) {
                scf_loge("need expr before ','\n");
@@ -138,17 +138,16 @@ static int _for_action_comma(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _for_action_semicolon(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       printf("%s(),%d\n", __func__, __LINE__);
        if (!data) {
-               printf("%s(), %d, error: \n", __func__, __LINE__);
+               scf_loge("\n");
                return SCF_DFA_ERROR;
        }
 
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = data;
-       scf_lex_word_t*   w     = words->data[words->size - 1];
-       scf_stack_t*      s     = d->module_datas[dfa_module_for.index];
-       dfa_for_data_t*   fd    = scf_stack_top(s);
+       scf_parse_t*     parse = dfa->priv;
+       dfa_data_t*      d     = data;
+       scf_lex_word_t*  w     = words->data[words->size - 1];
+       scf_stack_t*     s     = d->module_datas[dfa_module_for.index];
+       dfa_for_data_t*  fd    = scf_stack_top(s);
 
        if (0 == fd->nb_semicolons) {
                if (d->expr) {
@@ -230,11 +229,11 @@ static int _for_add_exprs(dfa_for_data_t* fd)
 
 static int _for_action_rp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = data;
-       scf_lex_word_t*   w     = words->data[words->size - 1];
-       scf_stack_t*      s     = d->module_datas[dfa_module_for.index];
-       dfa_for_data_t*  fd     = scf_stack_top(s);
+       scf_parse_t*     parse = dfa->priv;
+       dfa_data_t*      d     = data;
+       scf_lex_word_t*  w     = words->data[words->size - 1];
+       scf_stack_t*     s     = d->module_datas[dfa_module_for.index];
+       dfa_for_data_t*  fd    = scf_stack_top(s);
 
        fd->nb_rps++;
 
@@ -269,12 +268,10 @@ static int _for_action_rp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _for_action_end(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*      parse     = dfa->priv;
-       dfa_parse_data_t* d         = data;
-       scf_stack_t*      s         = d->module_datas[dfa_module_for.index];
-       dfa_for_data_t*  fd         = scf_stack_pop(s);
-
-       scf_loge("current_block: %p, parent_block: %p\n", parse->ast->current_block, fd->parent_block);
+       scf_parse_t*     parse = dfa->priv;
+       dfa_data_t*      d     = data;
+       scf_stack_t*     s     = d->module_datas[dfa_module_for.index];
+       dfa_for_data_t*  fd    = scf_stack_pop(s);
 
        if (3 == fd->_for->nb_nodes)
                scf_node_add_child(fd->_for, NULL);
@@ -305,9 +302,9 @@ static int _dfa_init_module_for(scf_dfa_t* dfa)
 
        SCF_DFA_MODULE_NODE(dfa, for, _for,      scf_dfa_is_for,        _for_action_for);
 
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = parse->dfa_data;
-       scf_stack_t*      s     = d->module_datas[dfa_module_for.index];
+       scf_parse_t*  parse = dfa->priv;
+       dfa_data_t*   d     = parse->dfa_data;
+       scf_stack_t*  s     = d->module_datas[dfa_module_for.index];
 
        assert(!s);
 
@@ -324,9 +321,9 @@ static int _dfa_init_module_for(scf_dfa_t* dfa)
 
 static int _dfa_fini_module_for(scf_dfa_t* dfa)
 {
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = parse->dfa_data;
-       scf_stack_t*      s     = d->module_datas[dfa_module_for.index];
+       scf_parse_t*  parse = dfa->priv;
+       dfa_data_t*   d     = parse->dfa_data;
+       scf_stack_t*  s     = d->module_datas[dfa_module_for.index];
 
        if (s) {
                scf_stack_free(s);
@@ -367,7 +364,6 @@ static int _dfa_init_syntax_for(scf_dfa_t* dfa)
        // for body block
        scf_dfa_node_add_child(rp,     block);
 
-       scf_logi("\n");
        return 0;
 }
 
@@ -380,4 +376,3 @@ scf_dfa_module_t dfa_module_for =
 
        .fini_module = _dfa_fini_module_for,
 };
-
index 30ffda1e99b49c481b4b2511a8c95debcd48520e..9bbe184b0aa7c313d0c4aa850aacdc81b9cf986b 100644 (file)
@@ -10,7 +10,7 @@ typedef struct {
 
 } dfa_fun_data_t;
 
-int _function_add_function(scf_dfa_t* dfa, dfa_parse_data_t* d)
+int _function_add_function(scf_dfa_t* dfa, dfa_data_t* d)
 {
        if (d->current_identities->size < 2) {
                scf_loge("d->current_identities->size: %d\n", d->current_identities->size);
@@ -119,7 +119,7 @@ int _function_add_function(scf_dfa_t* dfa, dfa_parse_data_t* d)
        return SCF_DFA_NEXT_WORD;
 }
 
-int _function_add_arg(scf_dfa_t* dfa, dfa_parse_data_t* d)
+int _function_add_arg(scf_dfa_t* dfa, dfa_data_t* d)
 {
        dfa_identity_t* t = NULL;
        dfa_identity_t* v = NULL;
@@ -200,7 +200,7 @@ int _function_add_arg(scf_dfa_t* dfa, dfa_parse_data_t* d)
 
 static int _function_action_vargs(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       dfa_parse_data_t* d = data;
+       dfa_data_t* d = data;
 
        d->current_function->vargs_flag = 1;
 
@@ -209,7 +209,7 @@ static int _function_action_vargs(scf_dfa_t* dfa, scf_vector_t* words, void* dat
 
 static int _function_action_comma(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       dfa_parse_data_t* d   = data;
+       dfa_data_t* d = data;
 
        if (_function_add_arg(dfa, d) < 0) {
                scf_loge("function add arg failed\n");
@@ -223,9 +223,9 @@ static int _function_action_comma(scf_dfa_t* dfa, scf_vector_t* words, void* dat
 
 static int _function_action_lp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = data;
-       dfa_fun_data_t*   fd    = d->module_datas[dfa_module_function.index];
+       scf_parse_t*     parse = dfa->priv;
+       dfa_data_t*      d     = data;
+       dfa_fun_data_t*  fd    = d->module_datas[dfa_module_function.index];
 
        assert(!d->current_node);
 
@@ -245,11 +245,11 @@ static int _function_action_lp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _function_action_rp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = data;
-       dfa_fun_data_t*   fd    = d->module_datas[dfa_module_function.index];
-       scf_function_t*   f     = d->current_function;
-       scf_function_t*   fprev = NULL;
+       scf_parse_t*     parse = dfa->priv;
+       dfa_data_t*      d     = data;
+       dfa_fun_data_t*  fd    = d->module_datas[dfa_module_function.index];
+       scf_function_t*  f     = d->current_function;
+       scf_function_t*  fprev = NULL;
 
        d->nb_rps++;
 
@@ -366,12 +366,12 @@ static int _function_action_rp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _function_action_end(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = data;
-       scf_lex_word_t*   w     = words->data[words->size - 1];
-       dfa_fun_data_t*   fd    = d->module_datas[dfa_module_function.index];
+       scf_parse_t*     parse = dfa->priv;
+       dfa_data_t*      d     = data;
+       scf_lex_word_t*  w     = words->data[words->size - 1];
+       dfa_fun_data_t*  fd    = d->module_datas[dfa_module_function.index];
 
-       parse->ast->current_block  = (scf_block_t*)(fd->parent_block);
+       parse->ast->current_block = (scf_block_t*)(fd->parent_block);
 
        if (d->current_function->node.nb_nodes > 0)
                d->current_function->node.define_flag = 1;
@@ -395,9 +395,9 @@ static int _dfa_init_module_function(scf_dfa_t* dfa)
        SCF_DFA_MODULE_NODE(dfa, function, lp,     scf_dfa_is_lp,    _function_action_lp);
        SCF_DFA_MODULE_NODE(dfa, function, rp,     scf_dfa_is_rp,    _function_action_rp);
 
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = parse->dfa_data;
-       dfa_fun_data_t*   fd    = d->module_datas[dfa_module_function.index];
+       scf_parse_t*     parse = dfa->priv;
+       dfa_data_t*      d     = parse->dfa_data;
+       dfa_fun_data_t*  fd    = d->module_datas[dfa_module_function.index];
 
        assert(!fd);
 
@@ -414,9 +414,9 @@ static int _dfa_init_module_function(scf_dfa_t* dfa)
 
 static int _dfa_fini_module_function(scf_dfa_t* dfa)
 {
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = parse->dfa_data;
-       dfa_fun_data_t*   fd    = d->module_datas[dfa_module_function.index];
+       scf_parse_t*     parse = dfa->priv;
+       dfa_data_t*      d     = parse->dfa_data;
+       dfa_fun_data_t*  fd    = d->module_datas[dfa_module_function.index];
 
        if (fd) {
                free(fd);
@@ -471,7 +471,6 @@ static int _dfa_init_syntax_function(scf_dfa_t* dfa)
        // function body
        scf_dfa_node_add_child(rp,        block);
 
-       scf_logi("\n");
        return 0;
 }
 
index 176b067b547b510422d6e9c46349c6d7cac80b10..b3ea503d033040e30bfb5c99946e0e99d62319f7 100644 (file)
@@ -7,7 +7,7 @@ extern scf_dfa_module_t dfa_module_goto;
 static int _goto_action_goto(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*      parse  = dfa->priv;
-       dfa_parse_data_t* d      = data;
+       dfa_data_t*       d      = data;
        scf_lex_word_t*   w      = words->data[words->size - 1];
 
        scf_node_t*       _goto  = scf_node_alloc(w, SCF_OP_GOTO, NULL);
@@ -29,7 +29,7 @@ static int _goto_action_goto(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 static int _goto_action_identity(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*      parse  = dfa->priv;
-       dfa_parse_data_t* d      = data;
+       dfa_data_t*       d      = data;
        scf_lex_word_t*   w      = words->data[words->size - 1];
 
        scf_label_t*      l      = scf_label_alloc(w);
@@ -42,7 +42,7 @@ static int _goto_action_identity(scf_dfa_t* dfa, scf_vector_t* words, void* data
 
 static int _goto_action_semicolon(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       dfa_parse_data_t* d     = data;
+       dfa_data_t* d = data;
 
        d->current_goto = NULL;
 
@@ -67,7 +67,6 @@ static int _dfa_init_syntax_goto(scf_dfa_t* dfa)
        scf_dfa_node_add_child(_goto,    identity);
        scf_dfa_node_add_child(identity, semicolon);
 
-       scf_logi("\n");
        return 0;
 }
 
@@ -77,4 +76,3 @@ scf_dfa_module_t dfa_module_goto =
        .init_module = _dfa_init_module_goto,
        .init_syntax = _dfa_init_syntax_goto,
 };
-
index 5861ae9117200d1cc4455fe886129dd182551734..01d08bf2341852d9c60d51b93da4bcff32efdecc 100644 (file)
@@ -6,9 +6,9 @@ extern scf_dfa_module_t dfa_module_identity;
 
 static int _identity_action_identity(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_lex_word_t*   w = words->data[words->size - 1];
-       dfa_parse_data_t* d = data;
-       scf_stack_t*      s = d->current_identities;
+       scf_lex_word_t*  w = words->data[words->size - 1];
+       dfa_data_t*      d = data;
+       scf_stack_t*     s = d->current_identities;
 
        scf_logd("w: '%s'\n", w->text->data);
 
@@ -37,8 +37,6 @@ static int _dfa_init_module_identity(scf_dfa_t* dfa)
 
 static int _dfa_init_syntax_identity(scf_dfa_t* dfa)
 {
-       scf_logi("\n");
-
        SCF_DFA_GET_MODULE_NODE(dfa, identity, identity,  identity);
 
        scf_vector_add(dfa->syntaxes, identity);
index dc50c611f7d5e934d63c61a6fd76c10d3f40d383..cd2f75b3d6ce16904e86980d4204ec41b6e1e629 100644 (file)
@@ -29,13 +29,13 @@ static int _if_is_end(scf_dfa_t* dfa, void* word)
 
 static int _if_action_if(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = data;
-       scf_lex_word_t*   w     = words->data[words->size - 1];
-       scf_stack_t*      s     = d->module_datas[dfa_module_if.index];
-       dfa_if_data_t*    ifd   = scf_stack_top(s);
+       scf_parse_t*     parse = dfa->priv;
+       dfa_data_t*      d     = data;
+       scf_lex_word_t*  w     = words->data[words->size - 1];
+       scf_stack_t*     s     = d->module_datas[dfa_module_if.index];
+       dfa_if_data_t*   ifd   = scf_stack_top(s);
+       scf_node_t*     _if    = scf_node_alloc(w, SCF_OP_IF, NULL);
 
-       scf_node_t*       _if   = scf_node_alloc(w, SCF_OP_IF, NULL);
        if (!_if) {
                scf_loge("\n");
                return SCF_DFA_ERROR;
@@ -68,11 +68,11 @@ static int _if_action_if(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _if_action_else(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = data;
-       scf_lex_word_t*   w     = words->data[words->size - 1];
-       scf_stack_t*      s     = d->module_datas[dfa_module_if.index];
-       dfa_if_data_t*    ifd   = scf_stack_top(s);
+       scf_parse_t*     parse = dfa->priv;
+       dfa_data_t*      d     = data;
+       scf_lex_word_t*  w     = words->data[words->size - 1];
+       scf_stack_t*     s     = d->module_datas[dfa_module_if.index];
+       dfa_if_data_t*   ifd   = scf_stack_top(s);
 
        if (!ifd) {
                scf_loge("no 'if' before 'else' in line: %d\n", w->line);
@@ -97,9 +97,9 @@ static int _if_action_else(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _if_action_lp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       dfa_parse_data_t* d     = data;
-       scf_stack_t*      s     = d->module_datas[dfa_module_if.index];
-       dfa_if_data_t*    ifd   = scf_stack_top(s);
+       dfa_data_t*     d   = data;
+       scf_stack_t*    s   = d->module_datas[dfa_module_if.index];
+       dfa_if_data_t*  ifd = scf_stack_top(s);
 
        if (d->expr) {
                scf_expr_free(d->expr);
@@ -117,9 +117,9 @@ static int _if_action_lp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _if_action_lp_stat(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       dfa_parse_data_t* d     = data;
-       scf_stack_t*      s     = d->module_datas[dfa_module_if.index];
-       dfa_if_data_t*    ifd   = scf_stack_top(s);
+       dfa_data_t*     d   = data;
+       scf_stack_t*    s   = d->module_datas[dfa_module_if.index];
+       dfa_if_data_t*  ifd = scf_stack_top(s);
 
        ifd->nb_lps++;
 
@@ -130,9 +130,9 @@ static int _if_action_lp_stat(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _if_action_rp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       dfa_parse_data_t* d     = data;
-       scf_stack_t*      s     = d->module_datas[dfa_module_if.index];
-       dfa_if_data_t*    ifd   = scf_stack_top(s);
+       dfa_data_t*     d   = data;
+       scf_stack_t*    s   = d->module_datas[dfa_module_if.index];
+       dfa_if_data_t*  ifd = scf_stack_top(s);
 
        if (!d->expr) {
                scf_loge("\n");
@@ -172,11 +172,11 @@ static int _is_end(scf_dfa_t* dfa)
 
 static int _if_action_end(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*      parse     = dfa->priv;
-       dfa_parse_data_t* d         = data;
-       scf_stack_t*      s         = d->module_datas[dfa_module_if.index];
-       dfa_if_data_t*    ifd       = scf_stack_top(s);
-       scf_lex_word_t*   prev_else = ifd->prev_else;
+       scf_parse_t*     parse     = dfa->priv;
+       dfa_data_t*      d         = data;
+       scf_stack_t*     s         = d->module_datas[dfa_module_if.index];
+       dfa_if_data_t*   ifd       = scf_stack_top(s);
+       scf_lex_word_t*  prev_else = ifd->prev_else;
 
        if (!_is_end(dfa)) {
 
@@ -216,9 +216,9 @@ static int _dfa_init_module_if(scf_dfa_t* dfa)
        SCF_DFA_MODULE_NODE(dfa, if, _if,       scf_dfa_is_if,    _if_action_if);
        SCF_DFA_MODULE_NODE(dfa, if, _else,     scf_dfa_is_else,  _if_action_else);
 
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = parse->dfa_data;
-       scf_stack_t*      s     = d->module_datas[dfa_module_if.index];
+       scf_parse_t*  parse = dfa->priv;
+       dfa_data_t*   d     = parse->dfa_data;
+       scf_stack_t*  s     = d->module_datas[dfa_module_if.index];
 
        assert(!s);
 
@@ -235,9 +235,9 @@ static int _dfa_init_module_if(scf_dfa_t* dfa)
 
 static int _dfa_fini_module_if(scf_dfa_t* dfa)
 {
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = parse->dfa_data;
-       scf_stack_t*      s     = d->module_datas[dfa_module_if.index];
+       scf_parse_t*  parse = dfa->priv;
+       dfa_data_t*   d     = parse->dfa_data;
+       scf_stack_t*  s     = d->module_datas[dfa_module_if.index];
 
        if (s) {
                scf_stack_free(s);
@@ -278,7 +278,6 @@ static int _dfa_init_syntax_if(scf_dfa_t* dfa)
        // last else block
        scf_dfa_node_add_child(_else,  block);
 
-       scf_logi("\n");
        return 0;
 }
 
@@ -291,4 +290,3 @@ scf_dfa_module_t dfa_module_if =
 
        .fini_module = _dfa_fini_module_if,
 };
-
index 20e5fe8e83c2afe57df8e030407afb475ee575cd..141bf429bdded8a714e5cc8bd85d8607493e081d 100644 (file)
@@ -6,9 +6,9 @@ extern scf_dfa_module_t dfa_module_include;
 
 static int _include_action_include(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*      parse  = dfa->priv;
-       dfa_parse_data_t* d      = data;
-       scf_lex_word_t*   w      = words->data[words->size - 1];
+       scf_parse_t*     parse  = dfa->priv;
+       dfa_data_t*      d      = data;
+       scf_lex_word_t*  w      = words->data[words->size - 1];
 
        scf_loge("include '%s', line %d\n", w->text->data, w->line);
        return SCF_DFA_NEXT_WORD;
@@ -16,11 +16,11 @@ static int _include_action_include(scf_dfa_t* dfa, scf_vector_t* words, void* da
 
 static int _include_action_path(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*      parse  = dfa->priv;
-       dfa_parse_data_t* d      = data;
-       scf_lex_word_t*   w      = words->data[words->size - 1];
-       scf_lex_t*        lex    = parse->lex;
-       scf_block_t*      cur    = parse->ast->current_block;
+       scf_parse_t*     parse  = dfa->priv;
+       dfa_data_t*      d      = data;
+       scf_lex_word_t*  w      = words->data[words->size - 1];
+       scf_lex_t*       lex    = parse->lex;
+       scf_block_t*     cur    = parse->ast->current_block;
 
        assert(w->data.s);
        scf_loge("include '%s', line %d\n", w->data.s->data, w->line);
@@ -34,8 +34,25 @@ static int _include_action_path(scf_dfa_t* dfa, scf_vector_t* words, void* data)
                return SCF_DFA_ERROR;
        }
 
-       if (parse->lex)
-               scf_lex_close(parse->lex);
+       if (parse->lex != lex && parse->lex->macros) { // copy macros
+
+               if (!lex->macros) {
+                       lex->macros = scf_vector_clone(parse->lex->macros);
+                       if (!lex->macros)
+                               return -ENOMEM;
+               } else {
+                       ret = scf_vector_cat(lex->macros, parse->lex->macros);
+                       if (ret < 0)
+                               return ret;
+               }
+
+               scf_macro_t* m;
+               int i;
+               for (i = 0; i < parse->lex->macros->size; i++) {
+                       m  =        parse->lex->macros->data[i];
+                       m->refs++;
+               }
+       }
 
        parse->lex = lex;
        parse->ast->current_block = cur;
@@ -43,7 +60,7 @@ static int _include_action_path(scf_dfa_t* dfa, scf_vector_t* words, void* data)
        return SCF_DFA_NEXT_WORD;
 }
 
-static int _include_action_semicolon(scf_dfa_t* dfa, scf_vector_t* words, void* data)
+static int _include_action_LF(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        return SCF_DFA_OK;
 }
@@ -52,23 +69,23 @@ static int _dfa_init_module_include(scf_dfa_t* dfa)
 {
        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, semicolon, scf_dfa_is_semicolon,    _include_action_semicolon);
+       SCF_DFA_MODULE_NODE(dfa, include, LF,        scf_dfa_is_LF,           _include_action_LF);
 
        return SCF_DFA_OK;
 }
 
 static int _dfa_init_syntax_include(scf_dfa_t* dfa)
 {
-       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,   semicolon, semicolon);
+       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_vector_add(dfa->syntaxes,    include);
+       SCF_DFA_GET_MODULE_NODE(dfa, macro,   hash,    hash);
 
+       scf_dfa_node_add_child(hash,     include);
        scf_dfa_node_add_child(include,  path);
-       scf_dfa_node_add_child(path,     semicolon);
+       scf_dfa_node_add_child(path,     LF);
 
-       scf_logi("\n");
        return 0;
 }
 
@@ -78,4 +95,3 @@ scf_dfa_module_t dfa_module_include =
        .init_module = _dfa_init_module_include,
        .init_syntax = _dfa_init_syntax_include,
 };
-
index 62fc35a8bbbe963f2cc608acef69567a20a42b0b..d9fce44653b84f3fca9a62f373b1f40d58fa2229 100644 (file)
@@ -2,12 +2,12 @@
 #include"scf_dfa_util.h"
 #include"scf_parse.h"
 
-extern scf_dfa_module_t dfa_module_init_data;
+extern scf_dfa_module_t  dfa_module_init_data;
 
-int scf_array_init(scf_ast_t* ast, scf_lex_word_t* w, scf_variable_t* var, scf_vector_t* init_exprs);
+int scf_array_init (scf_ast_t* ast, scf_lex_word_t* w, scf_variable_t* var, scf_vector_t* init_exprs);
 int scf_struct_init(scf_ast_t* ast, scf_lex_word_t* w, scf_variable_t* var, scf_vector_t* init_exprs);
 
-int _expr_add_var(scf_parse_t* parse, dfa_parse_data_t* d);
+int _expr_add_var(scf_parse_t* parse, dfa_data_t* d);
 
 typedef struct {
        int              nb_lbs;
@@ -15,7 +15,7 @@ typedef struct {
 
 } data_module_data_t;
 
-static int _do_data_init(scf_dfa_t* dfa, scf_vector_t* words, dfa_parse_data_t* d)
+static int _do_data_init(scf_dfa_t* dfa, scf_vector_t* words, dfa_data_t* d)
 {
        scf_parse_t*        parse = dfa->priv;
        scf_variable_t*     var   = d->current_var;
@@ -89,7 +89,7 @@ error:
        return ret;
 }
 
-static int _add_data_init_expr(scf_dfa_t* dfa, scf_vector_t* words, dfa_parse_data_t* d)
+static int _add_data_init_expr(scf_dfa_t* dfa, scf_vector_t* words, dfa_data_t* d)
 {
        assert(!d->expr->parent);
        assert(d->current_dim >= 0);
@@ -113,7 +113,7 @@ static int _add_data_init_expr(scf_dfa_t* dfa, scf_vector_t* words, dfa_parse_da
 static int _data_action_comma(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*        parse = dfa->priv;
-       dfa_parse_data_t*   d     = data;
+       dfa_data_t*         d     = data;
        data_module_data_t* md    = d->module_datas[dfa_module_init_data.index];
 
        if (d->current_dim < 0) {
@@ -145,7 +145,7 @@ static int _data_action_lb(scf_dfa_t* dfa, scf_vector_t* words, void* data)
        }
 
        scf_parse_t*        parse = dfa->priv;
-       dfa_parse_data_t*   d     = data;
+       dfa_data_t*         d     = data;
        scf_lex_word_t*     w     = words->data[words->size - 2];
        data_module_data_t* md    = d->module_datas[dfa_module_init_data.index]; 
 
@@ -183,7 +183,7 @@ static int _data_action_lb(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 static int _data_action_rb(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*        parse = dfa->priv;
-       dfa_parse_data_t*   d     = data;
+       dfa_data_t*         d     = data;
        data_module_data_t* md    = d->module_datas[dfa_module_init_data.index]; 
 
        if (d->expr) {
@@ -224,12 +224,11 @@ static int _data_action_rb(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 static int _dfa_init_module_init_data(scf_dfa_t* dfa)
 {
        SCF_DFA_MODULE_NODE(dfa, init_data, comma, scf_dfa_is_comma, _data_action_comma);
-
        SCF_DFA_MODULE_NODE(dfa, init_data, lb,    scf_dfa_is_lb,    _data_action_lb);
        SCF_DFA_MODULE_NODE(dfa, init_data, rb,    scf_dfa_is_rb,    _data_action_rb);
 
        scf_parse_t*        parse = dfa->priv;
-       dfa_parse_data_t*   d     = parse->dfa_data;
+       dfa_data_t*         d     = parse->dfa_data;
        data_module_data_t* md    = d->module_datas[dfa_module_init_data.index];
 
        assert(!md);
@@ -247,12 +246,10 @@ static int _dfa_init_module_init_data(scf_dfa_t* dfa)
 
 static int _dfa_init_syntax_init_data(scf_dfa_t* dfa)
 {
-       SCF_DFA_GET_MODULE_NODE(dfa, init_data, comma,     comma);
-
-       SCF_DFA_GET_MODULE_NODE(dfa, init_data, lb,        lb);
-       SCF_DFA_GET_MODULE_NODE(dfa, init_data, rb,        rb);
-
-       SCF_DFA_GET_MODULE_NODE(dfa, expr, entry,     expr);
+       SCF_DFA_GET_MODULE_NODE(dfa, init_data, comma, comma);
+       SCF_DFA_GET_MODULE_NODE(dfa, init_data, lb,    lb);
+       SCF_DFA_GET_MODULE_NODE(dfa, init_data, rb,    rb);
+       SCF_DFA_GET_MODULE_NODE(dfa, expr,      entry, expr);
 
        // empty init, use 0 to fill the data
        scf_dfa_node_add_child(lb,        rb);
@@ -269,7 +266,6 @@ static int _dfa_init_syntax_init_data(scf_dfa_t* dfa)
        scf_dfa_node_add_child(comma,     expr);
        scf_dfa_node_add_child(expr,      rb);
 
-       scf_logi("\n");
        return 0;
 }
 
index 22f50c64031d165aac96f392f701a8e9606ad187..a017cf7a961016ba770939914c09a22921c4f692 100644 (file)
@@ -7,7 +7,7 @@ extern scf_dfa_module_t dfa_module_label;
 static int _label_action_colon(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*      parse  = dfa->priv;
-       dfa_parse_data_t* d      = data;
+       dfa_data_t*       d      = data;
        dfa_identity_t*   id     = scf_stack_top(d->current_identities);
 
        if (!id || !id->identity) {
diff --git a/parse/scf_dfa_macro.c b/parse/scf_dfa_macro.c
new file mode 100644 (file)
index 0000000..68d4280
--- /dev/null
@@ -0,0 +1,27 @@
+#include"scf_dfa.h"
+#include"scf_dfa_util.h"
+#include"scf_parse.h"
+
+extern scf_dfa_module_t dfa_module_macro;
+
+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);
+
+       return SCF_DFA_OK;
+}
+
+static int _dfa_init_syntax_macro(scf_dfa_t* dfa)
+{
+       SCF_DFA_GET_MODULE_NODE(dfa,  macro, hash, hash);
+
+       scf_vector_add(dfa->syntaxes, hash);
+       return 0;
+}
+
+scf_dfa_module_t dfa_module_macro =
+{
+       .name        = "macro",
+       .init_module = _dfa_init_module_macro,
+       .init_syntax = _dfa_init_syntax_macro,
+};
index cbd2698283101291a62b375c6244ca7be3680cc4..3e546780732b41294403b8f934a8d6d598094e0d 100644 (file)
@@ -26,7 +26,7 @@ static int _operator_is_op(scf_dfa_t* dfa, void* word)
        return (SCF_LEX_WORD_PLUS <= w->type && SCF_LEX_WORD_GE >= w->type);
 }
 
-int _operator_add_operator(scf_dfa_t* dfa, dfa_parse_data_t* d)
+int _operator_add_operator(scf_dfa_t* dfa, dfa_data_t* d)
 {
        scf_parse_t*     parse = dfa->priv;
        dfa_op_data_t*   opd   = d->module_datas[dfa_module_operator.index];
@@ -45,8 +45,7 @@ int _operator_add_operator(scf_dfa_t* dfa, dfa_parse_data_t* d)
                return SCF_DFA_ERROR;
        }
 
-       scf_logi("operator: %s,line:%d,pos:%d\n",
-                       f->node.w->text->data, f->node.w->line, f->node.w->pos);
+       scf_logi("operator: %s,line:%d,pos:%d\n", f->node.w->text->data, f->node.w->line, f->node.w->pos);
 
        while (d->current_identities->size > 0) {
 
@@ -91,7 +90,7 @@ int _operator_add_operator(scf_dfa_t* dfa, dfa_parse_data_t* d)
        return SCF_DFA_NEXT_WORD;
 }
 
-int _operator_add_arg(scf_dfa_t* dfa, dfa_parse_data_t* d)
+int _operator_add_arg(scf_dfa_t* dfa, dfa_data_t* d)
 {
        scf_variable_t* arg = NULL;
 
@@ -127,8 +126,7 @@ int _operator_add_arg(scf_dfa_t* dfa, dfa_parse_data_t* d)
                arg->arg_flag   = 1;
                arg->local_flag = 1;
 
-               scf_logi("d->current_function->argv->size: %d, %p\n",
-                               d->current_function->argv->size, d->current_function);
+               scf_logi("d->current_function->argv->size: %d, %p\n", d->current_function->argv->size, d->current_function);
 
                free(id0);
                free(id1);
@@ -141,7 +139,7 @@ int _operator_add_arg(scf_dfa_t* dfa, dfa_parse_data_t* d)
 
 static int _operator_action_comma(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       dfa_parse_data_t* d   = data;
+       dfa_data_t* d = data;
 
        if (_operator_add_arg(dfa, d) < 0) {
                scf_loge("add arg failed\n");
@@ -155,9 +153,9 @@ static int _operator_action_comma(scf_dfa_t* dfa, scf_vector_t* words, void* dat
 
 static int _operator_action_op(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = data;
-       dfa_op_data_t*    opd   = d->module_datas[dfa_module_operator.index];
+       scf_parse_t*    parse = dfa->priv;
+       dfa_data_t*     d     = data;
+       dfa_op_data_t*  opd   = d->module_datas[dfa_module_operator.index];
 
        opd->word_op = words->data[words->size - 1];
 
@@ -166,9 +164,9 @@ static int _operator_action_op(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _operator_action_lp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = data;
-       dfa_op_data_t*    opd   = d->module_datas[dfa_module_operator.index];
+       scf_parse_t*    parse = dfa->priv;
+       dfa_data_t*     d     = data;
+       dfa_op_data_t*  opd   = d->module_datas[dfa_module_operator.index];
 
        assert(!d->current_node);
 
@@ -188,10 +186,10 @@ static int _operator_action_lp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _operator_action_rp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = data;
-       dfa_op_data_t*    opd   = d->module_datas[dfa_module_operator.index];
-       scf_function_t*   f     = NULL;
+       scf_parse_t*     parse = dfa->priv;
+       dfa_data_t*      d     = data;
+       dfa_op_data_t*   opd   = d->module_datas[dfa_module_operator.index];
+       scf_function_t*  f     = NULL;
 
        d->nb_rps++;
 
@@ -278,10 +276,10 @@ static int _operator_action_rp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _operator_action_end(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = data;
-       scf_lex_word_t*   w     = words->data[words->size - 1];
-       dfa_op_data_t*   opd    = d->module_datas[dfa_module_operator.index];
+       scf_parse_t*     parse = dfa->priv;
+       dfa_data_t*      d     = data;
+       scf_lex_word_t*  w     = words->data[words->size - 1];
+       dfa_op_data_t*   opd   = d->module_datas[dfa_module_operator.index];
 
        parse->ast->current_block  = (scf_block_t*)(opd->parent_block);
 
@@ -313,9 +311,9 @@ static int _dfa_init_module_operator(scf_dfa_t* dfa)
        SCF_DFA_MODULE_NODE(dfa, operator, key,    _operator_is_key, NULL);
        SCF_DFA_MODULE_NODE(dfa, operator, op,     _operator_is_op,  _operator_action_op);
 
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = parse->dfa_data;
-       dfa_op_data_t*   opd    = d->module_datas[dfa_module_operator.index];
+       scf_parse_t*    parse = dfa->priv;
+       dfa_data_t*     d     = parse->dfa_data;
+       dfa_op_data_t*  opd   = d->module_datas[dfa_module_operator.index];
 
        assert(!opd);
 
@@ -332,9 +330,9 @@ static int _dfa_init_module_operator(scf_dfa_t* dfa)
 
 static int _dfa_fini_module_operator(scf_dfa_t* dfa)
 {
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = parse->dfa_data;
-       dfa_op_data_t*   opd    = d->module_datas[dfa_module_operator.index];
+       scf_parse_t*    parse = dfa->priv;
+       dfa_data_t*     d     = parse->dfa_data;
+       dfa_op_data_t*  opd    = d->module_datas[dfa_module_operator.index];
 
        if (opd) {
                free(opd);
@@ -400,7 +398,6 @@ static int _dfa_init_syntax_operator(scf_dfa_t* dfa)
        // operator body
        scf_dfa_node_add_child(rp,        block);
 
-       scf_logi("\n");
        return 0;
 }
 
@@ -413,4 +410,3 @@ scf_dfa_module_t dfa_module_operator =
 
        .fini_module = _dfa_fini_module_operator,
 };
-
index b6805a536a2f43647a2977dc48abbbc86fd78164..495c411fb6840cc4f44f06683da43a731d47c6dc 100644 (file)
@@ -1,6 +1,7 @@
 #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;
@@ -42,6 +43,7 @@ extern scf_dfa_module_t  dfa_module_block;
 
 scf_dfa_module_t* dfa_modules[] =
 {
+       &dfa_module_macro,
        &dfa_module_include,
 
        &dfa_module_identity,
@@ -91,7 +93,7 @@ int scf_parse_dfa_init(scf_parse_t* parse)
 
        int nb_modules  = sizeof(dfa_modules) / sizeof(dfa_modules[0]);
 
-       parse->dfa_data = calloc(1, sizeof(dfa_parse_data_t));
+       parse->dfa_data = calloc(1, sizeof(dfa_data_t));
        if (!parse->dfa_data) {
                scf_loge("\n");
                return -1;
index a3915f3d6d9eb963b0c5214e59b74c04cd969900..73228c75efcefbe8e8749e7a5ad2761df6a0464a 100644 (file)
@@ -2,14 +2,14 @@
 #include"scf_dfa_util.h"
 #include"scf_parse.h"
 
-extern scf_dfa_module_t dfa_module_return;
+extern scf_dfa_module_t  dfa_module_return;
 
 static int _return_action_return(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*      parse   = dfa->priv;
-       dfa_parse_data_t* d       = data;
-       scf_lex_word_t*   w       = words->data[words->size - 1];
-       scf_node_t*       _return = NULL;
+       scf_parse_t*     parse   = dfa->priv;
+       dfa_data_t*      d       = data;
+       scf_lex_word_t*  w       = words->data[words->size - 1];
+       scf_node_t*      _return = NULL;
 
        if (d->expr) {
                scf_loge("\n");
@@ -38,8 +38,8 @@ static int _return_action_return(scf_dfa_t* dfa, scf_vector_t* words, void* data
 
 static int _return_action_comma(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = data;
+       scf_parse_t*  parse = dfa->priv;
+       dfa_data_t*   d     = data;
 
        if (d->expr) {
                scf_node_add_child(d->current_return, d->expr);
@@ -53,8 +53,8 @@ static int _return_action_comma(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _return_action_semicolon(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = data;
+       scf_parse_t*  parse = dfa->priv;
+       dfa_data_t*   d     = data;
 
        if (d->expr) {
                scf_node_add_child(d->current_return, d->expr);
@@ -95,7 +95,6 @@ static int _dfa_init_syntax_return(scf_dfa_t* dfa)
        scf_dfa_node_add_child(comma,      expr);
        scf_dfa_node_add_child(expr,       semicolon);
 
-       scf_logi("\n");
        return 0;
 }
 
@@ -105,4 +104,3 @@ scf_dfa_module_t dfa_module_return =
        .init_module = _dfa_init_module_return,
        .init_syntax = _dfa_init_syntax_return,
 };
-
index 3b2bdb201fb70809a8353f0fd3062595b99c3b7c..df6366f4c31e4dd91660d83977752ca15832215d 100644 (file)
@@ -18,9 +18,9 @@ typedef struct {
 
 static int _sizeof_action_lp_stat(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       dfa_parse_data_t*  d     = data;
-       scf_stack_t*       s     = d->module_datas[dfa_module_sizeof.index];
-       dfa_sizeof_data_t* sd    = scf_stack_top(s);
+       dfa_data_t*         d  = data;
+       scf_stack_t*        s  = d->module_datas[dfa_module_sizeof.index];
+       dfa_sizeof_data_t*  sd = scf_stack_top(s);
 
        if (!sd) {
                scf_loge("\n");
@@ -36,10 +36,10 @@ static int _sizeof_action_lp_stat(scf_dfa_t* dfa, scf_vector_t* words, void* dat
 
 static int _sizeof_action_sizeof(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*       parse = dfa->priv;
-       dfa_parse_data_t*  d     = data;
-       scf_lex_word_t*    w     = words->data[words->size - 1];
-       scf_stack_t*       s     = d->module_datas[dfa_module_sizeof.index];
+       scf_parse_t*     parse = dfa->priv;
+       dfa_data_t*      d     = data;
+       scf_lex_word_t*  w     = words->data[words->size - 1];
+       scf_stack_t*     s     = d->module_datas[dfa_module_sizeof.index];
 
        dfa_sizeof_data_t* sd    = calloc(1, sizeof(dfa_sizeof_data_t));
        if (!sd) {
@@ -77,7 +77,7 @@ static int _sizeof_action_lp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 static int _sizeof_action_rp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*       parse = dfa->priv;
-       dfa_parse_data_t*  d     = data;
+       dfa_data_t*        d     = data;
        scf_lex_word_t*    w     = words->data[words->size - 1];
        scf_stack_t*       s     = d->module_datas[dfa_module_sizeof.index];
        dfa_sizeof_data_t* sd    = scf_stack_top(s);
@@ -196,9 +196,9 @@ static int _dfa_init_module_sizeof(scf_dfa_t* dfa)
        SCF_DFA_MODULE_NODE(dfa, sizeof, rp,       scf_dfa_is_rp,     _sizeof_action_rp);
        SCF_DFA_MODULE_NODE(dfa, sizeof, lp_stat,  scf_dfa_is_lp,     _sizeof_action_lp_stat);
 
-       scf_parse_t*       parse = dfa->priv;
-       dfa_parse_data_t*  d     = parse->dfa_data;
-       scf_stack_t*       s     = d->module_datas[dfa_module_sizeof.index];
+       scf_parse_t*  parse = dfa->priv;
+       dfa_data_t*   d     = parse->dfa_data;
+       scf_stack_t*  s     = d->module_datas[dfa_module_sizeof.index];
 
        assert(!s);
 
@@ -215,9 +215,9 @@ static int _dfa_init_module_sizeof(scf_dfa_t* dfa)
 
 static int _dfa_fini_module_sizeof(scf_dfa_t* dfa)
 {
-       scf_parse_t*       parse = dfa->priv;
-       dfa_parse_data_t*  d     = parse->dfa_data;
-       scf_stack_t*       s     = d->module_datas[dfa_module_sizeof.index];
+       scf_parse_t*  parse = dfa->priv;
+       dfa_data_t*   d     = parse->dfa_data;
+       scf_stack_t*  s     = d->module_datas[dfa_module_sizeof.index];
 
        if (s) {
                scf_stack_free(s);
@@ -250,7 +250,6 @@ static int _dfa_init_syntax_sizeof(scf_dfa_t* dfa)
        scf_dfa_node_add_child(identity,  rp);
        scf_dfa_node_add_child(star,      rp);
 
-       scf_logi("\n");
        return 0;
 }
 
@@ -262,4 +261,3 @@ scf_dfa_module_t dfa_module_sizeof =
 
        .fini_module = _dfa_fini_module_sizeof,
 };
-
index 589279aac08be8a00e22568ef8f7195e92721820..e95de0694eb718d0a883c21dc3d1412608e2f043 100644 (file)
@@ -24,12 +24,12 @@ static int _switch_is_end(scf_dfa_t* dfa, void* word)
 
 static int _switch_action_switch(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = data;
-       scf_lex_word_t*   w     = words->data[words->size - 1];
-       scf_stack_t*      s     = d->module_datas[dfa_module_switch.index];
-
+       scf_parse_t*     parse  = dfa->priv;
+       dfa_data_t*      d      = data;
+       scf_lex_word_t*  w      = words->data[words->size - 1];
+       scf_stack_t*     s      = d->module_datas[dfa_module_switch.index];
        scf_node_t*     _switch = scf_node_alloc(w, SCF_OP_SWITCH, NULL);
+
        if (!_switch) {
                scf_loge("node alloc failed\n");
                return SCF_DFA_ERROR;
@@ -58,8 +58,8 @@ static int _switch_action_switch(scf_dfa_t* dfa, scf_vector_t* words, void* data
 
 static int _switch_action_lp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*       parse = dfa->priv;
-       dfa_parse_data_t*  d     = data;
+       scf_parse_t*  parse = dfa->priv;
+       dfa_data_t*   d     = data;
 
        assert(!d->expr);
        d->expr_local_flag = 1;
@@ -72,7 +72,7 @@ static int _switch_action_lp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _switch_action_lp_stat(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       dfa_parse_data_t*  d  = data;
+       dfa_data_t*        d  = data;
        scf_stack_t*       s  = d->module_datas[dfa_module_switch.index];
        dfa_switch_data_t* sd = scf_stack_top(s);
 
@@ -86,7 +86,7 @@ static int _switch_action_lp_stat(scf_dfa_t* dfa, scf_vector_t* words, void* dat
 static int _switch_action_rp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*       parse = dfa->priv;
-       dfa_parse_data_t*  d     = data;
+       dfa_data_t*        d     = data;
        scf_stack_t*       s     = d->module_datas[dfa_module_switch.index];
        dfa_switch_data_t* sd    = scf_stack_top(s);
 
@@ -119,7 +119,7 @@ static int _switch_action_rp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 static int _switch_action_case(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*       parse = dfa->priv;
-       dfa_parse_data_t*  d     = data;
+       dfa_data_t*        d     = data;
        scf_lex_word_t*    w     = words->data[words->size - 1];
        scf_stack_t*       s     = d->module_datas[dfa_module_switch.index];
        dfa_switch_data_t* sd    = scf_stack_top(s);
@@ -139,7 +139,7 @@ static int _switch_action_case(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 static int _switch_action_default(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*       parse = dfa->priv;
-       dfa_parse_data_t*  d     = data;
+       dfa_data_t*        d     = data;
        scf_lex_word_t*    w     = words->data[words->size - 1];
        scf_stack_t*       s     = d->module_datas[dfa_module_switch.index];
        dfa_switch_data_t* sd    = scf_stack_top(s);
@@ -158,7 +158,7 @@ static int _switch_action_default(scf_dfa_t* dfa, scf_vector_t* words, void* dat
 static int _switch_action_colon(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*       parse = dfa->priv;
-       dfa_parse_data_t*  d     = data;
+       dfa_data_t*        d     = data;
        scf_stack_t*       s     = d->module_datas[dfa_module_switch.index];
        dfa_switch_data_t* sd    = scf_stack_top(s);
 
@@ -184,7 +184,7 @@ static int _switch_action_colon(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 static int _switch_action_end(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*       parse = dfa->priv;
-       dfa_parse_data_t*  d     = data;
+       dfa_data_t*        d     = data;
        scf_stack_t*       s     = d->module_datas[dfa_module_switch.index];
        dfa_switch_data_t* sd    = scf_stack_pop(s);
 
@@ -215,7 +215,7 @@ static int _dfa_init_module_switch(scf_dfa_t* dfa)
        SCF_DFA_MODULE_NODE(dfa, switch, end,       _switch_is_end,     _switch_action_end);
 
        scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = parse->dfa_data;
+       dfa_data_t* d     = parse->dfa_data;
        scf_stack_t*      s     = d->module_datas[dfa_module_switch.index];
 
        assert(!s);
@@ -233,9 +233,9 @@ static int _dfa_init_module_switch(scf_dfa_t* dfa)
 
 static int _dfa_fini_module_switch(scf_dfa_t* dfa)
 {
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = parse->dfa_data;
-       scf_stack_t*      s     = d->module_datas[dfa_module_switch.index];
+       scf_parse_t*  parse = dfa->priv;
+       dfa_data_t*   d     = parse->dfa_data;
+       scf_stack_t*  s     = d->module_datas[dfa_module_switch.index];
 
        if (s) {
                scf_stack_free(s);
@@ -270,7 +270,6 @@ static int _dfa_init_syntax_switch(scf_dfa_t* dfa)
        scf_dfa_node_add_child(expr,     colon);
        scf_dfa_node_add_child(_default, colon);
 
-       scf_logi("\n");
        return 0;
 }
 
index 4b2ef7d5348cde09b4bb45485a7790fc95bcf159..5ef9055a4eefdcf09eab8cab3c25c3df5eaeab7e 100644 (file)
@@ -14,7 +14,7 @@ static int _type_is__struct(scf_dfa_t* dfa, void* word)
 
 static int _type_action_const(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       dfa_parse_data_t* d = data;
+       dfa_data_t* d = data;
 
        d->const_flag = 1;
 
@@ -23,7 +23,7 @@ static int _type_action_const(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _type_action_extern(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       dfa_parse_data_t* d = data;
+       dfa_data_t* d = data;
 
        d->extern_flag = 1;
 
@@ -32,7 +32,7 @@ static int _type_action_extern(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _type_action_static(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       dfa_parse_data_t* d = data;
+       dfa_data_t* d = data;
 
        d->static_flag = 1;
 
@@ -41,7 +41,7 @@ static int _type_action_static(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _type_action_inline(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       dfa_parse_data_t* d = data;
+       dfa_data_t* d = data;
 
        d->inline_flag = 1;
 
@@ -50,12 +50,12 @@ static int _type_action_inline(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _type_action_base_type(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];
-       dfa_parse_data_t* d     = data;
-       scf_stack_t*      s     = d->current_identities;
+       scf_parse_t*     parse = dfa->priv;
+       scf_lex_word_t*  w     = words->data[words->size - 1];
+       dfa_data_t*      d     = data;
+       scf_stack_t*     s     = d->current_identities;
+       dfa_identity_t*  id    = calloc(1, sizeof(dfa_identity_t));
 
-       dfa_identity_t*   id    = calloc(1, sizeof(dfa_identity_t));
        if (!id)
                return SCF_DFA_ERROR;
 
@@ -150,11 +150,11 @@ int _type_find_type(scf_dfa_t* dfa, dfa_identity_t* id)
 
 static int _type_action_identity(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];
-       dfa_parse_data_t* d     = data;
-       scf_stack_t*      s     = d->current_identities;
-       dfa_identity_t*   id    = NULL;
+       scf_parse_t*     parse = dfa->priv;
+       scf_lex_word_t*  w     = words->data[words->size - 1];
+       dfa_data_t*      d     = data;
+       scf_stack_t*     s     = d->current_identities;
+       dfa_identity_t*  id    = NULL;
 
        if (s->size > 0) {
                id = scf_stack_top(s);
@@ -181,7 +181,7 @@ static int _type_action_identity(scf_dfa_t* dfa, scf_vector_t* words, void* data
 
 static int _type_action_star(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       dfa_parse_data_t* d  = data;
+       dfa_data_t* d  = data;
        dfa_identity_t*   id = scf_stack_top(d->current_identities);
 
        assert(id);
@@ -201,8 +201,8 @@ static int _type_action_star(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _type_action_comma(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       dfa_parse_data_t* d  = data;
-       dfa_identity_t*   id = scf_stack_top(d->current_identities);
+       dfa_data_t*      d  = data;
+       dfa_identity_t*  id = scf_stack_top(d->current_identities);
 
        assert(id);
 
@@ -312,7 +312,6 @@ static int _dfa_init_syntax_type(scf_dfa_t* dfa)
                scf_logd("n->name: %s\n", n->name);
        }
 
-       scf_logi("\n");
        return SCF_DFA_OK;
 }
 
index eb6754cfaea7cf949f0742082742578fe0da9436..6957bb73198df6f50a1931f059a6a64edf539e2c 100644 (file)
@@ -21,7 +21,7 @@ typedef struct {
 static int _union_action_identity(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*          parse = dfa->priv;
-       dfa_parse_data_t*     d     = data;
+       dfa_data_t*           d     = data;
        union_module_data_t*  md    = d->module_datas[dfa_module_union.index];
        scf_lex_word_t*       w     = words->data[words->size - 1];
 
@@ -53,7 +53,7 @@ static int _union_action_identity(scf_dfa_t* dfa, scf_vector_t* words, void* dat
 static int _union_action_lb(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*          parse = dfa->priv;
-       dfa_parse_data_t*     d     = data;
+       dfa_data_t*           d     = data;
        union_module_data_t*  md    = d->module_datas[dfa_module_union.index];
        scf_lex_word_t*       w     = words->data[words->size - 1];
        scf_type_t*           t     = NULL;
@@ -144,7 +144,7 @@ static int _union_calculate_size(scf_dfa_t* dfa, scf_type_t* s)
 static int _union_action_rb(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*          parse = dfa->priv;
-       dfa_parse_data_t*     d     = data;
+       dfa_data_t*           d     = data;
        union_module_data_t*  md    = d->module_datas[dfa_module_union.index];
 
        if (_union_calculate_size(dfa, md->current_union) < 0) {
@@ -165,7 +165,7 @@ static int _union_action_rb(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 static int _union_action_var(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*          parse = dfa->priv;
-       dfa_parse_data_t*     d     = data;
+       dfa_data_t*           d     = data;
        union_module_data_t*  md    = d->module_datas[dfa_module_union.index];
        scf_lex_word_t*       w     = words->data[words->size - 1];
 
@@ -190,7 +190,7 @@ static int _union_action_var(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 static int _union_action_semicolon(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*          parse = dfa->priv;
-       dfa_parse_data_t*     d     = data;
+       dfa_data_t*           d     = data;
        union_module_data_t*  md    = d->module_datas[dfa_module_union.index];
 
        if (md->nb_rbs == md->nb_lbs) {
@@ -229,7 +229,7 @@ static int _dfa_init_module_union(scf_dfa_t* dfa)
        SCF_DFA_MODULE_NODE(dfa, union, var,       scf_dfa_is_identity,  _union_action_var);
 
        scf_parse_t*          parse = dfa->priv;
-       dfa_parse_data_t*     d     = parse->dfa_data;
+       dfa_data_t*           d     = parse->dfa_data;
        union_module_data_t*  md    = d->module_datas[dfa_module_union.index];
 
        assert(!md);
@@ -248,7 +248,7 @@ static int _dfa_init_module_union(scf_dfa_t* dfa)
 static int _dfa_fini_module_union(scf_dfa_t* dfa)
 {
        scf_parse_t*          parse = dfa->priv;
-       dfa_parse_data_t*     d     = parse->dfa_data;
+       dfa_data_t*           d     = parse->dfa_data;
        union_module_data_t*  md    = d->module_datas[dfa_module_union.index];
 
        if (md) {
@@ -296,7 +296,6 @@ static int _dfa_init_syntax_union(scf_dfa_t* dfa)
        scf_dfa_node_add_child(var,       semicolon);
        scf_dfa_node_add_child(rb,        semicolon);
 
-       scf_logi("\n");
        return 0;
 }
 
index d8f75fde69755a507e88378846ba54a624869893..693b2217347d7bc9636a57cd6701ad3fcc47d045 100644 (file)
@@ -4,6 +4,20 @@
 #include"scf_lex_word.h"
 #include"scf_dfa.h"
 
+static inline int scf_dfa_is_hash(scf_dfa_t* dfa, void* word)
+{
+       scf_lex_word_t* w = word;
+
+       return SCF_LEX_WORD_HASH == w->type;
+}
+
+static inline int scf_dfa_is_LF(scf_dfa_t* dfa, void* word)
+{
+       scf_lex_word_t* w = word;
+
+       return SCF_LEX_WORD_LF == w->type;
+}
+
 static inline int scf_dfa_is_lp(scf_dfa_t* dfa, void* word)
 {
        scf_lex_word_t* w = word;
@@ -130,6 +144,13 @@ static inline int scf_dfa_is_include(scf_dfa_t* dfa, void* word)
        return SCF_LEX_WORD_KEY_INCLUDE == w->type;
 }
 
+static inline int scf_dfa_is_define(scf_dfa_t* dfa, void* word)
+{
+       scf_lex_word_t* w = word;
+
+       return SCF_LEX_WORD_KEY_DEFINE == w->type;
+}
+
 static inline int scf_dfa_is_vargs(scf_dfa_t* dfa, void* word)
 {
        scf_lex_word_t* w = word;
index 752f1c535e0031cdb1b62f600f13a6b979464aa4..0a4dc98a2279dfb654300499a3009b84c552ac9c 100644 (file)
@@ -9,9 +9,9 @@ int _type_find_type(scf_dfa_t* dfa, dfa_identity_t* id);
 
 static int _va_arg_action_start(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*       parse = dfa->priv;
-       dfa_parse_data_t*  d     = data;
-       scf_lex_word_t*    w     = words->data[words->size - 1];
+       scf_parse_t*     parse = dfa->priv;
+       dfa_data_t*      d     = data;
+       scf_lex_word_t*  w     = words->data[words->size - 1];
 
        if (d->current_va_start
                        || d->current_va_arg
@@ -33,9 +33,9 @@ static int _va_arg_action_start(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _va_arg_action_arg(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*       parse = dfa->priv;
-       dfa_parse_data_t*  d     = data;
-       scf_lex_word_t*    w     = words->data[words->size - 1];
+       scf_parse_t*     parse = dfa->priv;
+       dfa_data_t*      d     = data;
+       scf_lex_word_t*  w     = words->data[words->size - 1];
 
        if (d->current_va_start
                        || d->current_va_arg
@@ -60,9 +60,9 @@ static int _va_arg_action_arg(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _va_arg_action_end(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*       parse = dfa->priv;
-       dfa_parse_data_t*  d     = data;
-       scf_lex_word_t*    w     = words->data[words->size - 1];
+       scf_parse_t*     parse = dfa->priv;
+       dfa_data_t*      d     = data;
+       scf_lex_word_t*  w     = words->data[words->size - 1];
 
        if (d->current_va_start
                        || d->current_va_arg
@@ -84,9 +84,9 @@ static int _va_arg_action_end(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _va_arg_action_lp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*       parse = dfa->priv;
-       dfa_parse_data_t*  d     = data;
-       scf_lex_word_t*    w     = words->data[words->size - 1];
+       scf_parse_t*     parse = dfa->priv;
+       dfa_data_t*      d     = data;
+       scf_lex_word_t*  w     = words->data[words->size - 1];
 
        assert(d->current_va_start
                        || d->current_va_arg
@@ -100,13 +100,13 @@ static int _va_arg_action_lp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _va_arg_action_ap(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*       parse = dfa->priv;
-       dfa_parse_data_t*  d     = data;
-       scf_lex_word_t*    w     = words->data[words->size - 1];
+       scf_parse_t*     parse = dfa->priv;
+       dfa_data_t*      d     = data;
+       scf_lex_word_t*  w     = words->data[words->size - 1];
 
-       scf_variable_t*    ap;
-       scf_type_t*        t;
-       scf_node_t*        node;
+       scf_variable_t*  ap;
+       scf_type_t*      t;
+       scf_node_t*      node;
 
        ap = scf_block_find_variable(parse->ast->current_block, w->text->data);
        if (!ap) {
@@ -141,12 +141,7 @@ static int _va_arg_action_ap(scf_dfa_t* dfa, scf_vector_t* words, void* data)
                scf_loge("\n");
                return SCF_DFA_ERROR;
        }
-#if 0
-       if (ap->arg_flag) {
-               ap->nb_pointers = 1;
-               ap->size        = sizeof(void*);
-       }
-#endif
+
        return SCF_DFA_NEXT_WORD;
 }
 
@@ -159,14 +154,14 @@ static int _va_arg_action_comma(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _va_arg_action_fmt(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*       parse = dfa->priv;
-       dfa_parse_data_t*  d     = data;
-       scf_lex_word_t*    w     = words->data[words->size - 1];
+       scf_parse_t*     parse = dfa->priv;
+       dfa_data_t*      d     = data;
+       scf_lex_word_t*  w     = words->data[words->size - 1];
 
-       scf_function_t*    f;
-       scf_variable_t*    fmt;
-       scf_variable_t*    arg;
-       scf_node_t*        node;
+       scf_function_t*  f;
+       scf_variable_t*  fmt;
+       scf_variable_t*  arg;
+       scf_node_t*      node;
 
        fmt = scf_block_find_variable(parse->ast->current_block, w->text->data);
        if (!fmt) {
@@ -230,12 +225,11 @@ static int _va_arg_action_fmt(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _va_arg_action_rp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*       parse = dfa->priv;
-       dfa_parse_data_t*  d     = data;
-       scf_lex_word_t*    w     = words->data[words->size - 1];
+       scf_parse_t*     parse = dfa->priv;
+       dfa_data_t*      d     = data;
+       scf_lex_word_t*  w     = words->data[words->size - 1];
 
        if (d->current_va_arg) {
-
                if (d->current_va_arg->nb_nodes != 1) {
                        scf_loge("\n");
                        return SCF_DFA_ERROR;
@@ -302,8 +296,8 @@ static int _dfa_init_module_va_arg(scf_dfa_t* dfa)
        SCF_DFA_MODULE_NODE(dfa, va_arg, comma,      scf_dfa_is_comma,      _va_arg_action_comma);
        SCF_DFA_MODULE_NODE(dfa, va_arg, semicolon,  scf_dfa_is_semicolon,  _va_arg_action_semicolon);
 
-       scf_parse_t*       parse = dfa->priv;
-       dfa_parse_data_t*  d     = parse->dfa_data;
+       scf_parse_t*  parse = dfa->priv;
+       dfa_data_t*   d     = parse->dfa_data;
 
        d->current_va_start = NULL;
        d->current_va_arg   = NULL;
@@ -349,7 +343,6 @@ static int _dfa_init_syntax_va_arg(scf_dfa_t* dfa)
        scf_dfa_node_add_child(identity,  rp);
        scf_dfa_node_add_child(star,      rp);
 
-       scf_logi("\n");
        return 0;
 }
 
@@ -359,4 +352,3 @@ scf_dfa_module_t dfa_module_va_arg =
        .init_module = _dfa_init_module_va_arg,
        .init_syntax = _dfa_init_syntax_va_arg,
 };
-
index 00d0282b2f11e729ba8ae27115a1e061a3a37d61..b2615072c6ffe5867ac0186f7de16013397d1deb 100644 (file)
@@ -40,18 +40,17 @@ int _check_recursive(scf_type_t* parent, scf_type_t* child, scf_lex_word_t* w)
        return SCF_DFA_OK;
 }
 
-static int _var_add_var(scf_dfa_t* dfa, dfa_parse_data_t* d)
+static int _var_add_var(scf_dfa_t* dfa, dfa_data_t* d)
 {
-       scf_parse_t* parse = dfa->priv;
-
-       dfa_identity_t* id = scf_stack_top(d->current_identities);
+       scf_parse_t*     parse = dfa->priv;
+       dfa_identity_t*  id    = scf_stack_top(d->current_identities);
 
        if (id && id->identity) {
 
                scf_logd("d->current_identity: %p\n", id->identity);
 
-               scf_variable_t* var = scf_scope_find_variable(parse->ast->current_block->scope, id->identity->text->data);
-               if (var) {
+               scf_variable_t* v = scf_scope_find_variable(parse->ast->current_block->scope, id->identity->text->data);
+               if (v) {
                        scf_loge("repeated declare var '%s', line: %d\n", id->identity->text->data, id->identity->line);
                        return SCF_DFA_ERROR;
                }
@@ -123,27 +122,27 @@ static int _var_add_var(scf_dfa_t* dfa, dfa_parse_data_t* d)
                        return SCF_DFA_ERROR;
                }
 
-               var = SCF_VAR_ALLOC_BY_TYPE(id->identity, id0->type, id0->const_flag, id0->nb_pointers, id0->func_ptr);
-               if (!var) {
+               v = SCF_VAR_ALLOC_BY_TYPE(id->identity, id0->type, id0->const_flag, id0->nb_pointers, id0->func_ptr);
+               if (!v) {
                        scf_loge("alloc var failed\n");
                        return SCF_DFA_ERROR;
                }
-               var->local_flag  = local_flag;
-               var->global_flag = global_flag;
-               var->member_flag = member_flag;
+               v->local_flag  = local_flag;
+               v->global_flag = global_flag;
+               v->member_flag = member_flag;
 
-               var->static_flag = id0->static_flag;
-               var->extern_flag = id0->extern_flag;
+               v->static_flag = id0->static_flag;
+               v->extern_flag = id0->extern_flag;
 
                scf_logi("type: %d, nb_pointers: %d,nb_dimentions: %d, var: %s,line:%d,pos:%d, local: %d, global: %d, member: %d, extern: %d, static: %d\n\n",
-                               var->type, var->nb_pointers, var->nb_dimentions,
-                               var->w->text->data, var->w->line, var->w->pos,
-                               var->local_flag,  var->global_flag, var->member_flag,
-                               var->extern_flag, var->static_flag);
+                               v->type, v->nb_pointers, v->nb_dimentions,
+                               v->w->text->data, v->w->line, v->w->pos,
+                               v->local_flag,  v->global_flag, v->member_flag,
+                               v->extern_flag, v->static_flag);
 
-               scf_scope_push_var(parse->ast->current_block->scope, var);
+               scf_scope_push_var(parse->ast->current_block->scope, v);
 
-               d->current_var   = var;
+               d->current_var   = v;
                d->current_var_w = id->identity;
                id0->nb_pointers = 0;
                id0->const_flag  = 0;
@@ -158,7 +157,7 @@ static int _var_add_var(scf_dfa_t* dfa, dfa_parse_data_t* d)
        return 0;
 }
 
-static int _var_init_expr(scf_dfa_t* dfa, dfa_parse_data_t* d, int semi_flag)
+static int _var_init_expr(scf_dfa_t* dfa, dfa_data_t* d, int semi_flag)
 {
        scf_parse_t* parse = dfa->priv;
 
@@ -205,8 +204,8 @@ static int _var_init_expr(scf_dfa_t* dfa, dfa_parse_data_t* d, int semi_flag)
 
 static int _var_action_comma(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = data;
+       scf_parse_t*  parse = dfa->priv;
+       dfa_data_t*   d     = data;
 
        if (_var_add_var(dfa, d) < 0) {
                scf_loge("add var error\n");
@@ -227,9 +226,9 @@ static int _var_action_comma(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _var_action_semicolon(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = data;
-       dfa_identity_t*   id    = NULL;
+       scf_parse_t*     parse = dfa->priv;
+       dfa_data_t*      d     = data;
+       dfa_identity_t*  id    = NULL;
 
        d->var_semicolon_flag = 0;
 
@@ -238,8 +237,8 @@ static int _var_action_semicolon(scf_dfa_t* dfa, scf_vector_t* words, void* data
                return SCF_DFA_ERROR;
        }
 
-       d->nb_lss   = 0;
-       d->nb_rss   = 0;
+       d->nb_lss = 0;
+       d->nb_rss = 0;
 
        id = scf_stack_pop(d->current_identities);
        assert(id && id->type);
@@ -270,8 +269,8 @@ static int _var_action_semicolon(scf_dfa_t* dfa, scf_vector_t* words, void* data
 
 static int _var_action_assign(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = data;
+       scf_parse_t*  parse = dfa->priv;
+       dfa_data_t*   d     = data;
 
        if (_var_add_var(dfa, d) < 0) {
                scf_loge("add var error\n");
@@ -281,7 +280,7 @@ static int _var_action_assign(scf_dfa_t* dfa, scf_vector_t* words, void* data)
        d->nb_lss = 0;
        d->nb_rss = 0;
 
-       scf_lex_word_t*   w = words->data[words->size - 1];
+       scf_lex_word_t*  w = words->data[words->size - 1];
 
        if (!d->current_var) {
                scf_loge("\n");
@@ -327,8 +326,8 @@ static int _var_action_assign(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _var_action_ls(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = data;
+       scf_parse_t*  parse = dfa->priv;
+       dfa_data_t*   d     = data;
 
        if (_var_add_var(dfa, d) < 0) {
                scf_loge("add var error\n");
@@ -356,8 +355,8 @@ static int _var_action_ls(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _var_action_rs(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = data;
+       scf_parse_t*  parse = dfa->priv;
+       dfa_data_t*   d     = data;
 
        d->nb_rss++;
 
@@ -450,8 +449,6 @@ static int _dfa_init_syntax_var(scf_dfa_t* dfa)
        scf_dfa_node_add_child(init_data_rb, semicolon);
 
        scf_dfa_node_add_child(identity,  semicolon);
-
-       printf("%s(),%d\n\n", __func__, __LINE__);
        return 0;
 }
 
index 086b6522cb5e3c30e201567d7385f5b8047142bd..77aa343b2121be2a27f7bcd1758df8e7b14e8e54 100644 (file)
@@ -25,11 +25,11 @@ static int _while_is_end(scf_dfa_t* dfa, void* word)
 static int _while_action_while(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = data;
+       dfa_data_t*       d     = data;
        scf_lex_word_t*   w     = words->data[words->size - 1];
        scf_stack_t*      s     = d->module_datas[dfa_module_while.index];
+       scf_node_t*      _while = scf_node_alloc(w, SCF_OP_WHILE, NULL);
 
-       scf_node_t*       _while   = scf_node_alloc(w, SCF_OP_WHILE, NULL);
        if (!_while) {
                scf_loge("node alloc failed\n");
                return SCF_DFA_ERROR;
@@ -59,7 +59,7 @@ static int _while_action_while(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 static int _while_action_lp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = data;
+       dfa_data_t*       d     = data;
        scf_lex_word_t*   w     = words->data[words->size - 1];
        scf_stack_t*      s     = d->module_datas[dfa_module_while.index];
        dfa_while_data_t* wd    = scf_stack_top(s);
@@ -75,9 +75,9 @@ static int _while_action_lp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _while_action_lp_stat(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       dfa_parse_data_t* d     = data;
-       scf_stack_t*      s     = d->module_datas[dfa_module_while.index];
-       dfa_while_data_t* wd    = scf_stack_top(s);
+       dfa_data_t*       d  = data;
+       scf_stack_t*      s  = d->module_datas[dfa_module_while.index];
+       dfa_while_data_t* wd = scf_stack_top(s);
 
        SCF_DFA_PUSH_HOOK(scf_dfa_find_node(dfa, "while_lp_stat"), SCF_DFA_HOOK_POST);
 
@@ -89,7 +89,7 @@ static int _while_action_lp_stat(scf_dfa_t* dfa, scf_vector_t* words, void* data
 static int _while_action_rp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = data;
+       dfa_data_t*       d     = data;
        scf_lex_word_t*   w     = words->data[words->size - 1];
        scf_stack_t*      s     = d->module_datas[dfa_module_while.index];
        dfa_while_data_t* wd    = scf_stack_top(s);
@@ -123,10 +123,10 @@ static int _while_action_rp(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _while_action_end(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
-       scf_parse_t*      parse     = dfa->priv;
-       dfa_parse_data_t* d         = data;
-       scf_stack_t*      s         = d->module_datas[dfa_module_while.index];
-       dfa_while_data_t* wd        = scf_stack_pop(s);
+       scf_parse_t*      parse = dfa->priv;
+       dfa_data_t*       d     = data;
+       scf_stack_t*      s     = d->module_datas[dfa_module_while.index];
+       dfa_while_data_t* wd    = scf_stack_pop(s);
 
        assert(parse->ast->current_block == wd->parent_block);
 
@@ -152,9 +152,9 @@ static int _dfa_init_module_while(scf_dfa_t* dfa)
 
        SCF_DFA_MODULE_NODE(dfa, while, _while,    scf_dfa_is_while, _while_action_while);
 
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = parse->dfa_data;
-       scf_stack_t*      s     = d->module_datas[dfa_module_while.index];
+       scf_parse_t*  parse = dfa->priv;
+       dfa_data_t*   d     = parse->dfa_data;
+       scf_stack_t*  s     = d->module_datas[dfa_module_while.index];
 
        assert(!s);
 
@@ -171,9 +171,9 @@ static int _dfa_init_module_while(scf_dfa_t* dfa)
 
 static int _dfa_fini_module_while(scf_dfa_t* dfa)
 {
-       scf_parse_t*      parse = dfa->priv;
-       dfa_parse_data_t* d     = parse->dfa_data;
-       scf_stack_t*      s     = d->module_datas[dfa_module_while.index];
+       scf_parse_t*  parse = dfa->priv;
+       dfa_data_t*   d     = parse->dfa_data;
+       scf_stack_t*  s     = d->module_datas[dfa_module_while.index];
 
        if (s) {
                scf_stack_free(s);
@@ -206,7 +206,6 @@ static int _dfa_init_syntax_while(scf_dfa_t* dfa)
        // while body
        scf_dfa_node_add_child(rp,     block);
 
-       scf_logi("\n");
        return 0;
 }
 
@@ -219,4 +218,3 @@ scf_dfa_module_t dfa_module_while =
 
        .fini_module = _dfa_fini_module_while,
 };
-
index a1919657bd8c1fef5cc47958b668c3fdc37d4dbc..e7059b6c9e10dd4426094a6b1e7bb27a4ad3c1ad 100644 (file)
@@ -157,24 +157,22 @@ static int _scf_parse_add_sym(scf_parse_t* parse, const char* name,
 
 int scf_parse_file(scf_parse_t* parse, const char* path)
 {
-       assert(parse);
-
-       scf_block_t* root = parse->ast->root_block;
-       scf_block_t* b    = NULL;
-
-       int i;
-       for (i = 0; i < root->node.nb_nodes; i++) {
-               b  = (scf_block_t*)root->node.nodes[i];
+       if (!parse || !path)
+               return -EINVAL;
 
-               if (SCF_OP_BLOCK != b->node.type)
-                       continue;
+       scf_lex_t* lex = parse->lex_list;
 
-               if (!strcmp(b->name->data, path))
+       while (lex) {
+               if (!strcmp(lex->file->data, path))
                        break;
+
+               lex = lex->next;
        }
 
-       if (i < root->node.nb_nodes)
+       if (lex) {
+               parse->lex = lex;
                return 0;
+       }
 
        if (scf_lex_open(&parse->lex, path) < 0) {
                scf_loge("\n");
@@ -182,16 +180,19 @@ int scf_parse_file(scf_parse_t* parse, const char* path)
        }
        scf_ast_add_file_block(parse->ast, path);
 
+       parse->lex->next = parse->lex_list;
+       parse->lex_list  = parse->lex;
 
-       dfa_parse_data_t* d = parse->dfa_data;
+       dfa_data_t*       d = parse->dfa_data;
+       scf_lex_word_t*   w = NULL;
 
-       while (1) {
-               scf_lex_word_t* w = NULL;
+       int ret = 0;
 
-               int ret = scf_lex_pop_word(parse->lex, &w);
+       while (1) {
+               ret = scf_lex_pop_word(parse->lex, &w);
                if (ret < 0) {
                        scf_loge("lex pop word failed\n");
-                       return ret;
+                       break;
                }
 
                if (SCF_LEX_WORD_EOF == w->type) {
@@ -215,13 +216,16 @@ int scf_parse_file(scf_parse_t* parse, const char* path)
 
                assert(!d->expr);
 
-               if (scf_dfa_parse_word(parse->dfa, w, d) < 0) {
+               ret = scf_dfa_parse_word(parse->dfa, w, d);
+               if (ret < 0) {
                        scf_loge("dfa parse failed\n");
-                       return -1;
+                       break;
                }
        }
 
-       return 0;
+       fclose(parse->lex->fp);
+       parse->lex->fp = NULL;
+       return ret;
 }
 
 static int _debug_abbrev_find_by_tag(const void* v0, const void* v1)
index 8ef3d05cfa729e21982c396099425d77b6cee77f..c04ad9c52ab005fcf7576fceccc572f9e18f9035 100644 (file)
@@ -5,10 +5,10 @@
 #include"scf_ast.h"
 #include"scf_dfa.h"
 #include"scf_stack.h"
-#include"scf_dwarf_def.h"
+#include"scf_dwarf.h"
 
-typedef struct scf_parse_s             scf_parse_t;
-typedef struct dfa_parse_data_s dfa_parse_data_t;
+typedef struct scf_parse_s   scf_parse_t;
+typedef struct dfa_data_s    dfa_data_t;
 
 #define SCF_SHNDX_TEXT   1
 #define SCF_SHNDX_RODATA 2
@@ -21,17 +21,18 @@ typedef struct dfa_parse_data_s dfa_parse_data_t;
 
 struct scf_parse_s
 {
-       scf_lex_t*                 lex;
+       scf_lex_t*         lex_list;
+       scf_lex_t*         lex;
 
-       scf_ast_t*                 ast;
+       scf_ast_t*         ast;
 
-       scf_dfa_t*                 dfa;
-       dfa_parse_data_t*  dfa_data;
+       scf_dfa_t*         dfa;
+       dfa_data_t*        dfa_data;
 
        scf_vector_t*      symtab;
        scf_vector_t*      global_consts;
 
-       scf_dwarf_debug_t* debug;
+       scf_dwarf_t*       debug;
 };
 
 typedef struct {
@@ -56,7 +57,7 @@ typedef struct {
 
 } dfa_identity_t;
 
-struct dfa_parse_data_s {
+struct dfa_data_s {
        void**               module_datas;
 
        scf_expr_t*          expr;
@@ -114,8 +115,8 @@ struct dfa_parse_data_s {
 
 int scf_parse_dfa_init(scf_parse_t* parse);
 
-int    scf_parse_open(scf_parse_t** pparse);
-int scf_parse_close(scf_parse_t* parse);
+int scf_parse_open (scf_parse_t** pparse);
+int scf_parse_close(scf_parse_t*   parse);
 
 int scf_parse_file(scf_parse_t* parse, const char* path);
 
@@ -125,4 +126,3 @@ int _find_global_var(scf_node_t* node, void* arg, scf_vector_t* vec);
 int _find_function  (scf_node_t* node, void* arg, scf_vector_t* vec);
 
 #endif
-
index 4b5812cb8617048b3328f5fb4609c8cf480c0999..34626697d0f15d2c590bb9f31333e21fe41f70cb 100644 (file)
@@ -65,6 +65,16 @@ static inline void scf_list_add_front(scf_list_t* h, scf_list_t* n)
                }\
        } while(0)
 
+#define scf_slist_clear(h, type, next, type_free) \
+       do { \
+               while (h) { \
+                       type* p = h; \
+                       h = p->next; \
+                       type_free(p); \
+                       p = NULL; \
+               } \
+       } while (0)
+
 #define scf_list_mov(dst, src, type, member) \
        do {\
                scf_list_t* l;\
@@ -78,4 +88,3 @@ static inline void scf_list_add_front(scf_list_t* h, scf_list_t* n)
        } while(0)
 
 #endif
-
index c8df1714f48fb246c810e9a9837e893684343361..72324a459fe9b18c79fce668b97b453b347a40c5 100644 (file)
@@ -59,6 +59,4 @@ int                scf_rbtree_foreach(scf_rbtree_t* tree, scf_rbtree_node_t* roo
 
 int                scf_rbtree_foreach_reverse(scf_rbtree_t* tree, scf_rbtree_node_t* root, void* data, scf_rbtree_node_do_pt done);
 
-
 #endif
-
index a0b458794e3846e1c96658c474922c95f841a240..d0ee3d0f1fff1982bc05377ce67cbb09bdb467ea 100644 (file)
@@ -103,9 +103,6 @@ void scf_string_print_bin(scf_string_t* s)
 
 int    scf_string_cmp(const scf_string_t* s0, const scf_string_t* s1)
 {
-       if (!s0 || !s1 || !s0->data || !s1->data)
-               return -EINVAL;
-
        if (s0->len < s1->len)
                return -1;
 
@@ -116,17 +113,11 @@ int       scf_string_cmp(const scf_string_t* s0, const scf_string_t* s1)
 
 int    scf_string_cmp_cstr(const scf_string_t* s0, const char* str)
 {
-       if (!s0 || !s0->data || !str)
-               return -EINVAL;
-
        return scf_string_cmp_cstr_len(s0, str, strlen(str));
 }
 
 int    scf_string_cmp_cstr_len(const scf_string_t* s0, const char* str, size_t len)
 {
-       if (!s0 || !s0->data || !str)
-               return -EINVAL;
-
        scf_string_t s1;
        s1.capacity     = -1;
        s1.len          = len;
index d8abe21c65e9828c2bb8383c191d5cc837d8adb7..95592f0acf31e85b37ec0dc26c591110a1d7f37e 100644 (file)
@@ -29,23 +29,23 @@ static inline scf_vector_t* scf_vector_alloc()
        return v;
 }
 
-static inline scf_vector_t* scf_vector_clone(scf_vector_t* origin)
+static inline scf_vector_t* scf_vector_clone(scf_vector_t* src)
 {
-       scf_vector_t* clone = calloc(1, sizeof(scf_vector_t));
-       if (!clone)
+       scf_vector_t* dst = calloc(1, sizeof(scf_vector_t));
+       if (!dst)
                return NULL;
 
-       clone->data = calloc(origin->capacity, sizeof(void*));
-       if (!clone->data) {
-               free(clone);
-               clone = NULL;
+       dst->data = calloc(src->capacity, sizeof(void*));
+       if (!dst->data) {
+               free(dst);
                return NULL;
        }
 
-       clone->capacity = origin->capacity;
-       clone->size             = origin->size;
-       memcpy(clone->data, origin->data, origin->size * sizeof(void*));
-       return clone;
+       dst->capacity = src->capacity;
+       dst->size     = src->size;
+
+       memcpy(dst->data, src->data, src->size * sizeof(void*));
+       return dst;
 }
 
 static inline int scf_vector_cat(scf_vector_t* dst, scf_vector_t* src)