00001
00002
00003 #ifndef template_i_h
00004 #define template_i_h
00005
00006 #include <map>
00007 #include "except.h"
00008 #include "typedef.h"
00009 #include "paranoid_visitor.h"
00010 #include "annotator.h"
00011 #include "symbol_name.h"
00012 #include "decl_read.h"
00013
00014
00015
00016 class Template_spec {
00017 Type_vector args;
00018 Class_symbol* defn;
00019 Ptree* code;
00020
00021 public:
00022 Template_spec(Type_vector args, Class_symbol* defn);
00023
00024 ~Template_spec();
00025
00026 void add_code(Ptree* tree);
00027
00028 bool matches(const Type_vector& rhs) const;
00029
00030 Class_symbol* get_class() const;
00031
00032 Ptree* get_code() const;
00033 };
00034
00035
00036
00042 class Template_defn_scope : public Abstract_scope {
00043 std::map<std::string, Typedef_symbol*> things;
00044
00045 public:
00046 Template_defn_scope(Abstract_scope* parent, const Template_thing* arg_names, const Type_vector* arg_types, std::string class_name, std::string tpl_name);
00047
00048 ~Template_defn_scope();
00049
00050 Symbol_pair lookup_here(std::string name, bool for_decl);
00051
00052 Variable_symbol* add_variable(Storage_class_specifier s, Type t, Ptree* n, Ptree* i, Ptree* b);
00053
00054 Function_signature* add_function_decl(Storage_class_specifier s, Function_specifier_set f, Type t, const Symbol_name& n);
00055
00056 void add_function_implementation(Function_signature* sig, Block_scope* sco, Ptree* b, Ptree* i);
00057
00058 void add_symbol(std::string name, Symbol* s);
00059
00060 std::string get_unique_name(std::string name);
00061
00062 Type get_this_type() const;
00063 };
00064
00065
00066
00067 class Template_class_adder : public Class_adder {
00068 std::string mangled_name;
00069 std::string real_name;
00070
00071 public:
00072 Template_class_adder(std::string mangled_name, std::string real_name);
00073
00074 Class_symbol* add_class(Abstract_scope* scope, std::string name, Symbol::Kind k);
00075 };
00076
00077
00078
00079 typedef int Tpl_RT;
00080
00081 class Template_visitor : public Paranoid_visitor<Tpl_RT> {
00082 Abstract_scope* current_scope;
00083 Template_thing args;
00084
00085 public:
00086 Template_visitor(Source* s, Abstract_scope* scope, const Template_thing& args);
00087
00088 Tpl_RT visit_type_declaration(Ptree* storagespec, Ptree* typespec);
00089
00095 Tpl_RT visit_name_declaration(Ptree* storagespec, Ptree* typespec, Ptree* decllist);
00096
00097 Tpl_RT visit_function(Ptree* storagespec, Ptree* typespec, PtreeDeclarator* decl, PtreeBlock* block);
00098
00099 private:
00100 void declare_name(Ptree* p, Ptree* tree);
00101
00102 void declare_class(Ptree* class_tree);
00103 };
00104
00105
00106
00107
00108
00109
00110
00111 inline Class_symbol*
00112 Template_spec::get_class() const
00113 {
00114 return defn;
00115 }
00116
00117
00118 inline Ptree*
00119 Template_spec::get_code() const
00120 {
00121 return code;
00122 }
00123
00124 #endif // template_i_h