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