Annotation of parser3/src/types/pa_vstateless_class.h, revision 1.80
1.6 paf 1: /** @file
2: Parser: stateless class decls.
3:
1.78 moko 4: Copyright (c) 2001-2015 Art. Lebedev Studio (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.80 ! moko 11: #define IDENT_PA_VSTATELESS_CLASS_H "$Id: pa_vstateless_class.h,v 1.79 2016/04/01 16:27:32 moko Exp $"
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.2 paf 19:
1.38 paf 20: // defines
21:
22: #define CLASS_NAME "CLASS"
1.76 misha 23: #ifndef OPTIMIZE_BYTECODE_GET_ELEMENT__SPECIAL
1.54 misha 24: #define CLASS_NAMETEXT "CLASS_NAME"
1.63 misha 25: extern const String class_name, class_nametext;
1.76 misha 26: #endif
1.38 paf 27:
28: // forwards
29:
1.43 paf 30: class VStateless_class;
1.59 misha 31: typedef Array<VStateless_class*> ArrayClass;
1.66 misha 32: typedef HashString<Property *> HashStringProperty;
33: typedef HashString<Method *> HashStringMethod;
1.43 paf 34:
1.2 paf 35: class Temp_method;
36:
1.6 paf 37: /**
1.30 paf 38: object' class. stores
39: - base: VClass::base()
40: - methods: VStateless_class::fmethods
1.6 paf 41:
1.30 paf 42: @see Method, VStateless_object, Temp_method
1.6 paf 43: */
1.39 paf 44: class VStateless_class: public Value {
1.19 paf 45: friend class Temp_method;
1.43 paf 46:
1.66 misha 47: HashStringMethod fmethods;
1.43 paf 48:
49: bool flocked;
1.57 misha 50: bool fall_vars_local;
1.61 misha 51: bool fpartial;
1.70 misha 52: Method::Call_type fcall_type;
1.43 paf 53:
54: protected:
55:
56: VStateless_class* fbase;
1.68 misha 57: /// all derived classes, recursively
1.66 misha 58: ArrayClass fderived;
59:
1.60 misha 60: Method* fscalar;
1.58 misha 61: Method* fdefault_getter;
1.71 moko 62: Method* fdefault_setter;
1.43 paf 63:
1.2 paf 64: public: // Value
65:
1.5 paf 66: /// VStateless_class: this
1.69 misha 67: override VStateless_class* get_class() { return this; }
1.41 paf 68: /// VStateless_class: fbase
1.69 misha 69: override VStateless_class* base() { return fbase; }
1.66 misha 70:
71: override Value* get_element(const String& aname) { return get_element(*this, aname); }
72: /// get_element with aself for VObject junctions
73: virtual Value* get_element(Value& aself, const String& aname);
74:
1.75 moko 75: override const VJunction* put_element(const String& aname, Value* avalue) { return put_element(*this, aname, avalue); }
1.66 misha 76: /// put_element with aself for VObject junctions
1.75 moko 77: virtual const VJunction* put_element(Value& aself, const String& aname, Value* /*avalue*/) {
1.72 moko 78: aself.bark("element can not be stored to %s", &aname);
79: return 0;
80: }
1.66 misha 81:
1.74 moko 82: override Value& as_expr_result();
1.60 misha 83:
1.66 misha 84: Value* get_scalar(Value& aself);
85: void set_scalar(Method* amethod);
1.2 paf 86:
1.66 misha 87: Value* get_default_getter(Value& aself, const String& aname);
88: void set_default_getter(Method* amethod);
1.71 moko 89: bool has_default_getter();
90:
91: VJunction* get_default_setter(Value& aself, const String& aname);
92: void set_default_setter(Method* amethod);
93: bool has_default_setter();
1.60 misha 94:
1.66 misha 95: void add_derived(VStateless_class &aclass);
1.61 misha 96:
1.2 paf 97: public: // usage
98:
1.80 ! moko 99: VStateless_class(VStateless_class* amethoded_donor=0):
1.43 paf 100: flocked(false),
1.66 misha 101: fbase(0),
102: fderived(0),
1.58 misha 103: fall_vars_local(false),
1.61 misha 104: fpartial(false),
1.60 misha 105: fscalar(0),
1.70 misha 106: fdefault_getter(0),
1.71 moko 107: fdefault_setter(0),
1.70 misha 108: fcall_type(Method::CT_ANY)
1.80 ! moko 109: {
! 110: if(amethoded_donor)
! 111: fmethods.merge_dont_replace(amethoded_donor->fmethods);
1.2 paf 112: }
113:
1.43 paf 114: void lock() { flocked=true; }
115:
116: Method* get_method(const String& aname) const {
117: return fmethods.get(aname);
1.2 paf 118: }
119:
1.66 misha 120: HashStringMethod get_methods(){
1.65 misha 121: return fmethods;
122: }
123:
1.61 misha 124: bool is_vars_local(){
125: return fall_vars_local;
126: }
127:
128: void set_all_vars_local(){
1.57 misha 129: fall_vars_local=true;
130: }
131:
1.61 misha 132: bool is_partial(){
133: return fpartial;
134: }
135:
136: void set_partial(){
137: fpartial=true;
1.57 misha 138: }
139:
1.70 misha 140: Method::Call_type get_methods_call_type(){
141: return fcall_type;
142: }
143:
144: void set_methods_call_type(Method::Call_type call_type){
145: if(fcall_type!=Method::CT_ANY)
146: throw Exception(PARSER_RUNTIME,
147: 0,
148: "You can specify call type option in a class only once"
149: );
150: fcall_type=call_type;
151: }
152:
1.2 paf 153: void add_native_method(
1.43 paf 154: const char* cstr_name,
1.9 paf 155: Method::Call_type call_type,
1.43 paf 156: NativeCodePtr native_code,
1.62 misha 157: int min_numbered_params_count,
158: int max_numbered_params_count,
159: Method::Call_optimization call_optimization=Method::CO_WITHOUT_WCONTEXT);
1.66 misha 160:
1.68 misha 161: void set_method(const String& aname, Method* amethod);
162:
1.66 misha 163: /// overrided in VClass
1.80 ! moko 164: virtual void set_type(const char *atype) {}
1.68 misha 165: virtual void real_set_method(const String& aname, Method* amethod);
1.66 misha 166: virtual HashStringProperty* get_properties(){ return 0; };
167: virtual void set_base(VStateless_class* abase);
1.2 paf 168:
1.43 paf 169: VStateless_class* base_class() { return fbase; }
1.2 paf 170:
1.66 misha 171: bool derived_from(VStateless_class& vclass){
1.77 moko 172: return fbase==&vclass || ( fbase && fbase->derived_from(vclass) );
1.31 paf 173: }
174:
1.21 paf 175: /// @returns new value for current class, used in classes/ & VClass
1.66 misha 176: virtual Value* create_new_value(Pool&) { return 0; }
1.2 paf 177: };
178:
1.6 paf 179: /// Auto-object used for temporarily substituting/removing class method
1.2 paf 180: class Temp_method {
181: VStateless_class& fclass;
182: const String& fname;
1.43 paf 183: Method* saved_method;
1.2 paf 184: public:
1.43 paf 185: Temp_method(VStateless_class& aclass, const String& aname, Method* amethod) :
1.2 paf 186: fclass(aclass),
187: fname(aname),
188: saved_method(aclass.get_method(aname)) {
1.67 misha 189: fclass.set_method(aname, amethod);
1.2 paf 190: }
191: ~Temp_method() {
1.67 misha 192: fclass.set_method(fname, saved_method);
1.2 paf 193: }
194: };
195:
196: #endif
E-mail: