Annotation of parser3/src/types/pa_vmethod_frame.h, revision 1.12
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.12 ! parser 8: $Id: pa_vmethod_frame.h,v 1.11 2001/05/21 17:13:57 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
53: return result && result->is_defined()?result:WContext::result();
54: }
55:
56: public: // usage
57:
58: VMethodFrame(Pool& apool,
1.8 parser 59: const String& name,
1.1 paf 60: const Junction& ajunction/*info: always method-junction*/,
61: bool ais_constructor) :
62: WContext(apool, 0 /* empty */, false /* not constructing */),
63:
64: junction(ajunction),
65: is_constructor(ais_constructor),
66: store_param_index(0),
67: fself(0) {
1.9 parser 68: set_name(name);
1.1 paf 69:
70: const Method &method=*junction.method;
71:
1.3 paf 72: if(method.max_numbered_params_count) { // are this method params numbered?
73: my=0; // no named parameters
1.8 parser 74: fnumbered_params=NEW MethodParams(pool(), name); // create storage
1.3 paf 75: } else { // named params
1.1 paf 76: my=NEW Hash(pool()); // create storage
1.3 paf 77: fnumbered_params=0; // no numbered parameters
1.1 paf 78:
79: if(method.locals_names) { // are there any local var names?
80: // remember them
81: // those are flags that name is local == to be looked up in 'my'
82: for(int i=0; i<method.locals_names->size(); i++) {
83: // speedup: not checking for clash with "result" name
1.12 ! parser 84: Value *value=NEW VVoid(pool());
1.1 paf 85: const String& name=*method.locals_names->get_string(i);
86: my->put(name, value);
87: value->set_name(name);
88: }
89: }
90: { // always there is one local: $result
1.12 ! parser 91: Value *result_value=NEW VVoid(pool());
1.1 paf 92: my->put(*result_var_name, result_value);
93: result_value->set_name(*result_var_name);
94: }
95: }
96: }
97:
98: void set_self(Value& aself) { fself=&aself; }
99: Value *self() { return fself; }
100:
101: void store_param(const String& actual_method_name, Value *value) {
102: const Method& method=*junction.method;
103: int max_params=
104: method.max_numbered_params_count?method.max_numbered_params_count:
105: method.params_names?method.params_names->size():
106: 0;
107: if(store_param_index==max_params)
108: THROW(0,0,
109: &actual_method_name,
1.7 paf 110: "method of %s (%s) accepts maximum %d parameter(s)",
1.1 paf 111: junction.self.name().cstr(),
112: junction.self.type(),
113: max_params);
114:
115: if(method.max_numbered_params_count) { // are this method params numbered?
116: *fnumbered_params+=value;
117: } else { // named param
118: // speedup: not checking for clash with "result" name
119: const String& name=*method.params_names->get_string(store_param_index);
120: my->put(name, value); // remember param
121: value->set_name(name); // set param's 'name'
122: }
123: store_param_index++;
124: }
125: void fill_unspecified_params() {
126: const Method &method=*junction.method;
127: if(method.params_names) // there are any named parameters might need filling?
128: for(; store_param_index<method.params_names->size(); store_param_index++) {
1.12 ! parser 129: Value *value=NEW VVoid(pool());
1.1 paf 130: const String& name=*method.params_names->get_string(store_param_index);
131: my->put(name, value);
132: value->set_name(name);
133: }
134: }
135:
1.3 paf 136: MethodParams *numbered_params() { return fnumbered_params; }
1.1 paf 137:
138: public:
139:
140: const Junction& junction;
141: bool is_constructor;
142:
143: private:
144: int store_param_index;
1.3 paf 145: Hash *my;/*OR*/MethodParams *fnumbered_params;
1.1 paf 146: Value *fself;
147:
148: };
149:
150: #endif
E-mail: