Exemplo n.º 1
0
        public void create_main_function_as_in_module()
        {
            add_needed_cctors();
            statements_list sl        = new statements_list(loc);
            statements_list intern_sl = new statements_list(loc);
            statements_list sl2       = sl;

            sl = new statements_list(null);
            common_namespace_function_node init_func = new common_namespace_function_node("$_Init_", null, null, common_namespaces[0], null);

            common_namespaces[0].functions.AddElement(init_func);
            namespace_variable init_var = new namespace_variable("$is_init", SystemLibrary.SystemLibrary.bool_type, common_namespaces[0], null);

            common_namespaces[0].variables.AddElement(init_var);
            for (int i = 0; i < units.Count; i++)
            {
                if (units[i].main_function != null)
                {
                    common_namespace_function_call cnfc = new common_namespace_function_call(units[i].main_function, loc);
                    sl.statements.AddElement(cnfc);
                }
            }

            /*for (int i = units.Count - 1; i >= 0; i--)
             * {
             *  if (units[i].finalization_method != null)
             *  {
             *      common_namespace_function_call cnfc = new common_namespace_function_call(units[i].finalization_method, loc);
             *      sl.statements.AddElement(cnfc);
             *  }
             * }*/
            sl2 = new statements_list(loc);
            basic_function_call bfc = new basic_function_call(SystemLibrary.SystemLibrary.bool_assign as basic_function_node, null);

            bfc.parameters.AddElement(new namespace_variable_reference(init_var, null));
            bfc.parameters.AddElement(new bool_const_node(true, null));
            sl.statements.AddElementFirst(bfc);
            bfc = new basic_function_call(SystemLibrary.SystemLibrary.bool_not as basic_function_node, null);
            bfc.parameters.AddElement(new namespace_variable_reference(init_var, null));
            sl2.statements.AddElement(new if_node(bfc, sl, null, null));
            init_func.function_code = sl2;
            _init_code = new common_namespace_function_call(init_func, null);
            add_initialization_to_cctors();
        }
 private void SaveVariableReferencePosition(namespace_variable nv)
 {
     List<int> offs = (List<int>)var_positions[nv];
     if (offs == null)
     {
         offs = new List<int>();
         var_positions[nv] = offs;
     }
     offs.Add((int)bw.BaseStream.Position);
 }
		private int GetVariableReference(namespace_variable nv, ref byte is_def)
		{
            int off = 0;
            if (members.TryGetValue(nv, out off)) //если этот тип описан в этом модуле
            {
                is_def = 1;
                return off;//возвращаем его смещение
            }
            if (!used_units.ContainsKey(nv.namespace_node))
            {
                is_def = 1;
                return -1;
            }
			is_def = 0;
            ImportedEntity ie = null;
            if (ext_members.TryGetValue(nv, out ie))
            {
                return ie.index * ie.GetSize();
            }
			ie = new ImportedEntity();
			ie.flag = ImportKind.Common;
			ie.num_unit = GetUnitToken(nv.namespace_node);
			ie.offset = GetExternalOffset(nv);
			int offset = imp_entitles.Count*ie.GetSize();
            ie.index = imp_entitles.Count;
            imp_entitles.Add(ie);
			ext_members[nv] = ie;
			return offset;
		}
