Annotation of parser3/src/types/pa_vclass.C, revision 1.23

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.23    ! paf         8: static const char * const IDENT_VCLASS_C="$Date: 2005/07/25 07:44:02 $";
1.7       paf         9: 
1.1       paf        10: #include "pa_vclass.h"
                     11: 
1.22      paf        12: /// preparing property accessors to fields
1.23    ! paf        13: void VClass::fill_properties()
1.22      paf        14: {
1.23    ! paf        15:        // TODO: refresh properties list on ^execute [maybe]
        !            16:        VStateless_class::fill_properties(ffields);
1.22      paf        17: }
                     18: 
1.17      paf        19: Value* VClass::as(const char* atype, bool looking_up) {
                     20:        if(Value* result=Value::as(atype, looking_up))
1.12      paf        21:                return result;
1.11      paf        22:        else
1.12      paf        23:                return fbase?fbase->as(atype, looking_up):0;
1.11      paf        24: }
                     25: 
1.22      paf        26: /// VClass: $CLASS, (field/property)=STATIC value;(method)=method_ref with self=object_class
1.17      paf        27: Value* VClass::get_element(const String& aname, Value& aself, bool looking_up) {
1.22      paf        28:        // simple things first: $field=static field/property
                     29:        if(Value* result=ffields.get(aname)) {
                     30:                if(Property* prop=result->get_property()) // it is property?
                     31:                {
                     32:                        Method* method=prop->getter;
                     33:                        if(!method)
                     34:                                throw Exception("parser.runtime",
                     35:                                        &aname,
                     36:                                        "this property has no getter method (get_%s)", aname.cstr());
1.21      paf        37: 
1.22      paf        38:                        return new VJunction(new Junction(aself, method, true /*is_getter*/));
                     39:                }
1.21      paf        40:                return result;
                     41:        }
                     42: 
1.14      paf        43:        // $CLASS, $method, or other base element
1.17      paf        44:        if(Value* result=VStateless_class::get_element(aname, aself, looking_up))
1.22      paf        45:                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        46: 
                     47:        return 0;
                     48: }
                     49: 
                     50: /// VClass: (field)=value - static values only
1.21      paf        51: const Method* VClass::put_element(const String& aname, Value* avalue, bool replace) {
1.7       paf        52:        try {
                     53:                if(fbase && fbase->put_element(aname, avalue, true))
1.21      paf        54:                        return PUT_ELEMENT_REPLACED_ELEMENT; // replaced in base
1.10      paf        55:        } catch(Exception) {  /* allow override parent variables, useful for form descendants */ }
1.7       paf        56: 
                     57:        if(replace)
1.21      paf        58:                return ffields.put_replace(aname, avalue)? PUT_ELEMENT_REPLACED_ELEMENT: 0;
1.7       paf        59:        else {
                     60:                ffields.put(aname, avalue);
1.21      paf        61:                return 0;
1.7       paf        62:        }
                     63: }
                     64: 
                     65: /// @returns object of this class
1.18      paf        66: Value* VClass::create_new_value(Pool& apool) { 
                     67:        return new VObject(apool, *this);
1.1       paf        68: }

E-mail: