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