Exemplo n.º 4
0
        public void create_main_function(string[] used_stand_modules, Dictionary <string, object> config)
        {
            add_needed_cctors();
            common_namespace_function_node temp = _main_function;

            _main_function = new common_namespace_function_node("Main", null, null, (common_namespace_node)_main_function.comprehensive_namespace, null);
            location        loc = temp.loc;
            statements_list sl  = new statements_list(loc);

            _main_function.function_code = sl;
//            if (units[0].MainArgsParameter!=null)
//            {
//                _main_function.parameters.AddElement(units[0].MainArgsParameter);
//                sl.statements.AddElement(units[0].MainArgsAssignExpr);
//            }
//            if (units[0].IsConsoleApplicationVariableAssignExpr!=null)
//            {
//                sl.statements.AddElement(units[0].IsConsoleApplicationVariableAssignExpr);
//            }
            statements_list sl2 = sl;

            sl = new statements_list(null);
            common_namespace_function_node init_func = new common_namespace_function_node("$_Init_", null, null, (common_namespace_node)_main_function.comprehensive_namespace, null);

            ((common_namespace_node)_main_function.comprehensive_namespace).functions.AddElement(init_func);
            namespace_variable init_var = new namespace_variable("$is_init", SystemLibrary.SystemLibrary.bool_type, (common_namespace_node)_main_function.comprehensive_namespace, null);

            ((common_namespace_node)_main_function.comprehensive_namespace).variables.AddElement(init_var);
            if (SystemLibrary.SystemLibInitializer.ConfigVariable != null && SystemLibrary.SystemLibInitializer.ConfigVariable.Found)
            {
                namespace_variable           conf_nv = null;
                compiled_variable_definition conf_cf = null;
                if (SystemLibrary.SystemLibInitializer.ConfigVariable.sym_info is namespace_variable)
                {
                    conf_nv = SystemLibrary.SystemLibInitializer.ConfigVariable.sym_info as namespace_variable;
                }
                else
                {
                    conf_cf = SystemLibrary.SystemLibInitializer.ConfigVariable.sym_info as compiled_variable_definition;
                }
                foreach (string config_var in config.Keys)
                {
                    var config_value           = config[config_var];
                    compiled_function_call cfc = new compiled_function_call(compiled_function_node.get_compiled_method(NetHelper.NetHelper.AddToDictionaryMethod),
                                                                            (conf_nv != null) ? (expression_node) new namespace_variable_reference(conf_nv, null) : (expression_node) new static_compiled_variable_reference(conf_cf, null), null);
                    cfc.parameters.AddElement(new string_const_node(config_var, null));
                    switch (Type.GetTypeCode(config_value.GetType()))
                    {
                    case TypeCode.String:
                        cfc.parameters.AddElement(new string_const_node((string)config_value, null));
                        break;

                    case TypeCode.Int32:
                        cfc.parameters.AddElement(new int_const_node((int)config_value, null));
                        break;

                    case TypeCode.Boolean:
                        cfc.parameters.AddElement(new bool_const_node((bool)config_value, null));
                        break;

                    case TypeCode.Double:
                        cfc.parameters.AddElement(new double_const_node((double)config_value, null));
                        break;

                    default:
                        throw new NotSupportedException("Config value type is nort supported");
                    }
                    sl.statements.AddElement(cfc);
                }
            }
            if (units[0].MainArgsParameter != null)
            {
                _main_function.parameters.AddElement(units[0].MainArgsParameter);
                sl.statements.AddElementFirst(units[0].MainArgsAssignExpr);
            }
            if (units[0].IsConsoleApplicationVariableAssignExpr != null)
            {
                sl.statements.AddElementFirst(units[0].IsConsoleApplicationVariableAssignExpr);
            }
            for (int i = 0; i < units.Count; i++)
            {
                if (units[i].main_function != null)
                {
                    if (units[i].main_function.name != TreeConverter.compiler_string_consts.temp_main_function_name)
                    {
                        common_namespace_function_call cnfc = new common_namespace_function_call(units[i].main_function, loc);
                        sl.statements.AddElement(cnfc);
                    }
                    else
                    {
                        common_namespace_function_call cnfc = new common_namespace_function_call(units[i].main_function, loc);
                        sl2.statements.AddElement(cnfc);
                    }
                }
            }
            //if (units.Count == 1)
            for (int i = 0; i < used_stand_modules.Length; i++)
            {
                Type t = NetHelper.NetHelper.FindRtlType(used_stand_modules[i] + "." + used_stand_modules[i]);
                if (t == null)
                {
                    continue;
                }
                compiled_type_node           ctn = compiled_type_node.get_type_node(t);
                System.Reflection.MethodInfo mi  = ctn.compiled_type.GetMethod("__InitModule__");
                if (mi == null)
                {
                    continue;
                }
                compiled_static_method_call csmc = new compiled_static_method_call(compiled_function_node.get_compiled_method(mi), null);
                sl.statements.AddElement(csmc);
            }
            for (int i = units.Count - 1; i >= 0; i--)
            {
                if (units[i].finalization_method != null)
                {
                    common_namespace_function_call cnfc = new common_namespace_function_call(units[i].finalization_method, loc);
                    sl2.statements.AddElement(cnfc);
                }
            }
            //if (units.Count == 1)
            for (int i = 0; i < used_stand_modules.Length; i++)
            {
                Type t = NetHelper.NetHelper.FindRtlType(used_stand_modules[i] + "." + used_stand_modules[i]);
                if (t == null)
                {
                    continue;
                }
                compiled_type_node           ctn = compiled_type_node.get_type_node(t);
                System.Reflection.MethodInfo mi  = ctn.compiled_type.GetMethod("__FinalizeModule__");
                if (mi == null)
                {
                    continue;
                }
                compiled_static_method_call csmc = new compiled_static_method_call(compiled_function_node.get_compiled_method(mi), null);
                sl2.statements.AddElement(csmc);
            }
            sl2 = new statements_list(loc);
            basic_function_call bfc = new basic_function_call(SystemLibrary.SystemLibrary.bool_assign as basic_function_node, null);

            bfc.parameters.AddElement(new namespace_variable_reference(init_var, null));
            bfc.parameters.AddElement(new bool_const_node(true, null));
            sl.statements.AddElementFirst(bfc);
            bfc = new basic_function_call(SystemLibrary.SystemLibrary.bool_not as basic_function_node, null);
            bfc.parameters.AddElement(new namespace_variable_reference(init_var, null));
            sl2.statements.AddElement(new if_node(bfc, sl, null, null));
            init_func.function_code = sl2;
            sl = new statements_list(null);

            sl.statements.AddElement(new common_namespace_function_call(init_func, null));
            common_namespace_function_node init_variables_func = new common_namespace_function_node("$_InitVariables_", null, null, (common_namespace_node)_main_function.comprehensive_namespace, null);

            init_variables_func.function_code = new statements_list(null);
            ((common_namespace_node)_main_function.comprehensive_namespace).functions.AddElement(init_variables_func);

            sl.statements.AddElement(new common_namespace_function_call(init_variables_func, null));
            _init_code = sl;
        }
        public namespace_variable GetNamespaceVariable(int offset)
		{
            definition_node dn = null;
            if (members.TryGetValue(offset, out dn))
                return dn as namespace_variable;
			namespace_variable nv = null;
			int pos = (int)br.BaseStream.Position;
			br.BaseStream.Seek(start_pos+offset,SeekOrigin.Begin);
			br.ReadByte();
			int ind = br.ReadInt32();
			string name;
			bool is_interface = br.ReadBoolean();
			if (is_interface)//пропускаем флаг - интерфейсности
			{
				name = GetString(br.ReadInt32());
			}
			else
			{
				name = br.ReadString();
			}
            nv = new namespace_variable(name, null, null, null);
            if (is_interface)
            	AddVarToOrderList(nv,ind);
            else
            	AddImplVarToOrderList(nv,ind);
            nv.type = GetTypeReference();
            //members[offset] = nv;
            AddMember(nv, offset);            
            br.ReadInt32();//namespace
			nv.loc = ReadDebugInfo();
            if (is_interface)
            {
                nv.namespace_node = cun.namespaces[0];
                int_members.Add(nv);
            }
            else
            {
                nv.namespace_node = cun.namespaces[1];
                impl_members.Add(nv);
            }
            if (CanReadObject())
                nv.inital_value = CreateExpressionWithOffset();
			br.BaseStream.Seek(pos,SeekOrigin.Begin);
            return nv;
		}
