Annotation of parser3/src/types/pa_vstateless_class.h, revision 1.58
1.6 paf 1: /** @file
2: Parser: stateless class decls.
3:
1.53 paf 4: Copyright (c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com)
1.23 paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.2 paf 6: */
7:
8: #ifndef PA_VSTATELESS_CLASS_H
9: #define PA_VSTATELESS_CLASS_H
1.27 paf 10:
1.58 ! misha 11: static const char * const IDENT_VSTATELESS_CLASS_H="$Date: 2008-05-30 12:24:44 $";
1.43 paf 12:
13: // include
1.2 paf 14:
1.45 paf 15: #include "pa_pool.h"
1.13 paf 16: #include "pa_hash.h"
1.2 paf 17: #include "pa_vjunction.h"
1.43 paf 18: #include "pa_method.h"
1.49 paf 19: #include "pa_vproperty.h"
1.2 paf 20:
1.38 paf 21: // defines
22:
23: #define CLASS_NAME "CLASS"
1.54 misha 24: #define CLASS_NAMETEXT "CLASS_NAME"
1.38 paf 25:
26: // forwards
27:
1.43 paf 28: class VStateless_class;
29:
1.2 paf 30: class Temp_method;
31:
1.6 paf 32: /**
1.30 paf 33: object' class. stores
34: - base: VClass::base()
35: - methods: VStateless_class::fmethods
1.6 paf 36:
1.30 paf 37: @see Method, VStateless_object, Temp_method
1.6 paf 38: */
1.39 paf 39: class VStateless_class: public Value {
1.19 paf 40: friend class Temp_method;
1.43 paf 41:
42: const String* fname;
43: mutable const char* fname_cstr;
1.44 paf 44: Hash<const String::Body, Method*> fmethods;
1.43 paf 45:
46: bool flocked;
1.57 misha 47: bool fall_vars_local;
1.43 paf 48:
49: protected:
50:
51: VStateless_class* fbase;
1.58 ! misha 52: Method* fdefault_getter;
1.43 paf 53:
1.2 paf 54: public: // Value
55:
1.43 paf 56: const char* type() const { return "stateless_class"; }
1.2 paf 57:
1.5 paf 58: /// VStateless_class: this
1.43 paf 59: override VStateless_class *get_class() { return this; }
1.41 paf 60: /// VStateless_class: fbase
1.43 paf 61: override Value* base() { return fbase; }
1.58 ! misha 62: override Value* get_element(const String& aname, Value& aself, bool alooking_up);
1.55 misha 63: override Value& as_expr_result(bool /*return_string_as_is=false*/);
1.58 ! misha 64: override Value* get_default_getter(Value& aself, const String& aname);
! 65: override void set_default_getter(Method* amethod);
1.2 paf 66:
67: public: // usage
68:
1.43 paf 69: VStateless_class(
70: const String* aname=0,
71: VStateless_class* abase=0):
1.24 paf 72: fname(aname),
1.43 paf 73: flocked(false),
1.57 misha 74: fbase(abase),
1.58 ! misha 75: fall_vars_local(false),
! 76: fdefault_getter(0) {
1.2 paf 77: }
78:
1.43 paf 79: void lock() { flocked=true; }
80:
1.24 paf 81: const String& name() const {
82: if(!fname) {
83: if(fbase)
84: return fbase->name();
85:
1.56 misha 86: throw Exception(PARSER_RUNTIME,
1.24 paf 87: 0,
88: "getting name of nameless class");
89: }
90:
91: return *fname;
92: }
1.43 paf 93: const char* name_cstr() const{
94: if(this) {
95: if(!fname_cstr) // remembering last calculated, and can't reassign 'fname_cstr'!
96: fname_cstr=name().cstr();
97: return fname_cstr;
98: } else
99: return "<unknown>";
1.24 paf 100: }
101: void set_name(const String& aname) {
102: fname=&aname;
103: }
104:
1.43 paf 105: Method* get_method(const String& aname) const {
106: return fmethods.get(aname);
1.2 paf 107: }
108:
1.57 misha 109: void all_vars_local(){
110: fall_vars_local=true;
111: }
112:
113: bool is_vars_local(){
114: return fall_vars_local;
115: }
116:
1.51 paf 117: /// virtual for VClass to override to pre-cache property accessors into fields
118: virtual void add_method(const String& name, Method& method);
1.40 paf 119:
1.2 paf 120: void add_native_method(
1.43 paf 121: const char* cstr_name,
1.9 paf 122: Method::Call_type call_type,
1.43 paf 123: NativeCodePtr native_code,
1.2 paf 124: int min_numbered_params_count, int max_numbered_params_count);
125:
1.43 paf 126: void set_base(VStateless_class* abase) {
1.2 paf 127: // remember the guy
1.32 paf 128: fbase=abase;
1.2 paf 129: }
1.43 paf 130: VStateless_class* base_class() { return fbase; }
1.2 paf 131:
1.30 paf 132: bool derived_from(VStateless_class& vclass) {
1.2 paf 133: return
1.30 paf 134: fbase==&vclass ||
135: fbase && fbase->derived_from(vclass);
1.31 paf 136: }
137:
1.11 paf 138: //@{
139: /// @name just stubs, real onces defined below the hierarchy
1.43 paf 140: virtual Value* get_field(const String&) { return 0; }
141: virtual bool replace_field(const String&, Value*) { return false; }
1.21 paf 142: //@}
143:
144: /// @returns new value for current class, used in classes/ & VClass
1.52 paf 145: virtual Value* create_new_value(Pool&, HashStringValue& /*afields*/) { return 0; }
1.50 paf 146:
147: protected:
148:
149: void fill_properties(HashStringValue& acache);
1.2 paf 150:
1.49 paf 151: private:
1.2 paf 152:
1.49 paf 153: void put_method(const String& aname, Method* amethod);
1.2 paf 154: };
155:
1.6 paf 156: /// Auto-object used for temporarily substituting/removing class method
1.2 paf 157: class Temp_method {
158: VStateless_class& fclass;
159: const String& fname;
1.43 paf 160: Method* saved_method;
1.2 paf 161: public:
1.43 paf 162: Temp_method(VStateless_class& aclass, const String& aname, Method* amethod) :
1.2 paf 163: fclass(aclass),
164: fname(aname),
165: saved_method(aclass.get_method(aname)) {
166: fclass.put_method(aname, amethod);
167: }
168: ~Temp_method() {
169: fclass.put_method(fname, saved_method);
170: }
171: };
172:
173: #endif
E-mail: