--- parser3/src/main/Attic/core.C 2001/02/12 11:34:12 1.2 +++ parser3/src/main/Attic/core.C 2001/02/13 12:59:58 1.7 @@ -1,19 +1,20 @@ -void process(Pool& pool, - Value& self, - RContext& rcontext, WContext& wcontext, - StringIterator& code, char char_to_stop_before) { +void process(method_self_n_params_n_locals& root, Value& self, + arcontext& arcontext, WContext& awcontext, + String_iterator& code, char char_to_stop_before) { // $ on code? - process_dollar(pool, rcontext, wcontext, code, char_to_stop_before); + process_dollar(root, self, arcontext, awcontext, code, char_to_stop_before); // ^ on code? - process_bird(pool, rcontext, wcontext, code, char_to_stop_before); + process_bird(root, self, arcontext, awcontext, code, char_to_stop_before); + + // TODO + // 2. вызовы статических методов } -void process_dollar(Pool& pool, - Value& THIS, - RContext& rcontext, WContext& wcontext, - StringIterator& iter, char char_to_stop_before) { +void process_dollar(method_self_n_params_n_locals& root, Value& self, + arcontext& arcontext, WContext& awcontext, + String_iterator& iter, char char_to_stop_before) { // $name.field.subfield -- read // $name.field.subfield(constructor code) -- construct @@ -21,28 +22,36 @@ void process_dollar(Pool& pool, Array/**/ names(pool); // what.they.refer.to left-to-right list char names_ended_before; // the char after long name + Prefix prefix; get_names( iter, " ([", - &names, &names_ended_before); // must return count()>0 + &prefix, &names, &names_ended_before); // can return count()=0 when $self alone bool read_mode=name_ended_before==' '; - Value *context=read_mode?rcontext:wcontext; + Value *context= + prefix? + prefix==ROOT?root:self: + read_mode?arcontext:awcontext; if(read_mode) { + // 'context' dive into dotted path for(int i=0; iget_element(static_cast(names.get[i])); if(!context) // no such object field, nothing bad, just ignore that return; } - wcontext.write(context); + awcontext.write(context); } else { // write mode iter++; // skip '(' '[' bool construct_mode=names_ended_before=='('; + // 'context' dive into dotted path, int steps=names.count(); + // if constructing then "excluding last .name" if(construct_mode) - steps--; + if(!steps--) // bad: "$self("; now we can safely do ".get[steps]" below + pool.exception().raise("self re-construction prohibited"); for(int i=0; i(names.get[i]); Value *next_current=context->get_element(name); @@ -52,71 +61,89 @@ void process_dollar(Pool& pool, } if(construct_mode) { - // pure side effect, no wcontext.write here + // .name(construct-code), processing on arcontext in empty temp awcontext + // pure side effect, no awcontext.write here + // last .name String& name=static_cast(names.get[steps]); WContext local_wcontext(pool /* empty */); - process(pool, rcontext, local_wcontext, iter, ')'); + process(root, self, arcontext, local_wcontext, iter, ')'); context->put_element(name, local_wcontext.value()); } else { // =='[' + // .name[with-code], processing on 'context' WContext local_context(pool, context); - process(pool, local_context, local_context, iter, ']'); - wcontext.write(local_context); + process(root, self, local_context, local_context, iter, ']'); + awcontext.write(local_context); } iter++; // skip ')' ']' } } -void process_bird(Pool& pool, - Value& self, - RContext& rcontext, WContext& wcontext, - StringIterator& iter, char char_to_stop_before) { +void process_bird(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 Array/**/ names(pool); // what.they.refer.to left-to-right list char names_ended_before; // the char after long name + Prefix prefix; get_names( iter, "[", - &names, &names_ended_before); // must return count()>0 + &prefix, &names, &names_ended_before); // can return count()=0 when ^self alone - Value *context=rcontext; + Value *context= + prefix? + prefix==ROOT?root:self: + arcontext; iter++; // skip '[' - Value *local_self=context; + // 'context' dive into dotted path, excluding last .name int steps=names.count()-1; + if(steps<0) // bad: "^self["; now we can safely do ".get[steps]" below + pool.exception().raise("call: calling method named 'self'"); for(int i=0; i(names.get[i]); - context=(local_self=context)->get_element(name); + context=context->get_element(name); if(!context) // no such object field, sad story: can't call method of void pool.exception().raise(name, "call: to void.method"); } + // last .name String& name=static_cast(names.get[steps]); // first we're trying to locate method with that 'name' Method *method=context.get_method(name); if(!method) { // no such method: try to locate method ref field Value *value=context.get_element(name); - if(!value) // failed: no element of that 'name' - pool.exception().raise(name, "call: no method field found"); - method=value->get_method(); - if(!method) // failed: that field wasn't method_ref - pool.exception().raise(name, "call: this field is not a method reference"); - local_self=value->get_self(); + if(value) { // good: we have some element of that 'name' + 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; + } 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 + pool.exception().raise(name, "call: neither method nor field nor operator"); + } } Array/**/ param_values(pool); get_params( - iter, "]", + iter, ¶m_values); iter++; // skip ']' - Method_self_n_params local_rcontext(pool, - local_self, - method->param_names, param_values); - WContext local_wcontext(pool /* empty */); - process(pool, local_rcontext, local_wcontext, iter, ']'); - wcontext.write(local_wcontext); + method_self_n_params_n_locals local_rcontext(pool, + context, + method->param_names, param_values, + method->local_names); + WContext local_wcontext(pool, local_self); + process( + context, local_rcontext, + local_rcontext, local_wcontext, + iter, ']'); + awcontext.write(local_wcontext); } \ No newline at end of file