Annotation of parser3/src/types/pa_vstateless_class.C, revision 1.41
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.41 ! misha 8: static const char * const IDENT_VSTATELESS_CLASS_C="$Date: 2009-05-14 07:28:45 $";
1.2 paf 9:
10: #include "pa_vstateless_class.h"
1.24 paf 11: #include "pa_vproperty.h"
1.29 misha 12: #include "pa_vstring.h"
1.30 misha 13: #include "pa_vbool.h"
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.24 paf 22: /// @TODO why?! request must be different ptr from global [used in VStateless_class.add_method]
1.17 paf 23: void VStateless_class::add_method(const String& name, Method& method) {
1.20 paf 24: if(flocked)
1.31 misha 25: throw Exception(PARSER_RUNTIME,
1.17 paf 26: &name,
27: "can not add method to system class (maybe you have forgotten .CLASS in ^process[$caller.CLASS]{...}?)");
1.20 paf 28:
1.17 paf 29: put_method(name, &method);
30: }
1.2 paf 31:
32: void VStateless_class::add_native_method(
1.20 paf 33: const char* cstr_name,
1.7 paf 34: Method::Call_type call_type,
1.20 paf 35: NativeCodePtr native_code,
1.38 misha 36: int min_numbered_params_count,
1.40 misha 37: int max_numbered_params_count,
38: Method::Call_optimization
39: #ifdef OPTIMIZE_CALL
40: call_optimization
41: #endif
42: ) {
1.2 paf 43:
1.20 paf 44: const String& name=*new String(cstr_name);
1.2 paf 45:
1.20 paf 46: Method& method=*new Method(
1.7 paf 47: call_type,
1.2 paf 48: min_numbered_params_count, max_numbered_params_count,
49: 0/*params_names*/, 0/*locals_names*/,
1.40 misha 50: 0/*parser_code*/, native_code, false/*all_vars_local*/
51: #ifdef OPTIMIZE_RESULT
52: , Method::RO_USE_WCONTEXT
53: #endif
54: #ifdef OPTIMIZE_CALL
55: , call_optimization
56: #endif
57: );
1.39 misha 58:
1.2 paf 59: add_method(name, method);
1.16 paf 60: }
61:
1.30 misha 62: /// VStateless_class: $CLASS, $CLASS_NAME, $method
1.32 misha 63: Value* VStateless_class::get_element(const String& aname, Value& aself, bool alooking_up) {
1.16 paf 64: // $CLASS
1.41 ! misha 65: if(aname==class_name)
1.16 paf 66: return this;
1.36 misha 67:
1.29 misha 68: // $CLASS_NAME
1.41 ! misha 69: if(aname==class_nametext)
1.29 misha 70: return new VString(this->name());
1.36 misha 71:
1.16 paf 72: // $method=junction(self+class+method)
1.36 misha 73: if(Method* method=get_method(aname)){
74: if(!method->junction_template)
75: return method->junction_template=new VJunction(aself, method);
76:
1.37 misha 77: return method->junction_template->get(aself);
1.36 misha 78: }
1.18 paf 79:
80: // base monkey
1.26 paf 81: if(fbase) {
82: if(Value* obase=aself.base()) // MXdoc has fbase but does not have object_base[ base() ]
1.32 misha 83: return fbase->get_element(aname, *obase, alooking_up);
1.26 paf 84: }
1.18 paf 85:
1.16 paf 86: return 0;
1.23 paf 87: }
88:
1.32 misha 89: void VStateless_class::put_method(const String& aname, Method* amethod){
1.25 paf 90: fmethods.put(aname, amethod);
1.2 paf 91: }
1.32 misha 92:
93: Value* VStateless_class::get_default_getter(Value& aself, const String& aname){
94: if(fdefault_getter)
95: return new VJunction(aself, fdefault_getter, true /*getter*/, (String*)&aname);
96:
97: if(fbase)
98: if(Value* obase=aself.base())
99: return fbase->get_default_getter(*obase, aname);
100:
101: return 0;
102: }
103:
104: void VStateless_class::set_default_getter(Method* amethod){
105: fdefault_getter=amethod;
106: }
107:
1.33 misha 108: Value* VStateless_class::get_scalar(Value& aself){
109: if(fscalar)
110: return new VJunction(aself, fscalar, true /*getter*/);
111:
112: if(fbase)
113: if(Value* obase=aself.base())
114: return fbase->get_scalar(*obase);
115:
116: return 0;
117: }
118:
119: void VStateless_class::set_scalar(Method* amethod){
120: fscalar=amethod;
1.34 misha 121: }
E-mail: