From ce8a86e0821f9cf27eb66c7cdc11984bd9533f6f Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Sat, 25 Jul 2015 15:01:51 +0000 Subject: [PATCH] added some code to support importing a pool dictionary --- stix/lib/comp.c | 178 +++++++++++++++++++++++++++----------------- stix/lib/exec.c | 2 +- stix/lib/main.c | 1 + stix/lib/stix-prv.h | 1 + 4 files changed, 114 insertions(+), 68 deletions(-) diff --git a/stix/lib/comp.c b/stix/lib/comp.c index 7307edb..c10a27b 100644 --- a/stix/lib/comp.c +++ b/stix/lib/comp.c @@ -2066,73 +2066,6 @@ static STIX_INLINE int find_temporary_variable (stix_t* stix, const stix_ucs_t* return find_word_in_string (&stix->c->mth.tmprs, name, xindex); } -static int compile_class_level_variables (stix_t* stix) -{ - var_type_t dcl_type = VAR_INSTANCE; - - if (stix->c->tok.type == STIX_IOTOK_LPAREN) - { - /* process variable modifiers */ - GET_TOKEN (stix); - - if (is_token_symbol(stix, VOCA_CLASS)) - { - /* #dcl(#class) */ - dcl_type = VAR_CLASS; - GET_TOKEN (stix); - } - else if (is_token_symbol(stix, VOCA_CLASSINST)) - { - /* #dcl(#classinst) */ - dcl_type = VAR_CLASSINST; - GET_TOKEN (stix); - } - - if (stix->c->tok.type != STIX_IOTOK_RPAREN) - { - set_syntax_error (stix, STIX_SYNERR_RPAREN, &stix->c->tok.loc, &stix->c->tok.name); - return -1; - } - - GET_TOKEN (stix); - } - - do - { - if (stix->c->tok.type == STIX_IOTOK_IDENT) - { - var_info_t var; - - if (find_class_level_variable(stix, STIX_NULL, &stix->c->tok.name, &var) >= 0) - { - set_syntax_error (stix, STIX_SYNERR_VARNAMEDUP, &stix->c->tok.loc, &stix->c->tok.name); - return -1; - } - -/* TOOD: CHECK IF IT CONFLICTS WITH GLOBAL VARIABLE NAMES */ -/* TODO: ------------------------------------------------ */ - - if (add_class_level_variable(stix, dcl_type, &stix->c->tok.name) <= -1) return -1; - } - else - { - break; - } - - GET_TOKEN (stix); - } - while (1); - - if (stix->c->tok.type != STIX_IOTOK_PERIOD) - { - set_syntax_error (stix, STIX_SYNERR_PERIOD, &stix->c->tok.loc, &stix->c->tok.name); - return -1; - } - - GET_TOKEN (stix); - return 0; -} - static stix_oop_set_t add_namespace (stix_t* stix, stix_oop_set_t dic, const stix_ucs_t* name) { stix_size_t tmp_count = 0; @@ -2259,6 +2192,117 @@ wrong_name: return -1; } +static int compile_class_level_variables (stix_t* stix) +{ + var_type_t dcl_type = VAR_INSTANCE; + + if (stix->c->tok.type == STIX_IOTOK_LPAREN) + { + /* process variable modifiers */ + GET_TOKEN (stix); + + if (is_token_symbol(stix, VOCA_CLASS)) + { + /* #dcl(#class) */ + dcl_type = VAR_CLASS; + GET_TOKEN (stix); + } + else if (is_token_symbol(stix, VOCA_CLASSINST)) + { + /* #dcl(#classinst) */ + dcl_type = VAR_CLASSINST; + GET_TOKEN (stix); + } + else if (is_token_symbol(stix, VOCA_POOLDIC)) + { + /* #dcl(#pooldic) */ + dcl_type = VAR_GLOBAL; /* this is not a real type. use for branching below */ + GET_TOKEN (stix); + } + + if (stix->c->tok.type != STIX_IOTOK_RPAREN) + { + set_syntax_error (stix, STIX_SYNERR_RPAREN, &stix->c->tok.loc, &stix->c->tok.name); + return -1; + } + + GET_TOKEN (stix); + } + + if (dcl_type == VAR_GLOBAL) + { + stix_ucs_t last; + stix_oop_set_t ns_oop; + stix_oop_association_t ass; + + do + { + if (stix->c->tok.type == STIX_IOTOK_IDENT_DOTTED) + { + if (preprocess_dotted_name(stix, 0, 0, &stix->c->tok.name, &stix->c->tok.loc, &last, &ns_oop) <= -1) return -1; + } + else if (stix->c->tok.type == STIX_IOTOK_IDENT) + { + last = stix->c->tok.name; + ns_oop = stix->sysdic; + } + else break; + + ass = stix_lookupdic (stix, ns_oop, &last); + if (!ass || STIX_CLASSOF(stix, ass->value) != stix->_pool_dictionary) + { + set_syntax_error (stix, STIX_SYNERR_POOLDIC, &stix->c->tok.loc, &stix->c->tok.name); + return -1; + } + + /* TODO: */ + /*if (add_pool_dictionary(stix, &stix->c->tok.name) <= -1) return -1;*/ + GET_TOKEN (stix); + } + while (1); + } + else + { + + do + { + if (stix->c->tok.type == STIX_IOTOK_IDENT) + { + var_info_t var; + + if (find_class_level_variable(stix, STIX_NULL, &stix->c->tok.name, &var) >= 0 || + stix_lookupdic (stix, stix->sysdic, &stix->c->tok.name) || /* conflicts with a top global name */ + stix_lookupdic (stix, stix->c->cls.ns_oop, &stix->c->tok.name)) /* conflicts with a global name in the class'es name space */ + { + set_syntax_error (stix, STIX_SYNERR_VARNAMEDUP, &stix->c->tok.loc, &stix->c->tok.name); + return -1; + } + + if (add_class_level_variable(stix, dcl_type, &stix->c->tok.name) <= -1) return -1; + } + else + { + break; + } + + GET_TOKEN (stix); + } + while (1); + } + + if (stix->c->tok.type != STIX_IOTOK_PERIOD) + { + set_syntax_error (stix, STIX_SYNERR_PERIOD, &stix->c->tok.loc, &stix->c->tok.name); + return -1; + } + + GET_TOKEN (stix); + return 0; + + + +} + static int compile_unary_method_name (stix_t* stix) { STIX_ASSERT (stix->c->mth.name.len == 0); diff --git a/stix/lib/exec.c b/stix/lib/exec.c index e82e924..b151df4 100644 --- a/stix/lib/exec.c +++ b/stix/lib/exec.c @@ -853,7 +853,7 @@ struct primitive_t { stix_ooi_t nargs; /* expected number of arguments */ primitive_handler_t handler; - stix_ucs_t name; + /* stix_ucs_t name; */ }; typedef struct primitive_t primitive_t; diff --git a/stix/lib/main.c b/stix/lib/main.c index 78221f6..671282f 100644 --- a/stix/lib/main.c +++ b/stix/lib/main.c @@ -217,6 +217,7 @@ static char* syntax_error_msg[] = "wrong primitive number", "#include error", "wrong namespace name", + "wrong pool dictionary name", "duplicate pool dictionary name", "literal expected" }; diff --git a/stix/lib/stix-prv.h b/stix/lib/stix-prv.h index a3df929..e62c065 100644 --- a/stix/lib/stix-prv.h +++ b/stix/lib/stix-prv.h @@ -331,6 +331,7 @@ enum stix_synerrnum_t STIX_SYNERR_PRIMNO, /* wrong primitive number */ STIX_SYNERR_INCLUDE, /* #include error */ STIX_SYNERR_NAMESPACE, /* wrong namespace name */ + STIX_SYNERR_POOLDIC, /* wrong pool dictionary */ STIX_SYNERR_POOLDICDUP, /* duplicate pool dictionary */ STIX_SYNERR_LITERAL /* literal expected */ };