Exemplo n.º 6
0
		public var_definition_node create_temp_variable(string name,type_node type,location loc)
		{
			var_definition_node vdn=null;
			switch (converting_block())
			{
				case block_type.function_block:
				{
                    common_function_node top_func = _func_stack.top();
					local_variable lv=new local_variable(name,type,top_func,loc);
					vdn=lv;
					top_func.var_definition_nodes_list.AddElement(lv);
					break;
				}
				case block_type.type_block:
				{
                    //TODO:сделать static и virtual.
					class_field cf=new class_field(name,type,_ctn,SemanticTree.polymorphic_state.ps_common,_fal,loc);
					vdn=cf;
					_ctn.fields.AddElement(cf);
					break;
				}
				case block_type.namespace_block:
				{
					namespace_variable nsv=new namespace_variable(name,type,_cmn,loc);
					vdn=nsv;
					_cmn.variables.AddElement(nsv);
					break;
				}
			}
			return vdn;
		}
Exemplo n.º 7
0
 public void create_main_function_as_in_module()
 {
     add_needed_cctors();
     statements_list sl = new statements_list(loc);
     statements_list intern_sl = new statements_list(loc);
     statements_list sl2 = sl;
     sl = new statements_list(null);
     common_namespace_function_node init_func = new common_namespace_function_node("$_Init_", null, null, common_namespaces[0], null);
     common_namespaces[0].functions.AddElement(init_func);
     namespace_variable init_var = new namespace_variable("$is_init", SystemLibrary.SystemLibrary.bool_type, common_namespaces[0], null);
     common_namespaces[0].variables.AddElement(init_var);
     for (int i = 0; i < units.Count; i++)
     {
         if (units[i].main_function != null)
         {
             common_namespace_function_call cnfc = new common_namespace_function_call(units[i].main_function, loc);
             sl.statements.AddElement(cnfc);
         }
     }
     /*for (int i = units.Count - 1; i >= 0; i--)
     {
         if (units[i].finalization_method != null)
         {
             common_namespace_function_call cnfc = new common_namespace_function_call(units[i].finalization_method, loc);
             sl.statements.AddElement(cnfc);
         }
     }*/
     sl2 = new statements_list(loc);
     basic_function_call bfc = new basic_function_call(SystemLibrary.SystemLibrary.bool_assign as basic_function_node, null);
     bfc.parameters.AddElement(new namespace_variable_reference(init_var, null));
     bfc.parameters.AddElement(new bool_const_node(true, null));
     sl.statements.AddElementFirst(bfc);
     bfc = new basic_function_call(SystemLibrary.SystemLibrary.bool_not as basic_function_node, null);
     bfc.parameters.AddElement(new namespace_variable_reference(init_var, null));
     sl2.statements.AddElement(new if_node(bfc, sl, null, null));
     init_func.function_code = sl2;
     _init_code = new common_namespace_function_call(init_func, null);
     add_initialization_to_cctors();
 }
        public common_namespace_event add_namespace_event(string name, location loc, type_node tn)
        {
            namespace_variable nv = new namespace_variable(name + "$", tn, converted_namespace, loc);
            common_namespace_event cne = new common_namespace_event(name, tn, converted_namespace, null, null, null, loc);
            common_namespace_function_node add_func = new common_namespace_function_node(compiler_string_consts.GetAddHandler(name),
                null, this.converted_namespace, null);
            common_parameter cp = new common_parameter("value", tn, SemanticTree.parameter_type.value, add_func, concrete_parameter_type.cpt_none, null, null);
            add_func.parameters.AddElement(cp);
            expression_node fld_ref = null;
            fld_ref = new namespace_variable_reference(nv, null);
            expression_node en = this.syntax_tree_visitor.convertion_data_and_alghoritms.type_constructor.delegate_add_assign_compile_time_executor
                (null, new expression_node[2] { fld_ref, new common_parameter_reference(cp, 0, null) });
            //en = this.syntax_tree_visitor.convertion_data_and_alghoritms.create_simple_function_call(tn.find_in_type(compiler_string_consts.assign_name).sym_info as function_node,null,
            //                                                                                    fld_ref,en);
            add_func.function_code = new statements_list(null);
            (add_func.function_code as statements_list).statements.AddElement(en);
            //remove
            common_namespace_function_node remove_func = new common_namespace_function_node(compiler_string_consts.GetRemoveHandler(name), null, this.converted_namespace, null);

            cp = new common_parameter("value", tn, SemanticTree.parameter_type.value, add_func, concrete_parameter_type.cpt_none, null, null);
            remove_func.parameters.AddElement(cp);
            en = this.syntax_tree_visitor.convertion_data_and_alghoritms.type_constructor.delegate_sub_assign_compile_time_executor
                (null, new expression_node[2] { fld_ref, new common_parameter_reference(cp, 0, null) });
            //en = this.syntax_tree_visitor.convertion_data_and_alghoritms.create_simple_function_call(tn.find_in_type(compiler_string_consts.assign_name).sym_info as function_node,null,
            //                                                                                    fld_ref,en);
            remove_func.function_code = new statements_list(null);
            (remove_func.function_code as statements_list).statements.AddElement(en);
            this.converted_namespace.functions.AddElement(add_func);
            this.converted_namespace.functions.AddElement(remove_func);
            cne.set_add_function(add_func);
            cne.set_remove_function(remove_func);
            cne.field = nv;
            this.converted_namespace.events.AddElement(cne);
            this.converted_namespace.variables.AddElement(nv);
            CurrentScope.AddSymbol(name, new SymbolInfo(cne));
            return cne;
        }
        public SymbolInfo(namespace_variable value)
		{
			//_name_information_type=name_information_type.nit_namespace_variable;
			_sym_info=value;
			_access_level=access_level.al_public;
			_symbol_kind=symbol_kind.sk_none;
		}
