Annotation of parser3/src/types/pa_vmethod_frame.h, revision 1.15
1.3 paf 1: /** @file
1.5 paf 2: Parser: @b method_frame write context
1.3 paf 3:
1.1 paf 4: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.3 paf 5:
1.1 paf 6: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
7:
1.15 ! parser 8: $Id: pa_vmethod_frame.h,v 1.14 2001/07/26 12:25:37 parser Exp $
1.1 paf 9: */
10:
11: #ifndef PA_VMETHOD_FRAME_H
12: #define PA_VMETHOD_FRAME_H
13:
14: #include "pa_wcontext.h"
1.12 parser 15: #include "pa_vvoid.h"
1.1 paf 16: #include "pa_vjunction.h"
17:
1.4 paf 18: /** Method frame write context
19: accepts values written by method code
20: also handles method parameters and local variables
1.3 paf 21: */
1.1 paf 22: class VMethodFrame : public WContext {
23: public: // Value
24:
25: const char *type() const { return "method_frame"; }
1.4 paf 26: /// VMethodFrame: my or self_transparent
1.1 paf 27: Value *get_element(const String& name) {
28: if(my) {
29: Value *result=static_cast<Value *>(my->get(name));
30: if(result)
31: return result;
32: }
33: return fself->get_element(name);
34: }
1.4 paf 35: /// VMethodFrame: my or self_transparent
1.1 paf 36: void put_element(const String& name, Value *value){
37: if(!(my && my->put_replace(name, value)))
38: fself->put_element(name, value);
39: }
40:
1.4 paf 41: /// VMethodFrame: self_transparent
1.1 paf 42: VStateless_class* get_class() { return fself->get_class(); }
43:
1.4 paf 44: /// VMethodFrame: self_transparent
1.1 paf 45: VAliased *get_aliased() { return fself->get_aliased(); }
46:
47: public: // wcontext
48:
49: Value *result() {
50: // check the $result value
51: Value *result=my?static_cast<Value*>(my->get(*result_var_name)):0;
52: // if we have one, return it, else return as usual: accumulated fstring or fvalue
1.15 ! parser 53: return result && (result!=fresult_initial_void) ?result:WContext::result();
1.1 paf 54: }
55:
56: public: // usage
57:
58: VMethodFrame(Pool& apool,
1.8 parser 59: const String& name,
1.13 parser 60: const Junction& ajunction/*info: always method-junction*/) :
1.14 parser 61: WContext(apool, 0 /* empty */),
1.1 paf 62:
63: junction(ajunction),
64: store_param_index(0),
1.15 ! parser 65: fself(0),
! 66: fresult_initial_void(0) {
1.9 parser 67: set_name(name);
1.1 paf 68:
69: const Method &method=*junction.method;
70:
1.3 paf 71: if(method.max_numbered_params_count) { // are this method params numbered?
72: my=0; // no named parameters
1.8 parser 73: fnumbered_params=NEW MethodParams(pool(), name); // create storage
1.3 paf 74: } else { // named params
1.1 paf 75: my=NEW Hash(pool()); // create storage
1.3 paf 76: fnumbered_params=0; // no numbered parameters
1.1 paf 77:
78: if(method.locals_names) { // are there any local var names?
79: // remember them
80: // those are flags that name is local == to be looked up in 'my'
81: for(int i=0; i<method.locals_names->size(); i++) {
82: // speedup: not checking for clash with "result" name
1.12 parser 83: Value *value=NEW VVoid(pool());
1.1 paf 84: const String& name=*method.locals_names->get_string(i);
85: my->put(name, value);
86: value->set_name(name);
87: }
88: }
89: { // always there is one local: $result
1.15 ! parser 90: fresult_initial_void=NEW VVoid(pool());
! 91: my->put(*result_var_name, fresult_initial_void);
! 92: fresult_initial_void->set_name(*result_var_name);
1.1 paf 93: }
94: }
95: }
96:
97: void set_self(Value& aself) { fself=&aself; }
98: Value *self() { return fself; }
99:
100: void store_param(const String& actual_method_name, Value *value) {
101: const Method& method=*junction.method;
102: int max_params=
103: method.max_numbered_params_count?method.max_numbered_params_count:
104: method.params_names?method.params_names->size():
105: 0;
106: if(store_param_index==max_params)
107: THROW(0,0,
108: &actual_method_name,
1.7 paf 109: "method of %s (%s) accepts maximum %d parameter(s)",
1.1 paf 110: junction.self.name().cstr(),
111: junction.self.type(),
112: max_params);
113:
114: if(method.max_numbered_params_count) { // are this method params numbered?
115: *fnumbered_params+=value;
116: } else { // named param
117: // speedup: not checking for clash with "result" name
118: const String& name=*method.params_names->get_string(store_param_index);
119: my->put(name, value); // remember param
120: value->set_name(name); // set param's 'name'
121: }
122: store_param_index++;
123: }
124: void fill_unspecified_params() {
125: const Method &method=*junction.method;
126: if(method.params_names) // there are any named parameters might need filling?
127: for(; store_param_index<method.params_names->size(); store_param_index++) {
1.12 parser 128: Value *value=NEW VVoid(pool());
1.1 paf 129: const String& name=*method.params_names->get_string(store_param_index);
130: my->put(name, value);
131: value->set_name(name);
132: }
133: }
134:
1.3 paf 135: MethodParams *numbered_params() { return fnumbered_params; }
1.1 paf 136:
137: public:
138:
139: const Junction& junction;
140:
141: private:
142: int store_param_index;
1.3 paf 143: Hash *my;/*OR*/MethodParams *fnumbered_params;
1.1 paf 144: Value *fself;
1.15 ! parser 145:
! 146: private:
! 147: Value *fresult_initial_void;
1.1 paf 148:
149: };
150:
151: #endif
E-mail: