Annotation of parser3/src/types/pa_vclass.C, revision 1.22
1.7 paf 1: /** @file
2: Parser: @b class parser class impl.
1.1 paf 3:
1.20 paf 4: Copyright (c) 2001-2004 ArtLebedev Group (http://www.artlebedev.com)
1.7 paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.1 paf 6: */
7:
1.22 ! paf 8: static const char * const IDENT_VCLASS_C="$Date: 2005/07/15 06:16:42 $";
1.7 paf 9:
1.1 paf 10: #include "pa_vclass.h"
11:
1.22 ! paf 12: /// preparing property accessors to fields
! 13: VClass::VClass()
! 14: {
! 15: fill_properties(ffields);
! 16: }
! 17:
1.17 paf 18: Value* VClass::as(const char* atype, bool looking_up) {
19: if(Value* result=Value::as(atype, looking_up))
1.12 paf 20: return result;
1.11 paf 21: else
1.12 paf 22: return fbase?fbase->as(atype, looking_up):0;
1.11 paf 23: }
24:
1.22 ! paf 25: /// VClass: $CLASS, (field/property)=STATIC value;(method)=method_ref with self=object_class
1.17 paf 26: Value* VClass::get_element(const String& aname, Value& aself, bool looking_up) {
1.22 ! paf 27: // simple things first: $field=static field/property
! 28: if(Value* result=ffields.get(aname)) {
! 29: if(Property* prop=result->get_property()) // it is property?
! 30: {
! 31: Method* method=prop->getter;
! 32: if(!method)
! 33: throw Exception("parser.runtime",
! 34: &aname,
! 35: "this property has no getter method (get_%s)", aname.cstr());
1.21 paf 36:
1.22 ! paf 37: return new VJunction(new Junction(aself, method, true /*is_getter*/));
! 38: }
1.21 paf 39: return result;
40: }
41:
1.14 paf 42: // $CLASS, $method, or other base element
1.17 paf 43: if(Value* result=VStateless_class::get_element(aname, aself, looking_up))
1.22 ! paf 44: return result; // TODO: this can be SIGNIFICANTLY sped up by caching in ffields! [THOUGH decide about different aself] // what REALLY would speed up things is to join storage of properties/methods/fields of all vobject parents into last descenant [sort of vmt + all fields as in other langs]
1.7 paf 45:
46: return 0;
47: }
48:
49: /// VClass: (field)=value - static values only
1.21 paf 50: const Method* VClass::put_element(const String& aname, Value* avalue, bool replace) {
1.7 paf 51: try {
52: if(fbase && fbase->put_element(aname, avalue, true))
1.21 paf 53: return PUT_ELEMENT_REPLACED_ELEMENT; // replaced in base
1.10 paf 54: } catch(Exception) { /* allow override parent variables, useful for form descendants */ }
1.7 paf 55:
56: if(replace)
1.21 paf 57: return ffields.put_replace(aname, avalue)? PUT_ELEMENT_REPLACED_ELEMENT: 0;
1.7 paf 58: else {
59: ffields.put(aname, avalue);
1.21 paf 60: return 0;
1.7 paf 61: }
62: }
63:
64: /// @returns object of this class
1.18 paf 65: Value* VClass::create_new_value(Pool& apool) {
66: return new VObject(apool, *this);
1.1 paf 67: }
E-mail: