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