Annotation of parser3/src/types/pa_vstateless_class.C, revision 1.60
1.8 paf 1: /** @file
2: Parser: stateless class.
3:
1.60 ! moko 4: Copyright (c) 2001-2017 Art. Lebedev Studio (http://www.artlebedev.com)
1.13 paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)\
1.14 paf 6: */
1.8 paf 7:
1.2 paf 8: #include "pa_vstateless_class.h"
1.29 misha 9: #include "pa_vstring.h"
1.30 misha 10: #include "pa_vbool.h"
1.55 moko 11: #include "pa_symbols.h"
1.45 moko 12: #include "pa_request.h"
1.30 misha 13:
1.60 ! moko 14: volatile const char * IDENT_PA_VSTATELESS_CLASS_C="$Id: pa_vstateless_class.C,v 1.59 2016/09/26 20:22:33 moko Exp $" IDENT_PA_VSTATELESS_CLASS_H IDENT_PA_METHOD_H;
1.41 misha 15:
1.48 moko 16: override Value& VStateless_class::as_expr_result() {
1.35 misha 17: return VBool::get(as_bool());
1.30 misha 18: }
1.17 paf 19:
1.43 misha 20: /// @TODO why?! request must be different ptr from global [used in VStateless_class.set_method]
21: void VStateless_class::set_method(const String& aname, Method* amethod) {
1.20 paf 22: if(flocked)
1.58 moko 23: throw Exception(PARSER_RUNTIME, &aname, "can not add method to system class (maybe you have forgotten .CLASS in ^process[$caller.CLASS]{...}?)");
1.20 paf 24:
1.58 moko 25: if(fderived.count() && aname != auto_method_name) {
1.43 misha 26: Method *omethod=fmethods.get(aname);
27: Array_iterator<VStateless_class *> i(fderived);
28: while(i.has_next()) {
29: VStateless_class *c=i.next();
30: if(c->fmethods.get(aname)==omethod)
1.44 misha 31: c->real_set_method(aname, amethod);
1.43 misha 32: }
33: }
1.44 misha 34: real_set_method(aname, amethod);
35: }
36:
37: void VStateless_class::real_set_method(const String& aname, Method* amethod) {
1.56 moko 38: #ifdef SYMBOLS_CACHING
39: // instance() as called from static constuctors
1.55 moko 40: Symbols::instance().add(aname);
1.56 moko 41: #endif
1.44 misha 42: fmethods.put(aname, amethod);
1.59 moko 43: if(amethod)
44: amethod->name=&aname;
1.17 paf 45: }
1.2 paf 46:
47: void VStateless_class::add_native_method(
1.20 paf 48: const char* cstr_name,
1.7 paf 49: Method::Call_type call_type,
1.20 paf 50: NativeCodePtr native_code,
1.38 misha 51: int min_numbered_params_count,
1.40 misha 52: int max_numbered_params_count,
53: Method::Call_optimization
54: #ifdef OPTIMIZE_CALL
55: call_optimization
56: #endif
57: ) {
1.2 paf 58:
1.43 misha 59: Method* method=new Method(
1.7 paf 60: call_type,
1.2 paf 61: min_numbered_params_count, max_numbered_params_count,
62: 0/*params_names*/, 0/*locals_names*/,
1.40 misha 63: 0/*parser_code*/, native_code, false/*all_vars_local*/
64: #ifdef OPTIMIZE_RESULT
65: , Method::RO_USE_WCONTEXT
66: #endif
67: #ifdef OPTIMIZE_CALL
68: , call_optimization
69: #endif
70: );
1.39 misha 71:
1.43 misha 72: set_method(*new String(cstr_name), method);
1.16 paf 73: }
74:
1.51 misha 75: /// VStateless_class: $method
1.42 misha 76: Value* VStateless_class::get_element(Value& aself, const String& aname) {
1.51 misha 77: #ifndef OPTIMIZE_BYTECODE_GET_ELEMENT__SPECIAL
1.16 paf 78: // $CLASS
1.57 moko 79: if(SYMBOLS_EQ(aname,CLASS_SYMBOL))
1.16 paf 80: return this;
1.36 misha 81:
1.29 misha 82: // $CLASS_NAME
1.57 moko 83: if(SYMBOLS_EQ(aname,CLASS_NAME_SYMBOL))
1.53 moko 84: return new VString(*new String(type()));
1.51 misha 85: #endif
1.36 misha 86:
1.16 paf 87: // $method=junction(self+class+method)
1.49 misha 88: if(Method* method=get_method(aname))
89: return method->get_vjunction(aself);
1.18 paf 90:
1.42 misha 91: return 0;
92: }
93:
94: Value* VStateless_class::get_scalar(Value& aself){
95: if(fscalar)
96: return new VJunction(aself, fscalar, true /*getter*/);
1.16 paf 97: return 0;
1.23 paf 98: }
99:
1.42 misha 100: void VStateless_class::set_scalar(Method* amethod){
101: fscalar=amethod;
1.2 paf 102: }
1.32 misha 103:
104: Value* VStateless_class::get_default_getter(Value& aself, const String& aname){
1.46 moko 105: if(fdefault_getter && aself.is_enabled_default_getter())
1.32 misha 106: return new VJunction(aself, fdefault_getter, true /*getter*/, (String*)&aname);
107: return 0;
108: }
109:
110: void VStateless_class::set_default_getter(Method* amethod){
111: fdefault_getter=amethod;
112: }
113:
1.46 moko 114: bool VStateless_class::has_default_getter(){
115: return fdefault_getter != NULL;
116: }
117:
118: VJunction* VStateless_class::get_default_setter(Value& aself, const String& aname){
1.50 moko 119: if(fdefault_setter && aself.is_enabled_default_setter())
1.46 moko 120: return new VJunction(aself, fdefault_setter, false /*setter*/, (String*)&aname);
121: return 0;
122: }
123:
124: void VStateless_class::set_default_setter(Method* amethod){
125: fdefault_setter=amethod;
126: }
127:
128: bool VStateless_class::has_default_setter(){
129: return fdefault_setter != NULL;
130: }
131:
1.42 misha 132: void VStateless_class::set_base(VStateless_class* abase){
133: if(abase){
134: fbase=abase;
135: fbase->add_derived(*this);
136:
1.45 moko 137: bool no_auto = fmethods.get(auto_method_name) == NULL;
1.42 misha 138: // we assume there is no derivatives at this point
139: fmethods.merge_dont_replace(abase->fmethods);
1.45 moko 140: // we don't want to inherit @auto (issue #75)
141: if (no_auto) fmethods.remove(auto_method_name);
1.42 misha 142:
143: if(fbase->fscalar && !fscalar)
144: fscalar=fbase->fscalar;
145: if(fbase->fdefault_getter && !fdefault_getter)
146: fdefault_getter=fbase->fdefault_getter;
1.46 moko 147: if(fbase->fdefault_setter && !fdefault_setter)
148: fdefault_setter=fbase->fdefault_setter;
1.42 misha 149: }
1.33 misha 150: }
151:
1.42 misha 152: void VStateless_class::add_derived(VStateless_class &aclass){
153: fderived+=&aclass;
154: if (fbase)
155: fbase->add_derived(aclass);
1.34 misha 156: }
E-mail: