Annotation of parser3/src/main/core.C, revision 1.5
1.1 paf 1: void process(Pool& pool,
2: Value& self,
3: RContext& rcontext, WContext& wcontext,
1.5 ! paf 4: String_iterator& code, char char_to_stop_before) {
1.1 paf 5:
6: // $ on code?
7: process_dollar(pool, rcontext, wcontext, code, char_to_stop_before);
8:
9: // ^ on code?
10: process_bird(pool, rcontext, wcontext, code, char_to_stop_before);
1.4 paf 11:
12: // TODO
13: // 1. случаи :: и this. в начале
14: // 2. вызовы статических методов
1.1 paf 15: }
16:
17: void process_dollar(Pool& pool,
1.3 paf 18: Value& self,
1.1 paf 19: RContext& rcontext, WContext& wcontext,
1.5 ! paf 20: String_iterator& iter, char char_to_stop_before) {
1.1 paf 21:
22: // $name.field.subfield -- read
23: // $name.field.subfield(constructor code) -- construct
24: // $name.field.subfield[usage code & if none existed autoconstructed as VHash] -- use OR auto-VHash construct
25:
26: Array/*<String&>*/ names(pool); // what.they.refer.to left-to-right list
27: char names_ended_before; // the char after long name
28: get_names(
29: iter, " ([",
30: &names, &names_ended_before); // must return count()>0
31:
32: bool read_mode=name_ended_before==' ';
33: Value *context=read_mode?rcontext:wcontext;
34:
35: if(read_mode) {
1.3 paf 36: // 'context' dive into dotted path
1.1 paf 37: for(int i=0; i<names.count(); i++) {
38: context=context->get_element(static_cast<Value *>(names.get[i]));
39: if(!context) // no such object field, nothing bad, just ignore that
40: return;
41: }
42: wcontext.write(context);
43: } else { // write mode
44: iter++; // skip '(' '['
45:
46: bool construct_mode=names_ended_before=='(';
47:
1.4 paf 48: // 'context' dive into dotted path,
1.1 paf 49: int steps=names.count();
1.4 paf 50: // if constructing then "excluding last .name"
1.1 paf 51: if(construct_mode)
52: steps--;
53: for(int i=0; i<steps; i++) {
54: String& name=static_cast<String&>(names.get[i]);
55: Value *next_current=context->get_element(name);
56: if(next_current)
57: next_current=context->put_element(name, new(pool) VHash(pool));
58: context=new_current;
59: }
60:
61: if(construct_mode) {
1.3 paf 62: // .name(construct-code), processing on rcontext in empty temp wcontext
1.1 paf 63: // pure side effect, no wcontext.write here
1.3 paf 64: // last .name
1.1 paf 65: String& name=static_cast<String&>(names.get[steps]);
66: WContext local_wcontext(pool /* empty */);
67: process(pool, rcontext, local_wcontext, iter, ')');
68: context->put_element(name, local_wcontext.value());
69: } else { // =='['
1.3 paf 70: // .name[with-code], processing on 'context'
1.1 paf 71: WContext local_context(pool, context);
72: process(pool, local_context, local_context, iter, ']');
73: wcontext.write(local_context);
74: }
75:
76: iter++; // skip ')' ']'
77: }
78: }
79:
80: void process_bird(Pool& pool,
81: Value& self,
82: RContext& rcontext, WContext& wcontext,
1.5 ! paf 83: String_iterator& iter, char char_to_stop_before) {
1.1 paf 84:
85: // ^name.field.subfield.method[..] -- plain call
86: // ^name.field.subfield.method_ref[..] -- method ref call, when .get_method()!=0
87:
88: Array/*<String&>*/ names(pool); // what.they.refer.to left-to-right list
89: char names_ended_before; // the char after long name
90: get_names(
91: iter, "[",
92: &names, &names_ended_before); // must return count()>0
93:
94: Value *context=rcontext;
95: iter++; // skip '['
96:
1.3 paf 97: // 'context' dive into dotted path, excluding last .name
1.1 paf 98: Value *local_self=context;
99: int steps=names.count()-1;
100: for(int i=0; i<steps; i++) {
101: String& name=static_cast<String&>(names.get[i]);
102: context=(local_self=context)->get_element(name);
103: if(!context) // no such object field, sad story: can't call method of void
104: pool.exception().raise(name, "call: to void.method");
105: }
106:
1.3 paf 107: // last .name
1.1 paf 108: String& name=static_cast<String&>(names.get[steps]);
109: // first we're trying to locate method with that 'name'
110: Method *method=context.get_method(name);
111: if(!method) { // no such method: try to locate method ref field
112: Value *value=context.get_element(name);
113: if(!value) // failed: no element of that 'name'
114: pool.exception().raise(name, "call: no method field found");
1.5 ! paf 115: Method_ref *method_ref=value->get_method_ref();
! 116: if(!method_ref) // failed: that field wasn't method_ref
1.1 paf 117: pool.exception().raise(name, "call: this field is not a method reference");
1.5 ! paf 118: method=method_ref->method;
! 119: local_self=method_ref->self;
1.1 paf 120: }
121:
122:
123: Array/*<String&>*/ param_values(pool);
124: get_params(
125: iter, "]",
126: ¶m_values);
127: iter++; // skip ']'
128:
1.2 paf 129: Method_self_n_params local_rcontext(pool,
1.1 paf 130: local_self,
131: method->param_names, param_values);
132: WContext local_wcontext(pool /* empty */);
133: process(pool, local_rcontext, local_wcontext, iter, ']');
134: wcontext.write(local_wcontext);
135: }
E-mail: