Annotation of parser3/src/types/pa_vstateless_class.h, revision 1.79
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.79 ! moko 11: #define IDENT_PA_VSTATELESS_CLASS_H "$Id: pa_vstateless_class.h,v 1.78 2015/10/26 01:22:02 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.79 ! moko 47: const char* ftype;
1.66 misha 48: HashStringMethod fmethods;
1.43 paf 49:
50: bool flocked;
1.57 misha 51: bool fall_vars_local;
1.61 misha 52: bool fpartial;
1.70 misha 53: Method::Call_type fcall_type;
1.43 paf 54:
55: protected:
56:
57: VStateless_class* fbase;
1.68 misha 58: /// all derived classes, recursively
1.66 misha 59: ArrayClass fderived;
60:
1.60 misha 61: Method* fscalar;
1.58 misha 62: Method* fdefault_getter;
1.71 moko 63: Method* fdefault_setter;
1.43 paf 64:
1.2 paf 65: public: // Value
66:
1.79 ! moko 67: const char* type() const {
! 68: if(!ftype)
! 69: throw Exception(PARSER_RUNTIME, 0, "getting type of nameless class");
! 70: return ftype;
! 71: }
1.2 paf 72:
1.5 paf 73: /// VStateless_class: this
1.69 misha 74: override VStateless_class* get_class() { return this; }
1.41 paf 75: /// VStateless_class: fbase
1.69 misha 76: override VStateless_class* base() { return fbase; }
1.66 misha 77:
78: override Value* get_element(const String& aname) { return get_element(*this, aname); }
79: /// get_element with aself for VObject junctions
80: virtual Value* get_element(Value& aself, const String& aname);
81:
1.75 moko 82: override const VJunction* put_element(const String& aname, Value* avalue) { return put_element(*this, aname, avalue); }
1.66 misha 83: /// put_element with aself for VObject junctions
1.75 moko 84: virtual const VJunction* put_element(Value& aself, const String& aname, Value* /*avalue*/) {
1.72 moko 85: aself.bark("element can not be stored to %s", &aname);
86: return 0;
87: }
1.66 misha 88:
1.74 moko 89: override Value& as_expr_result();
1.60 misha 90:
1.66 misha 91: Value* get_scalar(Value& aself);
92: void set_scalar(Method* amethod);
1.2 paf 93:
1.66 misha 94: Value* get_default_getter(Value& aself, const String& aname);
95: void set_default_getter(Method* amethod);
1.71 moko 96: bool has_default_getter();
97:
98: VJunction* get_default_setter(Value& aself, const String& aname);
99: void set_default_setter(Method* amethod);
100: bool has_default_setter();
1.60 misha 101:
1.66 misha 102: void add_derived(VStateless_class &aclass);
1.61 misha 103:
1.2 paf 104: public: // usage
105:
1.43 paf 106: VStateless_class(
1.79 ! moko 107: const char* atype=0,
1.43 paf 108: VStateless_class* abase=0):
1.79 ! moko 109: ftype(atype),
1.43 paf 110: flocked(false),
1.66 misha 111: fbase(0),
112: fderived(0),
1.58 misha 113: fall_vars_local(false),
1.61 misha 114: fpartial(false),
1.60 misha 115: fscalar(0),
1.70 misha 116: fdefault_getter(0),
1.71 moko 117: fdefault_setter(0),
1.70 misha 118: fcall_type(Method::CT_ANY)
1.61 misha 119: {
1.66 misha 120: set_base(abase);
1.2 paf 121: }
122:
1.43 paf 123: void lock() { flocked=true; }
124:
1.79 ! moko 125: void set_type(const char *atype) {
! 126: ftype=atype;
1.24 paf 127: }
128:
1.43 paf 129: Method* get_method(const String& aname) const {
130: return fmethods.get(aname);
1.2 paf 131: }
132:
1.66 misha 133: HashStringMethod get_methods(){
1.65 misha 134: return fmethods;
135: }
136:
1.61 misha 137: bool is_vars_local(){
138: return fall_vars_local;
139: }
140:
141: void set_all_vars_local(){
1.57 misha 142: fall_vars_local=true;
143: }
144:
1.61 misha 145: bool is_partial(){
146: return fpartial;
147: }
148:
149: void set_partial(){
150: fpartial=true;
1.57 misha 151: }
152:
1.70 misha 153: Method::Call_type get_methods_call_type(){
154: return fcall_type;
155: }
156:
157: void set_methods_call_type(Method::Call_type call_type){
158: if(fcall_type!=Method::CT_ANY)
159: throw Exception(PARSER_RUNTIME,
160: 0,
161: "You can specify call type option in a class only once"
162: );
163: fcall_type=call_type;
164: }
165:
1.2 paf 166: void add_native_method(
1.43 paf 167: const char* cstr_name,
1.9 paf 168: Method::Call_type call_type,
1.43 paf 169: NativeCodePtr native_code,
1.62 misha 170: int min_numbered_params_count,
171: int max_numbered_params_count,
172: Method::Call_optimization call_optimization=Method::CO_WITHOUT_WCONTEXT);
1.66 misha 173:
1.68 misha 174: void set_method(const String& aname, Method* amethod);
175:
1.66 misha 176: /// overrided in VClass
1.68 misha 177: virtual void real_set_method(const String& aname, Method* amethod);
1.66 misha 178: virtual HashStringProperty* get_properties(){ return 0; };
179: virtual void set_base(VStateless_class* abase);
1.2 paf 180:
1.43 paf 181: VStateless_class* base_class() { return fbase; }
1.2 paf 182:
1.66 misha 183: bool derived_from(VStateless_class& vclass){
1.77 moko 184: return fbase==&vclass || ( fbase && fbase->derived_from(vclass) );
1.31 paf 185: }
186:
1.21 paf 187: /// @returns new value for current class, used in classes/ & VClass
1.66 misha 188: virtual Value* create_new_value(Pool&) { return 0; }
1.2 paf 189: };
190:
1.6 paf 191: /// Auto-object used for temporarily substituting/removing class method
1.2 paf 192: class Temp_method {
193: VStateless_class& fclass;
194: const String& fname;
1.43 paf 195: Method* saved_method;
1.2 paf 196: public:
1.43 paf 197: Temp_method(VStateless_class& aclass, const String& aname, Method* amethod) :
1.2 paf 198: fclass(aclass),
199: fname(aname),
200: saved_method(aclass.get_method(aname)) {
1.67 misha 201: fclass.set_method(aname, amethod);
1.2 paf 202: }
203: ~Temp_method() {
1.67 misha 204: fclass.set_method(fname, saved_method);
1.2 paf 205: }
206: };
207:
208: #endif
E-mail: