Annotation of parser3/src/types/pa_vstateless_class.h, revision 1.62
1.6 paf 1: /** @file
2: Parser: stateless class decls.
3:
1.62 ! misha 4: Copyright (c) 2001-2009 ArtLebedev Group (http://www.artlebedev.com)
1.23 paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.2 paf 6: */
7:
8: #ifndef PA_VSTATELESS_CLASS_H
9: #define PA_VSTATELESS_CLASS_H
1.27 paf 10:
1.62 ! misha 11: static const char * const IDENT_VSTATELESS_CLASS_H="$Date: 2008-09-02 16:14:38 $";
1.43 paf 12:
13: // include
1.2 paf 14:
1.45 paf 15: #include "pa_pool.h"
1.13 paf 16: #include "pa_hash.h"
1.2 paf 17: #include "pa_vjunction.h"
1.43 paf 18: #include "pa_method.h"
1.49 paf 19: #include "pa_vproperty.h"
1.2 paf 20:
1.38 paf 21: // defines
22:
23: #define CLASS_NAME "CLASS"
1.54 misha 24: #define CLASS_NAMETEXT "CLASS_NAME"
1.38 paf 25:
26: // forwards
27:
1.43 paf 28: class VStateless_class;
1.59 misha 29: typedef Array<VStateless_class*> ArrayClass;
1.43 paf 30:
1.2 paf 31: class Temp_method;
32:
1.6 paf 33: /**
1.30 paf 34: object' class. stores
35: - base: VClass::base()
36: - methods: VStateless_class::fmethods
1.6 paf 37:
1.30 paf 38: @see Method, VStateless_object, Temp_method
1.6 paf 39: */
1.39 paf 40: class VStateless_class: public Value {
1.19 paf 41: friend class Temp_method;
1.43 paf 42:
43: const String* fname;
44: mutable const char* fname_cstr;
1.44 paf 45: Hash<const String::Body, Method*> fmethods;
1.43 paf 46:
47: bool flocked;
1.57 misha 48: bool fall_vars_local;
1.61 misha 49: bool fpartial;
1.43 paf 50:
51: protected:
52:
53: VStateless_class* fbase;
1.60 misha 54: Method* fscalar;
1.58 misha 55: Method* fdefault_getter;
1.61 misha 56: Method* fdefault_setter;
1.43 paf 57:
1.2 paf 58: public: // Value
59:
1.43 paf 60: const char* type() const { return "stateless_class"; }
1.2 paf 61:
1.5 paf 62: /// VStateless_class: this
1.43 paf 63: override VStateless_class *get_class() { return this; }
1.41 paf 64: /// VStateless_class: fbase
1.43 paf 65: override Value* base() { return fbase; }
1.58 misha 66: override Value* get_element(const String& aname, Value& aself, bool alooking_up);
1.55 misha 67: override Value& as_expr_result(bool /*return_string_as_is=false*/);
1.60 misha 68:
1.58 misha 69: override Value* get_default_getter(Value& aself, const String& aname);
70: override void set_default_getter(Method* amethod);
1.2 paf 71:
1.60 misha 72: override Value* get_scalar(Value& aself);
73: override void set_scalar(Method* amethod);
74:
1.61 misha 75: override VJunction* get_default_setter(Value& aself, const String& aname);
76: override void set_default_setter(Method* amethod);
77:
1.2 paf 78: public: // usage
79:
1.43 paf 80: VStateless_class(
81: const String* aname=0,
82: VStateless_class* abase=0):
1.24 paf 83: fname(aname),
1.43 paf 84: flocked(false),
1.57 misha 85: fbase(abase),
1.58 misha 86: fall_vars_local(false),
1.61 misha 87: fpartial(false),
1.60 misha 88: fscalar(0),
1.61 misha 89: fdefault_getter(0),
90: fdefault_setter(0)
91: {
1.2 paf 92: }
93:
1.43 paf 94: void lock() { flocked=true; }
95:
1.24 paf 96: const String& name() const {
97: if(!fname) {
98: if(fbase)
99: return fbase->name();
100:
1.56 misha 101: throw Exception(PARSER_RUNTIME,
1.24 paf 102: 0,
103: "getting name of nameless class");
104: }
105:
106: return *fname;
107: }
1.43 paf 108: const char* name_cstr() const{
109: if(this) {
110: if(!fname_cstr) // remembering last calculated, and can't reassign 'fname_cstr'!
111: fname_cstr=name().cstr();
112: return fname_cstr;
113: } else
114: return "<unknown>";
1.24 paf 115: }
1.61 misha 116:
1.24 paf 117: void set_name(const String& aname) {
118: fname=&aname;
119: }
120:
1.43 paf 121: Method* get_method(const String& aname) const {
122: return fmethods.get(aname);
1.2 paf 123: }
124:
1.61 misha 125: bool is_vars_local(){
126: return fall_vars_local;
127: }
128:
129: void set_all_vars_local(){
1.57 misha 130: fall_vars_local=true;
131: }
132:
1.61 misha 133: bool is_partial(){
134: return fpartial;
135: }
136:
137: void set_partial(){
138: fpartial=true;
1.57 misha 139: }
140:
1.51 paf 141: /// virtual for VClass to override to pre-cache property accessors into fields
142: virtual void add_method(const String& name, Method& method);
1.40 paf 143:
1.2 paf 144: void add_native_method(
1.43 paf 145: const char* cstr_name,
1.9 paf 146: Method::Call_type call_type,
1.43 paf 147: NativeCodePtr native_code,
1.62 ! misha 148: int min_numbered_params_count,
! 149: int max_numbered_params_count,
! 150: Method::Call_optimization call_optimization=Method::CO_WITHOUT_WCONTEXT);
1.2 paf 151:
1.43 paf 152: void set_base(VStateless_class* abase) {
1.2 paf 153: // remember the guy
1.32 paf 154: fbase=abase;
1.2 paf 155: }
1.43 paf 156: VStateless_class* base_class() { return fbase; }
1.2 paf 157:
1.30 paf 158: bool derived_from(VStateless_class& vclass) {
1.2 paf 159: return
1.30 paf 160: fbase==&vclass ||
161: fbase && fbase->derived_from(vclass);
1.31 paf 162: }
163:
1.11 paf 164: //@{
165: /// @name just stubs, real onces defined below the hierarchy
1.43 paf 166: virtual Value* get_field(const String&) { return 0; }
167: virtual bool replace_field(const String&, Value*) { return false; }
1.21 paf 168: //@}
169:
170: /// @returns new value for current class, used in classes/ & VClass
1.52 paf 171: virtual Value* create_new_value(Pool&, HashStringValue& /*afields*/) { return 0; }
1.50 paf 172:
173: protected:
174:
175: void fill_properties(HashStringValue& acache);
1.2 paf 176:
1.49 paf 177: private:
1.2 paf 178:
1.49 paf 179: void put_method(const String& aname, Method* amethod);
1.2 paf 180: };
181:
1.6 paf 182: /// Auto-object used for temporarily substituting/removing class method
1.2 paf 183: class Temp_method {
184: VStateless_class& fclass;
185: const String& fname;
1.43 paf 186: Method* saved_method;
1.2 paf 187: public:
1.43 paf 188: Temp_method(VStateless_class& aclass, const String& aname, Method* amethod) :
1.2 paf 189: fclass(aclass),
190: fname(aname),
191: saved_method(aclass.get_method(aname)) {
192: fclass.put_method(aname, amethod);
193: }
194: ~Temp_method() {
195: fclass.put_method(fname, saved_method);
196: }
197: };
198:
199: #endif
E-mail: