--- parser3/src/main/Attic/core.C 2001/02/13 15:10:46 1.8 +++ parser3/src/main/Attic/core.C 2001/02/14 14:15:37 1.11 @@ -1,30 +1,86 @@ -void process(method_self_n_params_n_locals& root, Value& self, - arcontext& arcontext, WContext& awcontext, - String_iterator& code, char char_to_stop_before) { +enum Prefix { + NO_PREFIX, + ROOT_PREFIX, + SELF_PREFIX +}; + +enum CHAR_TYPE { + NO_TYPE=0, // these got skipped by String::skip_to + VAR_START_TYPE, + METHOD_START_TYPE, + STOP_TYPE,///=-1 // same as EOF type(-1), see String::skip_to + DOT_TYPE, + COLON_TYPE, + CONSTRUCTOR_BODY_START_TYPE, + CONSTRUCTOR_BODY_FINISH_TYPE, + BLOCK_START_TYPE, + BLOCK_FINISH_TYPE, - // $ on code? - process_dollar(root, self, arcontext, awcontext, code, char_to_stop_before); + Z_TYPE +}; - // ^ on code? - process_bird(root, self, arcontext, awcontext, code, char_to_stop_before); +Char_types var_or_method_start; +Char_types var_or_method_start_or_constructor_stop; +Char_types var_or_method_start_or_block_stop; +Char_types common_names_breaks, var_names_breaks, method_names_breaks; + +void prepare() { + var_or_method_start.set('$', VAR_START_TYPE); + var_or_method_start.set('^', METHOD_START_TYPE); + + var_or_method_start_or_constructor_stop=var_or_method_start; + var_or_method_start_or_constructor_stop.set(')', STOP_TYPE); + + var_or_method_start_or_block_stop=var_or_method_start; + var_or_method_start_or_block_stop.set(']', STOP_TYPE); + + common_names_breaks.set(0, ' ', STOP_TYPE); + common_names_breaks.set('.', DOT_TYPE); + common_names_breaks.set(':', COLON_TYPE); + common_names_breaks.set(')', STOP_TYPE); // var_or_method_start_or_constructor_stop + common_names_breaks.set(']', STOP_TYPE); // var_or_method_start_or_block_stop - // TODO - // 2. вызовы статических методов + var_names_breaks=common_names_breaks; + var_names_breaks.set('(', CONSTRUCTOR_BODY_START_TYPE); + + method_names_breaks=common_names_breaks; + method_names_breaks.set('[', BLOCK_START_TYPE); } -void process_dollar(method_self_n_params_n_locals& root, Value& self, - arcontext& arcontext, WContext& awcontext, - String_iterator& iter, char char_to_stop_before) { +void process(method_self_n_params_n_locals& root, Value& self, + arcontext& arcontext, WContext& awcontext, + String_iterator& iter, Char_types& breaks) { + while(!iter.eof()) { + String_iterator start(iter); + CHAR_TYPE type=iter.skip_to(breaks); + awcontext.write(start, iter); + + switch(type) { + case VAR_START_TYPE: + process_var(root, self, arcontext, awcontext, iter, breaks); + break; + case METHOD_START_TYPE: + process_method(root, self, arcontext, awcontext, iter, breaks); + break; + case STOP_TYPE: + return; + } + } +} + +void process_var(method_self_n_params_n_locals& root, Value& self, + arcontext& arcontext, WContext& awcontext, + String_iterator& iter, Char_types& breaks) { // $name.field.subfield -- read // $name.field.subfield(constructor code) -- construct // $name.field.subfield[usage code & if none existed autoconstructed as VHash] -- use OR auto-VHash construct - Array/**/ names(pool); // what.they.refer.to left-to-right list - char names_ended_before; // the char after long name Prefix prefix; + Array/**/ names(pool); // what.they.refer.to left-to-right list + CHAR_TYPE names_ended_before; // the char type after long name get_names( - iter, " ([", + iter, var_names_breaks, &prefix, &names, &names_ended_before); // can return count()=0 when $self alone bool read_mode=name_ended_before==' '; @@ -79,9 +135,9 @@ void process_dollar(method_self_n_params } } -void process_bird(method_self_n_params_n_locals& root, Value& self, - arcontext& arcontext, WContext& awcontext, - String_iterator& iter, char char_to_stop_before) { +void process_method(method_self_n_params_n_locals& root, Value& self, + arcontext& arcontext, WContext& awcontext, + String_iterator& iter, char char_to_stop_before) { // ^name.field.subfield.method[..] -- plain call // ^name.field.subfield.method_ref[..] -- method ref call, when .get_method()!=0 @@ -90,11 +146,11 @@ void process_bird(method_self_n_params_n // 2: wcontext.object_class.has_parent('class')? -- dynamic call // 3: not -------------------------------------? -- static call - Array/**/ names(pool); // what.they.refer.to left-to-right list - char names_ended_before; // the char after long name Prefix prefix; + Array/**/ names(pool); // what.they.refer.to left-to-right list + CHAR_TYPE names_ended_before; // the char type after long name get_names( - iter, "[", + iter, method_names_breaks, &prefix, &names, &names_ended_before); // can return count()=0 when ^self alone Value *context= @@ -125,16 +181,16 @@ void process_bird(method_self_n_params_n String cn(pool); cn.append(0, ni); Class *right_class=classes.get(cn); - if(!oc) // bad: no such class + if(!right_class) // bad: no such class pool.exception().raise(cn, "call: undefined class"); Class *left_class=awcontext.get_class(); if(left_class) { if(left_class.has_parent(right_class)) // dynamic call - ; + context=awcontext.value(); // it's 'self' instance else // static call - context=right_class; + context=right_class; // 'self' := class, not instance } else { // constructor: $some(^class:method[..]) call - context=new(pool) VClass(pool, right_class); + context=new(pool) VClass(pool, right_class); // 'self' := new instance of 'class:' awcontext.write(context); } } @@ -147,31 +203,56 @@ void process_bird(method_self_n_params_n Method_ref *method_ref=value->get_method_ref(); if(!method_ref) // bad: that field wasn't method_ref pool.exception().raise(name, "call: this field is not a method reference"); - method=method_ref->method; context=method_ref->self; + method=method_ref->method; } else { // no element of that 'name', that must be operator then - method=operators.get(name); - if(!method) // bad: that 'name' is neither method nor field nor operator + Operator *op=operators.get(name); + if(!op) // bad: that 'name' is neither method nor field nor operator pool.exception().raise(name, "call: neither method nor field nor operator"); + context=op->self; + method=op; } } - Array/**/ param_values(pool); + // evaluating param values + Array/**/ param_values(pool); get_params( iter, - awcontext, + arcontext, ¶m_values); iter++; // skip ']' + // preparing contexts method_self_n_params_n_locals local_rcontext(pool, context, method->param_names, param_values, method->local_names); - WContext local_wcontext(pool, local_self); + WContext local_wcontext(pool, context); + String_iterator local_iter(method->code); + // calling method/operator process( - context, local_rcontext, + local_rcontext/* $:vars */, context /* $self.vars */, local_rcontext, local_wcontext, - iter, ']'); + local_iter, 0); awcontext.write(local_wcontext); -} \ No newline at end of file +} + + +enum Prefix { + NO_PREFIX, + ROOT_PREFIX, + SELF_PREFIX +}; +void get_names( + String_iterator& iter, Char_types& breaks, + Prefix prefix, Array& names, CHAR_TYPE& names_ended_before) { + + // can return count()=0 when $self alone +} + +void get_params( + String_iterator& iter, + Value *arcontext, + Array/**/& param_values) { +}