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