Exemplo n.º 10
0
        public void create_main_function(string[] used_stand_modules, Dictionary<string, object> config)
        {
        	add_needed_cctors();
        	common_namespace_function_node temp = _main_function;
            _main_function = new common_namespace_function_node("Main", null, null, (common_namespace_node)_main_function.comprehensive_namespace, null);
            location loc = temp.loc;
            statements_list sl = new statements_list(loc);
            _main_function.function_code = sl;
//            if (units[0].MainArgsParameter!=null)
//            {
//                _main_function.parameters.AddElement(units[0].MainArgsParameter);
//                sl.statements.AddElement(units[0].MainArgsAssignExpr);
//            }
//            if (units[0].IsConsoleApplicationVariableAssignExpr!=null)
//            {
//                sl.statements.AddElement(units[0].IsConsoleApplicationVariableAssignExpr);
//            }
            statements_list sl2 = sl;
            sl = new statements_list(null);
            common_namespace_function_node init_func = new common_namespace_function_node("$_Init_",null,null,(common_namespace_node)_main_function.comprehensive_namespace,null);
            ((common_namespace_node)_main_function.comprehensive_namespace).functions.AddElement(init_func);
            namespace_variable init_var = new namespace_variable("$is_init",SystemLibrary.SystemLibrary.bool_type,(common_namespace_node)_main_function.comprehensive_namespace,null);
            ((common_namespace_node)_main_function.comprehensive_namespace).variables.AddElement(init_var);
            if (SystemLibrary.SystemLibInitializer.ConfigVariable.Found)
            {
                namespace_variable conf_nv = null;
                compiled_variable_definition conf_cf = null;
                if (SystemLibrary.SystemLibInitializer.ConfigVariable.sym_info is namespace_variable)
                    conf_nv = SystemLibrary.SystemLibInitializer.ConfigVariable.sym_info as namespace_variable;
                else
                    conf_cf = SystemLibrary.SystemLibInitializer.ConfigVariable.sym_info as compiled_variable_definition;
                foreach (string config_var in config.Keys)
                {
                    var config_value = config[config_var];
                    compiled_function_call cfc = new compiled_function_call(compiled_function_node.get_compiled_method(NetHelper.NetHelper.AddToDictionaryMethod), 
                        (conf_nv != null) ? (expression_node)new namespace_variable_reference(conf_nv, null) : (expression_node)new static_compiled_variable_reference(conf_cf, null), null);
                    cfc.parameters.AddElement(new string_const_node(config_var, null));
                    switch (Type.GetTypeCode(config_value.GetType()))
                    {
                        case TypeCode.String:
                            cfc.parameters.AddElement(new string_const_node((string)config_value, null));
                            break;
                        case TypeCode.Int32:
                            cfc.parameters.AddElement(new int_const_node((int)config_value, null));
                            break;
                        case TypeCode.Boolean:
                            cfc.parameters.AddElement(new bool_const_node((bool)config_value, null));
                            break;
                        case TypeCode.Double:
                            cfc.parameters.AddElement(new double_const_node((double)config_value, null));
                            break;
                        default:
                            throw new NotSupportedException("Config value type is nort supported");
                    }
                    sl.statements.AddElement(cfc);
                }
            }
            if (units[0].MainArgsParameter!=null)
            {
                _main_function.parameters.AddElement(units[0].MainArgsParameter);
                sl.statements.AddElementFirst(units[0].MainArgsAssignExpr);
            }
            if (units[0].IsConsoleApplicationVariableAssignExpr!=null)
            {
                sl.statements.AddElementFirst(units[0].IsConsoleApplicationVariableAssignExpr);
            }
            for (int i = 0; i < units.Count; i++)
            {
                if (units[i].main_function != null)
                {
                	if (units[i].main_function.name != TreeConverter.compiler_string_consts.temp_main_function_name)
                	{
                		common_namespace_function_call cnfc = new common_namespace_function_call(units[i].main_function, loc);
                    	sl.statements.AddElement(cnfc);
                	}
                	else
                	{
                		common_namespace_function_call cnfc = new common_namespace_function_call(units[i].main_function, loc);
                    	sl2.statements.AddElement(cnfc);
                	}
                }
            }
            //if (units.Count == 1)
            for (int i = 0; i < used_stand_modules.Length; i++)
            {
                Type t = NetHelper.NetHelper.FindRtlType(used_stand_modules[i] + "." + used_stand_modules[i]);
                if (t == null)
                    continue;
                compiled_type_node ctn = compiled_type_node.get_type_node(t);
                System.Reflection.MethodInfo mi = ctn.compiled_type.GetMethod("__InitModule__");
                if (mi == null)
                {
                    continue;
                }
                compiled_static_method_call csmc = new compiled_static_method_call(compiled_function_node.get_compiled_method(mi), null);
                sl.statements.AddElement(csmc);
            }
            for (int i = units.Count - 1; i >= 0; i--)
            {
                if (units[i].finalization_method != null)
                {
                    common_namespace_function_call cnfc = new common_namespace_function_call(units[i].finalization_method, loc);
                    sl2.statements.AddElement(cnfc);
                }
            }
            //if (units.Count == 1)
            for (int i = 0; i < used_stand_modules.Length; i++)
            {
                Type t = NetHelper.NetHelper.FindRtlType(used_stand_modules[i] + "." + used_stand_modules[i]);
                if (t == null)
                    continue;
                compiled_type_node ctn = compiled_type_node.get_type_node(t);
                System.Reflection.MethodInfo mi = ctn.compiled_type.GetMethod("__FinalizeModule__");
                if (mi == null)
                    continue;
                compiled_static_method_call csmc = new compiled_static_method_call(compiled_function_node.get_compiled_method(mi), null);
                sl2.statements.AddElement(csmc);
            }
            sl2 = new statements_list(loc);
            basic_function_call bfc = new basic_function_call(SystemLibrary.SystemLibrary.bool_assign as basic_function_node,null);
            bfc.parameters.AddElement(new namespace_variable_reference(init_var,null));
            bfc.parameters.AddElement(new bool_const_node(true,null));
            sl.statements.AddElementFirst(bfc);
            bfc = new basic_function_call(SystemLibrary.SystemLibrary.bool_not as basic_function_node,null);
            bfc.parameters.AddElement(new namespace_variable_reference(init_var,null));
            sl2.statements.AddElement(new if_node(bfc,sl,null,null));
            init_func.function_code = sl2;
            sl = new statements_list(null);
            
            sl.statements.AddElement(new common_namespace_function_call(init_func,null));
            common_namespace_function_node init_variables_func = new common_namespace_function_node("$_InitVariables_", null, null, (common_namespace_node)_main_function.comprehensive_namespace, null);
            init_variables_func.function_code = new statements_list(null);
            ((common_namespace_node)_main_function.comprehensive_namespace).functions.AddElement(init_variables_func);
            
            sl.statements.AddElement(new common_namespace_function_call(init_variables_func,null));
            _init_code = sl;
            
        }
