Annotation of parser3/src/types/pa_vstateless_class.C, revision 1.24
1.8 paf 1: /** @file
2: Parser: stateless class.
3:
1.22 paf 4: Copyright (c) 2001-2004 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.24 ! paf 8: static const char * const IDENT_VSTATELESS_CLASS_C="$Date: 2005/07/15 06:16:42 $";
1.2 paf 9:
10: #include "pa_vstateless_class.h"
1.24 ! paf 11: #include "pa_vproperty.h"
1.17 paf 12:
1.24 ! paf 13: /// @TODO why?! request must be different ptr from global [used in VStateless_class.add_method]
1.17 paf 14: void VStateless_class::add_method(const String& name, Method& method) {
1.20 paf 15: if(flocked)
1.17 paf 16: throw Exception("parser.runtime",
17: &name,
18: "can not add method to system class (maybe you have forgotten .CLASS in ^process[$caller.CLASS]{...}?)");
1.20 paf 19:
1.17 paf 20: put_method(name, &method);
21: }
1.2 paf 22:
23: void VStateless_class::add_native_method(
1.20 paf 24: const char* cstr_name,
1.7 paf 25: Method::Call_type call_type,
1.20 paf 26: NativeCodePtr native_code,
1.2 paf 27: int min_numbered_params_count, int max_numbered_params_count) {
28:
1.20 paf 29: const String& name=*new String(cstr_name);
1.2 paf 30:
1.20 paf 31: Method& method=*new Method(
1.7 paf 32: call_type,
1.2 paf 33: min_numbered_params_count, max_numbered_params_count,
34: 0/*params_names*/, 0/*locals_names*/,
35: 0/*parser_code*/, native_code
36: );
37: add_method(name, method);
1.16 paf 38: }
39:
40: /// VStateless_class: $CLASS, $method
1.20 paf 41: Value* VStateless_class::get_element(const String& aname, Value& aself, bool looking_up) {
1.16 paf 42: // $CLASS
43: if(aname==CLASS_NAME)
44: return this;
45: // $method=junction(self+class+method)
1.20 paf 46: if(Method* method=get_method(aname))
1.23 paf 47: return new VJunction(new Junction(aself, method));
1.18 paf 48:
49: // base monkey
1.16 paf 50: if(fbase)
1.20 paf 51: if(Value* lbase=aself.base()) // one check would be enough...
1.18 paf 52: return fbase->get_element(aname, *lbase, looking_up);
53:
1.16 paf 54: return 0;
1.23 paf 55: }
56:
57: inline Property& register_property(const String& aname, Hash<const String::Body, Property*>& aprops) {
58: String prop_name=aname.mid(4, aname.length());
59: Property* result=aprops.get(prop_name);
60: if(!result) {
61: result=new Property();
62: aprops.put(prop_name, result);
63: }
64: return *result;
65: }
66:
67: void VStateless_class::put_method(const String& aname, Method* amethod) {
68: if(aname.starts_with("get_"))
69: register_property(aname, fprops).getter=amethod;
70: else if(aname.starts_with("put_") )
71: register_property(aname, fprops).setter=amethod;
72: else
73: fmethods.put(aname, amethod);
1.24 ! paf 74: }
! 75:
! 76: static void forward_cache_properties_one(const String::Body akey, Property* avalue,
! 77: HashStringValue* acache) {
! 78: acache->put(akey, new VProperty(*avalue));
! 79: }
! 80:
! 81: void VStateless_class::fill_properties(HashStringValue& acache) {
! 82: // base monkey
! 83: if(fbase)
! 84: fbase->fill_properties(acache);
! 85:
! 86: fprops.for_each(forward_cache_properties_one, &acache);
1.2 paf 87: }
E-mail: