00001
00002
00003 #ifndef function_h
00004 #define function_h
00005
00006 #include <vector>
00007 #include "symbol_table.h"
00008 #include "type_rep.h"
00009 #include "symbol_name.h"
00010
00011
00012
00013
00014
00015
00016 class Class_symbol;
00017 class Block_scope;
00018 class Function_symbol;
00019 class Variable_symbol;
00030 class Function_signature : public Symbol {
00031
00032 Type proto_type;
00033
00034 Type this_type;
00035
00036 Type call_type;
00037
00038 Storage_class_specifier storage_spec;
00039 Function_specifier_set function_spec;
00040 bool builtin;
00041 bool generated;
00042 Function_symbol* backlink;
00043 Ptree* definition;
00044 Ptree* initializers;
00045
00046 public:
00047 typedef std::vector<Variable_symbol*> Par_vec;
00048
00049 private:
00050 Par_vec parameters;
00051
00052 public:
00053
00054
00062 Function_signature(Type t, Type this_type, Type call_type, Storage_class_specifier sc, Function_specifier_set f, Function_symbol* backlink);
00063
00067 static Function_signature* make_builtin(Type t);
00068
00070 Type get_return_type() const;
00071
00073 Type get_proto_type() const;
00074
00076 Type get_call_type() const;
00077
00080 Type get_this_type() const;
00081
00087 bool has_pointer_type(Type t) const;
00088
00090 Type get_pointer_type() const;
00091
00093 Storage_class_specifier get_storage_specifier() const;
00094
00096 Function_specifier_set get_function_specifiers() const;
00097
00099 void merge_fspec(Function_specifier_set fspec);
00100
00103 bool is_builtin() const;
00104
00105 void set_builtin();
00106
00108 bool is_generated() const;
00109
00110 void set_generated();
00111
00113 Function_symbol* get_function() const;
00114
00116 Ptree* get_body() const;
00117
00125 Ptree* get_initializers() const;
00126
00129 void set_body(Ptree* tree, Ptree* init);
00130
00131 Function_signature::Par_vec::const_iterator par_begin() const;
00132
00133 Function_signature::Par_vec::const_iterator par_end() const;
00134
00135 void add_parameter(Variable_symbol* vsym);
00136
00137 Symbol::Kind get_kind() const;
00138
00139 void dump(std::ostream& os);
00140 };
00141
00142 class Function_symbol : public Symbol {
00143 typedef std::vector<Function_signature*> Sig_vec;
00144 Sig_vec signatures;
00145 Abstract_scope* declared_scope;
00146 Symbol_name::Kind fun_kind;
00147
00148 public:
00149 enum Add_arg {
00150 must_be_declared,
00151 must_be_new,
00152 may_be_anything
00153 };
00154 typedef Sig_vec::const_iterator Sig_it;
00155 Sig_it sig_begin() const { return signatures.begin(); }
00156 Sig_it sig_end() const { return signatures.end(); }
00157
00158 Symbol_name::Kind get_function_kind() const { return fun_kind; }
00159
00160 public:
00161
00162 Function_symbol(Abstract_scope* declared_scope, Symbol_name::Kind fun_kind);
00163
00164 Abstract_scope* get_declared_scope() const;
00165
00166 Function_symbol::Kind get_kind() const;
00167
00168 void fill_in_mangled_names(bool ignore_if_one);
00169
00180 Function_signature* add_signature(Type t, Type this_type, Storage_class_specifier sc, Function_specifier_set f, Add_arg what_to_do);
00181
00183 bool is_overloaded() const;
00184
00186 Type get_type() const;
00187
00190 Function_signature* get_nonoverloaded_signature() const;
00191
00197 Function_signature* get_function_signature(Type type, bool* ambig) const;
00198
00199 void dump(std::ostream& os);
00200 };
00201
00202
00203
00204
00205
00206
00207
00209 inline Type
00210 Function_signature::get_proto_type() const
00211 {
00212 return proto_type;
00213 }
00214
00215
00217 inline Type
00218 Function_signature::get_call_type() const
00219 {
00220 return call_type;
00221 }
00222
00223
00226 inline Type
00227 Function_signature::get_this_type() const
00228 {
00229 return this_type;
00230 }
00231
00232
00234 inline Storage_class_specifier
00235 Function_signature::get_storage_specifier() const
00236 {
00237 return storage_spec;
00238 }
00239
00240
00242 inline Function_specifier_set
00243 Function_signature::get_function_specifiers() const
00244 {
00245 return function_spec;
00246 }
00247
00248
00251 inline bool
00252 Function_signature::is_builtin() const
00253 {
00254 return builtin;
00255 }
00256
00257
00258 inline void
00259 Function_signature::set_builtin()
00260 {
00261 builtin = true;
00262 }
00263
00264
00266 inline bool
00267 Function_signature::is_generated() const
00268 {
00269 return generated;
00270 }
00271
00272
00273 inline void
00274 Function_signature::set_generated()
00275 {
00276 generated = true;
00277 if (!is_declared())
00278 set_status(st_Declared);
00279 }
00280
00281
00283 inline Function_symbol*
00284 Function_signature::get_function() const
00285 {
00286 return backlink;
00287 }
00288
00289
00291 inline Ptree*
00292 Function_signature::get_body() const
00293 {
00294 assert(is_defined());
00295 return definition;
00296 }
00297
00298
00306 inline Ptree*
00307 Function_signature::get_initializers() const
00308 {
00309 assert(is_defined());
00310 return initializers;
00311 }
00312
00313
00314 inline Abstract_scope*
00315 Function_symbol::get_declared_scope() const
00316 {
00317 return declared_scope;
00318 }
00319
00320
00322 inline Type
00323 Function_symbol::get_type() const
00324 {
00325 return get_nonoverloaded_signature()->get_proto_type();
00326 }
00327
00328 #endif // function_h