Annotation of parser3/src/include/pa_vmframe.h, revision 1.16
1.1 paf 1: /*
1.16 ! paf 2: $Id: pa_vmframe.h,v 1.15 2001/03/08 12:19:20 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++) {
! 56: my->put(
! 57: *static_cast<String *>(method.locals_names->get(i)),
! 58: NEW VUnknown(pool()));
1.1 paf 59: }
60: }
61: }
62:
1.15 paf 63: void set_self(Value& aself) { fself=&aself; }
1.1 paf 64:
65: void store_param(Value *value) {
1.16 ! paf 66: Method& method=*junction.method;
! 67: int max_params=
! 68: method.numbered_params_count?method.numbered_params_count:
! 69: method.params_names?method.params_names->size():
! 70: 0;
1.14 paf 71: if(store_param_index==max_params)
1.1 paf 72: THROW(0,0,
1.12 paf 73: &junction.self.name(),
74: "%s method '%s' accepts maximum %d parameters",
75: junction.self.type(),
1.16 ! paf 76: method.name.cstr(),
1.14 paf 77: max_params);
1.1 paf 78:
1.16 ! paf 79: if(method.numbered_params_count) { // are this method params numbered?
! 80: *fnumbered_params+=value;
! 81: } else { // named params
! 82: String& name=*static_cast<String *>(
! 83: method.params_names->get(store_param_index++));
! 84: my->put(name, value);
! 85: value->set_name(name);
! 86: }
1.1 paf 87: }
88: void fill_unspecified_params() {
1.16 ! paf 89: Method &method=*junction.method;
! 90: if(method.numbered_params_count) { // are this method params numbered?
! 91: for(; store_param_index<method.numbered_params_count; store_param_index++)
! 92: *fnumbered_params+=NEW VUnknown(pool());
! 93: } else { // named params
! 94: if(method.params_names) // there are any parameters might need filling?
! 95: for(; store_param_index<method.params_names->size(); store_param_index++)
! 96: my->put(
! 97: *static_cast<String *>(method.params_names->get(store_param_index)),
! 98: NEW VUnknown(pool()));
! 99: }
1.1 paf 100: }
101:
1.16 ! paf 102: Array& numbered_params() { return *fnumbered_params; }
! 103:
1.1 paf 104: public:
105:
106: const Junction& junction;
107:
108: private:
109: int store_param_index;
1.16 ! paf 110: Hash *my;/*OR*/Array *fnumbered_params;
1.15 paf 111: Value *fself;
1.1 paf 112:
113: };
114:
115: #endif
E-mail: