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