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