00001
00002
00003 #ifndef class_h
00004 #define class_h
00005
00006 #include <vector>
00007 #include "type_rep.h"
00008 #include "symbol_table.h"
00009 #include "symbol_name.h"
00010 #include "scope.h"
00011
00012
00013
00014
00015
00016
00017 class Variable_symbol;
00018 class Function_symbol;
00019 class Class_symbol;
00020
00021 class Class_scope : public Abstract_scope {
00022 Class_symbol* sym;
00023 std::string prefix;
00024 public:
00025
00026 public:
00027
00028 Class_scope(Class_symbol* sym);
00029
00030 ~Class_scope();
00031
00032 Class_symbol* get_class_symbol() const;
00033
00034 Type get_this_type() const;
00035
00036 std::string get_unique_name(std::string name);
00037
00039 Symbol_pair lookup_here(std::string name, bool for_decl);
00040
00041 void add_symbol(std::string name, Symbol* sym);
00042
00044 Variable_symbol* add_variable(Storage_class_specifier storage, Type type, Ptree* name, Ptree* init, Ptree* bitsize);
00045
00046 Function_signature* add_function_decl(Storage_class_specifier storage, Function_specifier_set fspec, Type type, const Symbol_name& sym_name);
00047
00048 void add_function_implementation(Function_signature* fsig, Block_scope* scope, Ptree* tree, Ptree* initializer);
00049
00050 bool is_constructor(Ptree* tree);
00051 };
00052
00054 class Class_symbol : public Type_symbol {
00055 public:
00056 typedef std::vector<Class_symbol*> bases_t;
00057 typedef std::vector<Variable_symbol*> members_t;
00058 typedef std::vector<Function_symbol*> memfuns_t;
00059 private:
00060 Kind k;
00061 Abstract_scope* in_scope;
00062 std::string real_name;
00063
00064
00065 bases_t base_classes, virtual_base_classes;
00066 members_t members;
00067 memfuns_t member_functions;
00068
00069 bool pod, aggregate;
00070
00071 friend class Class_lookup_helper;
00072 friend class Class_scope;
00073
00074 enum Assignment_operator {
00075 no_assignment_operator,
00076 const_assignment_operator,
00077 nonconst_assignment_operator
00078 };
00079
00080 public:
00081
00082 Class_symbol(Kind k, Abstract_scope* in_scope, std::string real_name);
00083
00084 ~Class_symbol();
00085
00086 Symbol::Kind get_kind() const;
00087
00088 bool is_pod() const;
00089
00090 bool is_aggregate() const;
00091
00092 const std::string& get_real_name() const;
00093
00094 bool is_base_class_of(Class_symbol* other) const;
00095
00096 bool is_unique_base_class_of(Class_symbol* other) const;
00097
00098 void enumerate_base_classes(bool with_virtuals, bases_t* output);
00099
00103 void add_base_class(Class_symbol* sym, bool is_virt);
00104
00105 void dump(std::ostream& os);
00106
00107 Symbol_pair lookup_helper(std::string name) const;
00108
00109 Class_scope* get_scope();
00110
00111 Class_symbol::members_t::const_iterator mem_begin() const;
00112
00113 Class_symbol::members_t::const_iterator mem_end() const;
00114
00115 Class_symbol::bases_t::const_iterator vbc_begin() const;
00116
00117 Class_symbol::bases_t::const_iterator vbc_end() const;
00118
00119 Class_symbol::bases_t::const_iterator base_begin() const;
00120
00121 Class_symbol::bases_t::const_iterator base_end() const;
00122
00124 void start_definition(std::string basename);
00125
00127 void finish_definition();
00128
00129 private:
00131 void maybe_add_vbc(Class_symbol* sym);
00132
00136 Function_signature* get_copy_ctor(Function_symbol* fsym, bool must_be_ref) const;
00137
00138 bool implicit_copy_ctor_is_const() const;
00139
00140 Class_symbol::Assignment_operator implicit_assignment_operator_style() const;
00141 };
00142
00143 class Class_lookup_helper {
00144 protected:
00145 typedef std::vector<Class_symbol*> classes_t;
00146 classes_t result_set;
00147 classes_t hidden_vbcs;
00148 virtual bool predicate(Class_symbol* sym) = 0;
00149
00150 public:
00151 virtual ~Class_lookup_helper();
00152
00154 void add_class(Class_symbol* sym);
00155
00158 void finish(Class_symbol* sym);
00159
00160 protected:
00161
00162
00188 Class_lookup_helper();
00189 };
00190
00191 class Class_adder {
00192 public:
00193 virtual Class_symbol* add_class(Abstract_scope* scope, std::string name, Symbol::Kind k) = 0;
00194 virtual ~Class_adder() { }
00195 };
00196
00197 class Default_class_adder : public Class_adder {
00198
00199 private:
00200 Class_symbol* add_class(Abstract_scope* scope, std::string name, Symbol::Kind k);
00201 };
00202
00203
00204
00205
00206
00207 Class_symbol* parse_class(Ptree* tree, Abstract_scope* scope, Ptree* name_for_anon, bool is_type_declaration, Class_adder& adder);
00208
00209
00210
00211
00212
00213
00214
00215 inline Class_symbol*
00216 Class_scope::get_class_symbol() const
00217 {
00218 return sym;
00219 }
00220
00221
00222 inline bool
00223 Class_symbol::is_pod() const
00224 {
00225 return pod;
00226 }
00227
00228
00229 inline bool
00230 Class_symbol::is_aggregate() const
00231 {
00232 return aggregate;
00233 }
00234
00235
00236 inline const std::string&
00237 Class_symbol::get_real_name() const
00238 {
00239 return real_name;
00240 }
00241
00242
00243 inline Symbol_pair
00244 Class_symbol::lookup_helper(std::string name) const
00245 {
00246
00247 return Symbol_table::get_instance().
00248 get_symbol(Symbol_name::get_mangled_symbol_name(Symbol_name::get_mangled_scope_from_symbol(get_name()), name));
00249 }
00250
00251
00252 inline Class_symbol::members_t::const_iterator
00253 Class_symbol::mem_begin() const
00254 {
00255 return members.begin();
00256 }
00257
00258
00259 inline Class_symbol::members_t::const_iterator
00260 Class_symbol::mem_end() const
00261 {
00262 return members.end();
00263 }
00264
00265
00266 inline Class_symbol::bases_t::const_iterator
00267 Class_symbol::vbc_begin() const
00268 {
00269 return virtual_base_classes.begin();
00270 }
00271
00272
00273 inline Class_symbol::bases_t::const_iterator
00274 Class_symbol::vbc_end() const
00275 {
00276 return virtual_base_classes.end();
00277 }
00278
00279
00280 inline Class_symbol::bases_t::const_iterator
00281 Class_symbol::base_begin() const
00282 {
00283 return base_classes.begin();
00284 }
00285
00286
00287 inline Class_symbol::bases_t::const_iterator
00288 Class_symbol::base_end() const
00289 {
00290 return base_classes.end();
00291 }
00292
00293 #endif // class_h