Annotation of parser3/src/types/pa_vstateless_class.C, revision 1.45
1.8 paf 1: /** @file
2: Parser: stateless class.
3:
1.35 misha 4: Copyright (c) 2001-2009 ArtLebedev Group (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.45 ! moko 8: static const char * const IDENT_VSTATELESS_CLASS_C="$Date: 2009-08-11 23:54:29 $";
1.2 paf 9:
10: #include "pa_vstateless_class.h"
1.29 misha 11: #include "pa_vstring.h"
1.30 misha 12: #include "pa_vbool.h"
1.45 ! moko 13: #include "pa_request.h"
1.30 misha 14:
1.41 misha 15: /// globals
16: const String class_name(CLASS_NAME), class_nametext(CLASS_NAMETEXT);
17:
1.30 misha 18: override Value& VStateless_class::as_expr_result(bool /*return_string_as_is=false*/) {
1.35 misha 19: return VBool::get(as_bool());
1.30 misha 20: }
1.17 paf 21:
1.43 misha 22: /// @TODO why?! request must be different ptr from global [used in VStateless_class.set_method]
23: void VStateless_class::set_method(const String& aname, Method* amethod) {
1.20 paf 24: if(flocked)
1.31 misha 25: throw Exception(PARSER_RUNTIME,
1.42 misha 26: &aname,
1.17 paf 27: "can not add method to system class (maybe you have forgotten .CLASS in ^process[$caller.CLASS]{...}?)");
1.20 paf 28:
1.43 misha 29: if(fderived.count()) {
30: Method *omethod=fmethods.get(aname);
31: Array_iterator<VStateless_class *> i(fderived);
32: while(i.has_next()) {
33: VStateless_class *c=i.next();
34: if(c->fmethods.get(aname)==omethod)
1.44 misha 35: c->real_set_method(aname, amethod);
1.43 misha 36: }
37: }
1.44 misha 38: real_set_method(aname, amethod);
39: }
40:
41: void VStateless_class::real_set_method(const String& aname, Method* amethod) {
42: fmethods.put(aname, amethod);
1.17 paf 43: }
1.2 paf 44:
45: void VStateless_class::add_native_method(
1.20 paf 46: const char* cstr_name,
1.7 paf 47: Method::Call_type call_type,
1.20 paf 48: NativeCodePtr native_code,
1.38 misha 49: int min_numbered_params_count,
1.40 misha 50: int max_numbered_params_count,
51: Method::Call_optimization
52: #ifdef OPTIMIZE_CALL
53: call_optimization
54: #endif
55: ) {
1.2 paf 56:
1.43 misha 57: Method* method=new Method(
1.7 paf 58: call_type,
1.2 paf 59: min_numbered_params_count, max_numbered_params_count,
60: 0/*params_names*/, 0/*locals_names*/,
1.40 misha 61: 0/*parser_code*/, native_code, false/*all_vars_local*/
62: #ifdef OPTIMIZE_RESULT
63: , Method::RO_USE_WCONTEXT
64: #endif
65: #ifdef OPTIMIZE_CALL
66: , call_optimization
67: #endif
68: );
1.39 misha 69:
1.43 misha 70: set_method(*new String(cstr_name), method);
1.16 paf 71: }
72:
1.30 misha 73: /// VStateless_class: $CLASS, $CLASS_NAME, $method
1.42 misha 74: Value* VStateless_class::get_element(Value& aself, const String& aname) {
1.16 paf 75: // $CLASS
1.41 misha 76: if(aname==class_name)
1.16 paf 77: return this;
1.36 misha 78:
1.29 misha 79: // $CLASS_NAME
1.41 misha 80: if(aname==class_nametext)
1.42 misha 81: return new VString(name());
1.36 misha 82:
1.16 paf 83: // $method=junction(self+class+method)
1.36 misha 84: if(Method* method=get_method(aname)){
85: if(!method->junction_template)
86: return method->junction_template=new VJunction(aself, method);
1.37 misha 87: return method->junction_template->get(aself);
1.36 misha 88: }
1.18 paf 89:
1.42 misha 90: return 0;
91: }
92:
93: Value* VStateless_class::get_scalar(Value& aself){
94: if(fscalar)
95: return new VJunction(aself, fscalar, true /*getter*/);
1.16 paf 96: return 0;
1.23 paf 97: }
98:
1.42 misha 99: void VStateless_class::set_scalar(Method* amethod){
100: fscalar=amethod;
1.2 paf 101: }
1.32 misha 102:
103: Value* VStateless_class::get_default_getter(Value& aself, const String& aname){
104: if(fdefault_getter)
105: return new VJunction(aself, fdefault_getter, true /*getter*/, (String*)&aname);
106: return 0;
107: }
108:
109: void VStateless_class::set_default_getter(Method* amethod){
110: fdefault_getter=amethod;
111: }
112:
1.42 misha 113: void VStateless_class::set_base(VStateless_class* abase){
114: if(abase){
115: fbase=abase;
116: fbase->add_derived(*this);
117:
1.45 ! moko 118: bool no_auto = fmethods.get(auto_method_name) == NULL;
1.42 misha 119: // we assume there is no derivatives at this point
120: fmethods.merge_dont_replace(abase->fmethods);
1.45 ! moko 121: // we don't want to inherit @auto (issue #75)
! 122: if (no_auto) fmethods.remove(auto_method_name);
1.42 misha 123:
124: if(fbase->fscalar && !fscalar)
125: fscalar=fbase->fscalar;
126: if(fbase->fdefault_getter && !fdefault_getter)
127: fdefault_getter=fbase->fdefault_getter;
128: }
1.33 misha 129: }
130:
1.42 misha 131: void VStateless_class::add_derived(VStateless_class &aclass){
132: fderived+=&aclass;
133: if (fbase)
134: fbase->add_derived(aclass);
1.34 misha 135: }
E-mail: