Annotation of parser3/src/include/pa_vmframe.h, revision 1.22
1.1 paf 1: /*
1.22 ! paf 2: $Id: pa_vmframe.h,v 1.21 2001/03/09 08:19:47 paf Exp $
1.1 paf 3: */
4:
5: #ifndef PA_VMFRAME_H
6: #define PA_VMFRAME_H
7:
8: #include "pa_wcontext.h"
9: #include "pa_vunknown.h"
10: #include "pa_vjunction.h"
11:
12: class VMethodFrame : public WContext {
13: public: // Value
14:
15: // all: for error reporting after fail(), etc
1.11 paf 16: const char *type() const { return "method_frame"; }
1.1 paf 17: // frame: my or self_transparent
1.13 paf 18: Value *get_element(const String& name) {
1.20 paf 19: if(my) {
20: Value *result=static_cast<Value *>(my->get(name));
21: if(result)
22: return result;
23: }
24: return fself->get_element(name);
1.1 paf 25: }
26: // frame: my or self_transparent
27: void put_element(const String& name, Value *value){
1.20 paf 28: if(!(my && my->put_replace(name, value)))
1.15 paf 29: fself->put_element(name, value);
1.1 paf 30: }
31:
1.6 paf 32: // frame: self_transparent
1.15 paf 33: VClass* get_class() { return fself->get_class(); }
1.6 paf 34:
1.8 paf 35: // methodframe: self_transparent
1.15 paf 36: VAliased *get_aliased() { return fself->get_aliased(); }
1.7 paf 37:
1.1 paf 38: public: // usage
39:
1.16 paf 40: VMethodFrame(Pool& apool, const Junction& ajunction/*info: always method-junction*/) :
1.5 paf 41: WContext(apool, 0 /* empty */, false /* not constructing */),
42:
1.1 paf 43: junction(ajunction),
44: store_param_index(0),
1.21 paf 45: my(0), fnumbered_params(0),
46: fself(0) {
1.16 paf 47:
48: Method &method=*junction.method;
49:
1.21 paf 50: if(method.max_numbered_params_count) // are this method params numbered?
1.16 paf 51: fnumbered_params=NEW Array(pool()); // create storage
52: else // named params
53: my=NEW Hash(pool()); // create storage
54:
55: if(method.locals_names) { // there are any local var names?
56: // remember them
57: // those are flags that name is local == to be looked up in 'my'
58: for(int i=0; i<method.locals_names->size(); i++) {
1.17 paf 59: Value *value=NEW VUnknown(pool());
60: String& name=*static_cast<String *>(method.locals_names->get(i));
1.22 ! paf 61: my->put(name, value);
1.17 paf 62: value->set_name(name);
1.1 paf 63: }
64: }
65: }
66:
1.15 paf 67: void set_self(Value& aself) { fself=&aself; }
1.1 paf 68:
69: void store_param(Value *value) {
1.16 paf 70: Method& method=*junction.method;
71: int max_params=
1.21 paf 72: method.max_numbered_params_count?method.max_numbered_params_count:
1.16 paf 73: method.params_names?method.params_names->size():
74: 0;
1.14 paf 75: if(store_param_index==max_params)
1.1 paf 76: THROW(0,0,
1.12 paf 77: &junction.self.name(),
1.21 paf 78: "(%s) method '%s' accepts maximum %d parameter(s)",
1.12 paf 79: junction.self.type(),
1.16 paf 80: method.name.cstr(),
1.14 paf 81: max_params);
1.1 paf 82:
1.21 paf 83: if(method.max_numbered_params_count) { // are this method params numbered?
1.16 paf 84: *fnumbered_params+=value;
1.18 paf 85: } else { // named param
1.16 paf 86: String& name=*static_cast<String *>(
87: method.params_names->get(store_param_index++));
1.19 paf 88: my->put(name, value); // remember param
89: value->set_name(name); // set param's 'name'
1.16 paf 90: }
1.1 paf 91: }
92: void fill_unspecified_params() {
1.16 paf 93: Method &method=*junction.method;
1.21 paf 94: if(method.params_names) // there are any named parameters might need filling?
95: for(; store_param_index<method.params_names->size(); store_param_index++) {
1.17 paf 96: Value *value=NEW VUnknown(pool());
1.21 paf 97: String& name=*static_cast<String *>(
98: method.params_names->get(store_param_index));
1.22 ! paf 99: my->put(name, value);
1.21 paf 100: value->set_name(name);
1.17 paf 101: }
1.1 paf 102: }
103:
1.21 paf 104: Array *numbered_params() { return fnumbered_params; }
1.16 paf 105:
1.1 paf 106: public:
107:
108: const Junction& junction;
109:
110: private:
111: int store_param_index;
1.16 paf 112: Hash *my;/*OR*/Array *fnumbered_params;
1.15 paf 113: Value *fself;
1.1 paf 114:
115: };
116:
117: #endif
E-mail: