00001
00002
00003 #include "block.h"
00004 #include "block_i.h"
00005
00006
00007 #line 38 "block.cpp"
00008
00012 Block_scope::Block_scope(Function_signature* fsig)
00013 : Abstract_scope(fsig->get_function()->get_declared_scope()),
00014 use_parent(false),
00015 fun_prefix(Symbol_name::get_mangled_scope_from_symbol(fsig->get_function()->get_name())),
00016 block_prefix(Symbol_name::get_mangled_block_scope(fun_prefix)),
00017 this_type(fsig->get_this_type()),
00018 fsig(fsig)
00019
00020 { }
00021
00022 #line 51 "block.cpp"
00023
00030 Block_scope::Block_scope(Block_scope* parent, bool use_parent)
00031 : Abstract_scope(parent),
00032 use_parent(use_parent),
00033 fun_prefix(parent->fun_prefix),
00034 block_prefix(Symbol_name::get_mangled_block_scope(fun_prefix)),
00035 this_type(parent->get_this_type()),
00036 fsig(parent->fsig)
00037 { }
00038
00039 #line 66 "block.cpp"
00040
00041
00042 Block_scope::~Block_scope()
00043 { }
00044
00045 #line 70 "block.cpp"
00046
00047 Variable_symbol*
00048 Block_scope::add_variable(Storage_class_specifier storage,
00049 Type type, Ptree* name, Ptree* init,
00050 Ptree* bitsize)
00051 {
00052 if (bitsize)
00053 compile_error("local variables can't have bitsize");
00054 if (!name && storage != s_Parameter)
00055 compile_error("you cannot declare nameless local variables");
00056 if (storage == s_None)
00057 storage = s_Auto;
00058 else if (storage == s_Auto || storage == s_Parameter || storage == s_Register || storage == s_Static)
00059 ;
00060 else if (storage == s_Extern)
00061 compile_error("FIXME: extern within a function");
00062 else
00063 compile_error("invalid storage class for local variable");
00064
00065
00066 if (init)
00067 init = Init_handler(this, init, true).process_initializer(type.get_unqualified_type());
00068
00069
00070
00071
00072 Symbol_name sym_name (name, this, false);
00073 if (sym_name.is_template())
00074 compile_error("template variables are not allowed");
00075 if (sym_name.is_qualified())
00076 compile_error("can't define qualified ids in block scope");
00077
00078 Variable_symbol* vsym = new Variable_symbol(type, storage, init, 0, Symbol::st_Defined);
00079 add_symbol(sym_name.get_name(), vsym);
00080
00081
00082 if (storage == s_Parameter)
00083 fsig->add_parameter(vsym);
00084
00085 return vsym;
00086 }
00087
00088 #line 111 "block.cpp"
00089
00090 Function_signature*
00091 Block_scope::add_function_decl(Storage_class_specifier storage,
00092 Function_specifier_set fspec,
00093 Type type, const Symbol_name& sym_name)
00094 {
00095 compile_error("geht auch noch nicht");
00096 }
00097
00098 #line 119 "block.cpp"
00099
00100 void
00101 Block_scope::add_function_implementation(Function_signature* fsig,
00102 Block_scope* scope,
00103 Ptree* defn,
00104 Ptree* initializer)
00105 {
00106 compile_error("geht erst recht nicht");
00107 }
00108
00109 #line 128 "block.cpp"
00110
00111 void
00112 Block_scope::add_symbol(std::string name, Symbol* sym)
00113 {
00114
00115
00116
00117
00118
00119
00120
00121
00122 Symbol_table::get_instance().add_symbol(get_unique_name(name),
00123 name.length(), sym);
00124 }
00125
00126 #line 143 "block.cpp"
00127
00128 std::string
00129 Block_scope::get_unique_name(std::string name)
00130 {
00131 return Symbol_name::get_mangled_symbol_name(block_prefix, name);
00132 }
00133
00134 #line 149 "block.cpp"
00135
00136 Type
00137 Block_scope::get_this_type() const
00138 {
00139 return this_type;
00140 }
00141
00142 #line 161 "block.cpp"
00143
00144 void
00145 Block_scope::set_this_type(Type t)
00146 {
00147 this_type = t;
00148 }
00149
00150 #line 167 "block.cpp"
00151
00152 Symbol_pair
00153 Block_scope::lookup_here(std::string name, bool for_decl)
00154 {
00155 if (Symbol_pair p = Symbol_table::get_instance().get_symbol(get_unique_name(name)))
00156 return p;
00157 if (use_parent)
00158 return get_parent()->lookup_here(name, for_decl);
00159 else
00160 return Symbol_pair();
00161 }