Exemplo n.º 11
0
 public namespace_variable_reference(namespace_variable var, location loc) :
     base(var.type, loc)
 {
     _var = var;
 }
Exemplo n.º 12
0
		public namespace_variable_reference(namespace_variable var,location loc) :
			base(var.type,loc)
		{
			_var=var;
		}
		public var_definition_node add_var_definition(string name, location loc, type_node tn, SemanticTree.polymorphic_state ps)
		{
			check_name_free(name,loc);
			var_definition_node vdn=null;
            if (CurrentScope is SymbolTable.BlockScope)
            {
                if (SemanticRules.DisabledDefinitionBlockVariablesWithSameNameThatInAboveScope)
                {
                    SymbolTable.Scope cs = CurrentScope;
                    while (cs.TopScope != null /*(cs.TopScope is SymbolTable.BlockScope || cs.TopScope is SymbolTable.UnitPartScope)*/)
                    {
                    	if (cs.TopScope is SymbolTable.BlockScope)//projdemsja po blokam koda
                    	{
                    		if (cs.TopScope.FindOnlyInScope(name) != null)
                                syntax_tree_visitor.AddError(loc, "BLOCK_VARIABLES_CANNOT_HAVE_NAMES_UPPER_SCOPE");
                    		cs = cs.TopScope;
                    	}
                    	else // a zdes proverjaem v verhnem bloke i vse, to chto eshe vyshe, tam ne proverjaem, tak dejstvuet princip blochnosti
                    	{
                    		if (cs.TopScope.FindOnlyInScope(name) != null)
                                syntax_tree_visitor.AddError(loc, "BLOCK_VARIABLES_CANNOT_HAVE_NAMES_UPPER_SCOPE");
                    		break;
                    	}
                        
                    }
                }
            	local_block_variable lv = new local_block_variable(name, tn, CurrentStatementList, loc);
                CurrentScope.AddSymbol(name, new SymbolInfo(lv));
                lv.block.local_variables.Add(lv);
                if (tn == null) //Тип еще неизвестен, будем закрывать.
                    var_defs.Add(lv);
                return lv;
            }
            switch (converting_block())
			{
				case block_type.function_block:
				{
                    common_function_node top_func = _func_stack.top();
					local_variable lv=new local_variable(name,tn,top_func,loc);
					vdn=lv;
					top_func.var_definition_nodes_list.AddElement(lv);
                    CurrentScope.AddSymbol(name, new SymbolInfo(lv));
					//top_func.scope.AddSymbol(name,new SymbolInfo(lv));
					break;
				}
				case block_type.type_block:
				{
                    //TODO:сделать static и virtual.
                    class_field cf = new class_field(name,tn, _ctn, ps,_fal,loc);
					vdn=cf;
					//_ctn.Scope.AddSymbol(name,new SymbolInfo(cf));
                    CurrentScope.AddSymbol(name, new SymbolInfo(cf));
					_ctn.fields.AddElement(cf);
					break;
				}
				case block_type.namespace_block:
				{
					namespace_variable nsv=new namespace_variable(name,tn,_cmn,loc);
					vdn=nsv;
					//_cmn.scope.AddSymbol(name,new SymbolInfo(nsv));
                    CurrentScope.AddSymbol(name, new SymbolInfo(nsv));
					_cmn.variables.AddElement(nsv);
					break;
				}
			}
            if (tn == null) //Тип еще неизвестен, будем закрывать.
                var_defs.Add(vdn);
            return vdn;
		}
		private void WriteVariableReference(namespace_variable nv)
		{
			byte is_def = 0;
			int offset = GetVariableReference(nv, ref is_def);
			bw.Write(is_def);
            if (offset == -1) SaveVariableReferencePosition(nv);
			bw.Write(offset);
		}
 private namespace_variable CreateInterfaceNamespaceVariable(string name, int offset)
 {
     definition_node dn = null;
     if (members.TryGetValue(offset, out dn))
         return dn as namespace_variable;
     namespace_variable nv = null;
     nv = new namespace_variable(name, null, cun.namespaces[0], null);
     int ind = br.ReadInt32();
     AddVarToOrderList(nv,ind);
     br.ReadBoolean();
     br.ReadInt32();
     nv.type = GetTypeReference();
     br.ReadInt32();//namespace
     nv.loc = ReadDebugInfo();
     if (CanReadObject())
         nv.inital_value = CreateExpressionWithOffset();
     //members[offset] = nv;
     AddMember(nv, offset);            
     int_members.Add(nv);
     return nv;
 }
        private void VisitVariableDefinition(namespace_variable var)
		{
			if (is_interface) 
                SavePositionAndConstPool(var);
			else 
                SavePositionAndImplementationPool(var);
			bw.Write((byte)var.semantic_node_type);
			bw.Write(entity_index++);
			bw.Write(is_interface);
			if (is_interface == true)
		 	    bw.Write(GetNameIndex(var));
			else
			    bw.Write(var.name);
			WriteTypeReference(var.type);
			bw.Write(GetUnitReference(var.namespace_node));
			WriteDebugInfo(var.loc);
            if (CanWriteObject(var.inital_value))
            {
            	SaveExpressionAndOffset(var.inital_value);
            	bw.Write(0);
            	//VisitExpression((expression_node)var.inital_value);
            }
        }
        public var_definition_node add_var_definition_in_entry_scope(string name, location loc)
        {
        	namespace_variable nsv=new namespace_variable(name,null,_cmn,loc);
			//_cmn.scope.AddSymbol(name,new SymbolInfo(nsv));
            CurrentScope.AddSymbol(name, new SymbolInfo(nsv));
			_cmn.variables.AddElement(nsv);
            var_defs.Add(nsv);
            return nsv;		
        }