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:
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);
+ }
+}
#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, // +
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
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
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)
{
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);
-#include"scf_dwarf_def.h"
+#include"scf_dwarf.h"
#include"scf_leb128.h"
static scf_dwarf_abbrev_attribute_t abbrev_cu[] =
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;
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;
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)
free(debug);
}
}
-
--- /dev/null
+#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
-#include"scf_dwarf_def.h"
+#include"scf_dwarf.h"
#include"scf_leb128.h"
typedef struct {
-#include"scf_dwarf_def.h"
+#include"scf_dwarf.h"
#include"scf_leb128.h"
#include"scf_native.h"
#include"scf_elf.h"
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)
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;
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");
}
}
}
-
-#include"scf_dwarf_def.h"
+#include"scf_dwarf.h"
#include"scf_leb128.h"
#include"scf_native.h"
#include"scf_elf.h"
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;
-include "../lib/scf_capi.c";
+#include "../lib/scf_capi.c"
int* f()
{
-include "../lib/scf_capi.c";
-include "../lib/scf_complex.c";
+#include "../lib/scf_capi.c"
+#include "../lib/scf_complex.c"
int main()
{
-include "../lib/scf_list.c";
-include "../lib/scf_capi.c";
+#include "../lib/scf_list.c"
+#include "../lib/scf_capi.c"
struct Data
{
--- /dev/null
+
+int printf(const char* fmt, ...);
+
+#define ABC 1111
+
+int main()
+{
+ printf("ABC: %d\n", ABC);
+ return 0;
+}
-include "../lib/scf_capi.c";
+#include"../lib/scf_capi.c"
const int MAT_TYPE_NONE = 0;
const int MAT_TYPE_U8 = 1;
-include "../lib/scf_capi.c";
+#include "../lib/scf_capi.c"
int f(int** t0, int **t1);
-include "../lib/scf_capi.c";
+#include "../lib/scf_capi.c"
struct str
{
-include "../lib/scf_capi.c";
+#include "../lib/scf_capi.c"
struct str
{
printf("%s\n", p0->data);
return 0;
}
-
-include "../lib/scf_capi.c";
+#include "../lib/scf_capi.c"
struct string
{
{"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},
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];
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)
}
}
-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
}
}
- return scf_lex_pop_word(lex, pword);
+ return __lex_pop_word(lex, pword);
} else if ('*' == c2->c) {
free(c);
}
}
- return scf_lex_pop_word(lex, pword);
+ return __lex_pop_word(lex, pword);
} else {
_lex_push_char(lex, c2);
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) {
}
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;
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;
+}
#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;
} scf_escape_char_t;
#define SCF_UTF8_MAX 6
+#define SCF_UTF8_LF 1
struct scf_char_s
{
scf_char_t* next;
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);
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) {
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)
-
-include "../lib/scf_capi.c";
+#include "../lib/scf_capi.c"
struct complex
{
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
}
}
- char* obj = "1.elf";
+ char* obj = "1.o";
char* exec = "1.out";
if (out) {
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) {
#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");
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;
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;
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;
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) {
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");
scf_dfa_node_add_child(async, expr);
scf_dfa_node_add_child(expr, semicolon);
- scf_logi("\n");
return 0;
}
.init_module = _dfa_init_module_async,
.init_syntax = _dfa_init_syntax_async,
};
-
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);
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;
}
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);
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);
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];
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;
}
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);
SCF_DFA_GET_MODULE_NODE(dfa, expr, entry, expr);
SCF_DFA_GET_MODULE_NODE(dfa, type, entry, type);
+ SCF_DFA_GET_MODULE_NODE(dfa, macro, hash, macro);
+
SCF_DFA_GET_MODULE_NODE(dfa, if, _if, _if);
SCF_DFA_GET_MODULE_NODE(dfa, while, _while, _while);
SCF_DFA_GET_MODULE_NODE(dfa, do, _do, _do);
scf_dfa_node_add_child(entry, expr);
scf_dfa_node_add_child(entry, type);
+ scf_dfa_node_add_child(entry, macro);
+
scf_dfa_node_add_child(entry, _if);
scf_dfa_node_add_child(entry, _while);
scf_dfa_node_add_child(entry, _do);
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);
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) {
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) {
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;
}
.init_module = _dfa_init_module_break,
.init_syntax = _dfa_init_syntax_break,
};
-
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");
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;
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;
}
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];
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);
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);
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);
scf_dfa_node_add_child(comma, expr);
scf_dfa_node_add_child(expr, rp);
- scf_logi("\n");
return 0;
}
.fini_module = _dfa_fini_module_call,
};
-
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];
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;
}
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];
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;
}
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) {
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) {
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;
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) {
scf_dfa_node_add_child(end, member);
scf_dfa_node_add_child(end, rb);
- printf("%s(),%d\n\n", __func__, __LINE__);
return 0;
}
.fini_module = _dfa_fini_module_class,
};
-
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);
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];
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);
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);
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);
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);
scf_dfa_node_add_child(comma, identity);
scf_dfa_node_add_child(identity, rp);
- scf_logi("\n");
return 0;
}
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) {
SCF_DFA_GET_MODULE_NODE(dfa, continue, _continue, _continue);
scf_dfa_node_add_child(_continue, semicolon);
-
- scf_logi("\n");
return 0;
}
.init_module = _dfa_init_module_continue,
.init_syntax = _dfa_init_syntax_continue,
};
-
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++;
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];
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];
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];
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];
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];
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);
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) {
scf_dfa_node_add_child(comma, expr);
scf_dfa_node_add_child(expr, rp);
- scf_logi("\n");
return 0;
}
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;
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;
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);
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");
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);
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);
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);
scf_dfa_node_add_child(expr, rp);
scf_dfa_node_add_child(rp, semicolon);
- scf_logi("\n");
return 0;
}
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];
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;
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];
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];
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;
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;
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];
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);
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) {
// end
scf_dfa_node_add_child(rb, semicolon);
- scf_logi("\n");
return 0;
}
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)
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
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
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;
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();
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);
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) {
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) {
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();
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) {
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) {
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) {
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) {
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) {
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) {
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;
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;
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);
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)
scf_dfa_node_add_child(identity, semicolon);
scf_dfa_node_add_child(rs, semicolon);
- scf_logi("\n\n");
return 0;
}
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;
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);
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);
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");
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) {
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++;
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);
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);
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);
// for body block
scf_dfa_node_add_child(rp, block);
- scf_logi("\n");
return 0;
}
.fini_module = _dfa_fini_module_for,
};
-
} 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);
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;
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;
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");
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);
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++;
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;
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);
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);
// function body
scf_dfa_node_add_child(rp, block);
- scf_logi("\n");
return 0;
}
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);
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);
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;
scf_dfa_node_add_child(_goto, identity);
scf_dfa_node_add_child(identity, semicolon);
- scf_logi("\n");
return 0;
}
.init_module = _dfa_init_module_goto,
.init_syntax = _dfa_init_syntax_goto,
};
-
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);
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);
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;
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);
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);
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++;
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");
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)) {
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);
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);
// last else block
scf_dfa_node_add_child(_else, block);
- scf_logi("\n");
return 0;
}
.fini_module = _dfa_fini_module_if,
};
-
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;
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);
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;
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;
}
{
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;
}
.init_module = _dfa_init_module_include,
.init_syntax = _dfa_init_syntax_include,
};
-
#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;
} 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;
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);
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) {
}
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];
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) {
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);
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);
scf_dfa_node_add_child(comma, expr);
scf_dfa_node_add_child(expr, rb);
- scf_logi("\n");
return 0;
}
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) {
--- /dev/null
+#include"scf_dfa.h"
+#include"scf_dfa_util.h"
+#include"scf_parse.h"
+
+extern scf_dfa_module_t dfa_module_macro;
+
+static int _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,
+};
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];
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) {
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;
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);
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");
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];
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);
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++;
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);
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);
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);
// operator body
scf_dfa_node_add_child(rp, block);
- scf_logi("\n");
return 0;
}
.fini_module = _dfa_fini_module_operator,
};
-
#include"scf_dfa.h"
#include"scf_parse.h"
+extern scf_dfa_module_t dfa_module_macro;
extern scf_dfa_module_t dfa_module_include;
extern scf_dfa_module_t dfa_module_identity;
scf_dfa_module_t* dfa_modules[] =
{
+ &dfa_module_macro,
&dfa_module_include,
&dfa_module_identity,
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;
#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");
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);
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);
scf_dfa_node_add_child(comma, expr);
scf_dfa_node_add_child(expr, semicolon);
- scf_logi("\n");
return 0;
}
.init_module = _dfa_init_module_return,
.init_syntax = _dfa_init_syntax_return,
};
-
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");
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) {
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);
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);
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);
scf_dfa_node_add_child(identity, rp);
scf_dfa_node_add_child(star, rp);
- scf_logi("\n");
return 0;
}
.fini_module = _dfa_fini_module_sizeof,
};
-
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;
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;
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);
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);
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);
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);
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);
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);
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);
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);
scf_dfa_node_add_child(expr, colon);
scf_dfa_node_add_child(_default, colon);
- scf_logi("\n");
return 0;
}
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;
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;
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;
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;
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;
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);
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);
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);
scf_logd("n->name: %s\n", n->name);
}
- scf_logi("\n");
return SCF_DFA_OK;
}
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];
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;
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) {
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];
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) {
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);
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) {
scf_dfa_node_add_child(var, semicolon);
scf_dfa_node_add_child(rb, semicolon);
- scf_logi("\n");
return 0;
}
#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;
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;
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
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
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
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
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) {
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;
}
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) {
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;
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;
scf_dfa_node_add_child(identity, rp);
scf_dfa_node_add_child(star, rp);
- scf_logi("\n");
return 0;
}
.init_module = _dfa_init_module_va_arg,
.init_syntax = _dfa_init_syntax_va_arg,
};
-
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;
}
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;
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;
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");
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;
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);
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");
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");
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");
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++;
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;
}
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;
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);
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);
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);
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);
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);
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);
// while body
scf_dfa_node_add_child(rp, block);
- scf_logi("\n");
return 0;
}
.fini_module = _dfa_fini_module_while,
};
-
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");
}
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) {
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)
#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
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 {
} dfa_identity_t;
-struct dfa_parse_data_s {
+struct dfa_data_s {
void** module_datas;
scf_expr_t* expr;
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);
int _find_function (scf_node_t* node, void* arg, scf_vector_t* vec);
#endif
-
}\
} 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;\
} while(0)
#endif
-
int scf_rbtree_foreach_reverse(scf_rbtree_t* tree, scf_rbtree_node_t* root, void* data, scf_rbtree_node_do_pt done);
-
#endif
-
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;
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;
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)