示例#1
0
 private void VisitNestedFunction(common_in_function_function_node cnfn)
 {
     if (extended_mode)
         VisitVariables(cnfn.var_definition_nodes_list);
     foreach (var_definition_node vdn in cnfn.var_definition_nodes_list)
         helper.AddVariable(vdn);
     foreach (common_parameter prm in cnfn.parameters)
         helper.AddParameter(prm);
     foreach (common_in_function_function_node nested in cnfn.functions_nodes_list)
         VisitNestedFunction(nested);
     cur_func = cnfn;
     VisitStatement(cnfn.function_code);
     foreach (var_definition_node vdn2 in cnfn.var_definition_nodes_list)
     {
     	if (vdn2 is local_variable)
     	{
     		local_variable vdn = vdn2 as local_variable;
     		VarInfo vi = helper.GetVariable(vdn);
         	if (vi.num_use == 0 && !vdn.is_special_name) warns.Add(new UnusedVariable(vdn.name, vdn.loc));
             else if (vi.num_ass == 0 && vdn.is_ret_value && !cnfn.name.StartsWith("<>") && cnfn.return_value_type.type_special_kind != SemanticTree.type_special_kind.record && !cnfn.return_value_type.IsPointer && cnfn.return_value_type.type_special_kind != SemanticTree.type_special_kind.array_wrapper
             && !helper.IsExternal(cnfn)) warns.Add(new UndefinedReturnValue(cnfn.name, cnfn.function_code.location));
         	if (vi.num_ass > 0 && vi.act_num_use == 0 && !vdn.is_special_name) warns.Add(new AssignWithoutUsing(vdn.name, vi.last_ass_loc));
         //if (vi.num_ass == 0 && vi.act_num_use > 0) helper.AddRealWarning(vdn, warns);
     	}
     	else if (vdn2 is local_block_variable)
     	{
     		local_block_variable vdn = vdn2 as local_block_variable;
     		VarInfo vi = helper.GetVariable(vdn);
         	if (vi.num_use == 0 && !vdn.is_special_name) warns.Add(new UnusedVariable(vdn.name, vdn.loc));
             else if (vi.num_ass == 0 && vdn.is_ret_value && !cnfn.name.StartsWith("<>") && cnfn.return_value_type.type_special_kind != SemanticTree.type_special_kind.record && !cnfn.return_value_type.IsPointer && cnfn.return_value_type.type_special_kind != SemanticTree.type_special_kind.array_wrapper
             && !helper.IsExternal(cnfn)) warns.Add(new UndefinedReturnValue(cnfn.name, cnfn.function_code.location));
         	if (vi.num_ass > 0 && vi.act_num_use == 0 && !vdn.is_special_name) warns.Add(new AssignWithoutUsing(vdn.name, vi.last_ass_loc));
         //if (vi.num_ass == 0 && vi.act_num_use > 0) helper.AddRealWarning(vdn, warns);
     	}
     	if (vdn2.inital_value != null) VisitExpression(vdn2.inital_value);
     }
     foreach (common_parameter prm in cnfn.parameters)
     {
         ParamInfo vi = helper.GetParameter(prm);
         if (prm.inital_value != null) VisitExpression(prm.inital_value);
         //if (vi.num_use == 0 && !prm.name.Contains("$")) warns.Add(new UnusedParameter(prm.name, prm.loc));
     }
     foreach (var_definition_node vdn in cnfn.var_definition_nodes_list)
     {
     	VarInfo vi = helper.GetVariable(vdn);
     	if (vdn.inital_value != null) VisitExpression(vdn.inital_value);
     }
 }
		private void VisitNestedFunctionImplementation(common_in_function_function_node func)
		{
			foreach (common_in_function_function_node nested in func.functions_nodes_list)
				VisitNestedFunctionImplementation(nested);
            //(ssyy) метки
            VisitLabelDeclarations(func.label_nodes_list);
            FixupCode(func);
			VisitStatement(func.function_code);
		}
        //сохранение вложенной функций
		private void VisitNestedFunctionDefinition(common_in_function_function_node func)
		{
			SavePosition(func);
			bw.Write((byte)func.semantic_node_type);
			bw.Write(func.name);
			if (func.return_value_type == null) bw.Write((byte)0);
			else 
			{
				bw.Write((byte)1);
				WriteTypeReference(func.return_value_type);
				VisitLocalVariable(func.return_variable);
			}
            bw.Write(func.parameters.Count);
            foreach (common_parameter p in func.parameters)
                VisitParameter(p);
            bw.Write(0);
			bw.Write(func.is_forward);
			bw.Write(func.is_overload);
			bw.Write(func.num_of_default_variables);
			bw.Write(func.num_of_for_cycles);
			bw.Write(func.var_definition_nodes_list.Count);
			foreach (local_variable var in func.var_definition_nodes_list)
			 if (var != func.return_variable) VisitLocalVariable(var);
			bw.Write(func.constants.Count);
            foreach (function_constant_definition cnst in func.constants)
            	VisitFunctionConstant(cnst);
			bw.Write(func.functions_nodes.Length);
			foreach (common_in_function_function_node nest_func in func.functions_nodes_list)
			 VisitNestedFunctionDefinition(nest_func);
            WriteDebugInfo(func.loc);
            SaveCodeReference(func);
			bw.Write(0);
		}
示例#4
0
		public common_function_node create_function(string name,location def_loc)
		{
			check_function_name(name,def_loc);
			common_function_node cfn=null;
			switch (converting_block())
			{
				case block_type.function_block:
				{
                    common_function_node top_func = _func_stack.top();
                    SymbolTable.Scope scope = convertion_data_and_alghoritms.symbol_table.CreateScope(top_func.scope);
					common_in_function_function_node ciffn;
					ciffn=new common_in_function_function_node(name,def_loc,top_func,scope);
					top_func.functions_nodes_list.AddElement(ciffn);
					_last_created_function=new SymbolInfo(ciffn);
					top_func.scope.AddSymbol(name,_last_created_function);
					cfn=ciffn;
					break;
				}
				case block_type.type_block:
				{
					common_method_node cmmn;
                    SymbolTable.Scope scope = convertion_data_and_alghoritms.symbol_table.CreateClassMethodScope(_cmn.scope, _ctn.Scope);
                    //TODO:сделать static и virtual.
                    //TODO: interface and implementation scopes.
					cmmn=new common_method_node(name,def_loc,_ctn,SemanticTree.polymorphic_state.ps_common,_fal,scope);
					_last_created_function=new SymbolInfo(cmmn);
					_ctn.Scope.AddSymbol(name,_last_created_function);
					_ctn.methods.AddElement(cmmn);

                    local_variable lv = new local_variable(compiler_string_consts.self_word, _ctn, cmmn, def_loc);
                    cmmn.scope.AddSymbol(compiler_string_consts.self_word, new SymbolInfo(lv));
                    cmmn.self_variable = lv;
                    cmmn.var_definition_nodes_list.AddElement(lv);

					cfn=cmmn;
					break;
				}
				case block_type.namespace_block:
				{
					common_namespace_function_node cnfnn;
                    SymbolTable.Scope scope = convertion_data_and_alghoritms.symbol_table.CreateScope(_cmn.scope);
					cnfnn=new common_namespace_function_node(name,def_loc,_cmn,scope);
					_cmn.functions.AddElement(cnfnn);
					_last_created_function=new SymbolInfo(cnfnn);
					_cmn.scope.AddSymbol(name,_last_created_function);
					cfn=cnfnn;
					break;
				}
			}
			_func_stack.push(cfn);
			return cfn;
		}
		private common_in_function_function_call create_common_in_function_function_call(common_in_function_function_node cfn,
			int static_depth,location loc,params expression_node[] exprs)
		{

			common_in_function_function_call cc=new common_in_function_function_call(cfn,static_depth,loc);
			cc.parameters.AddRange(exprs);
			return cc;
		}
        //\ssyy

		private common_in_function_function_node GetNestedFunction()
		{
			int offset = (int)br.BaseStream.Position-start_pos;
			br.ReadByte();
			common_in_function_function_node cffn = new common_in_function_function_node(br.ReadString(),null,null,null);
			if (br.ReadByte() == 1)
			{
				cffn.return_value_type = GetTypeReference();
				cffn.return_variable = GetLocalVariable(cffn);
				cffn.var_definition_nodes_list.AddElement(cffn.return_variable);
			}
			int num_par = br.ReadInt32();
			for (int i=0; i<num_par; i++)
				cffn.parameters.AddElement(GetParameter(cffn));
			br.ReadInt32(); //namespace
			cffn.is_forward = br.ReadBoolean();
			cffn.is_overload = br.ReadBoolean();
			cffn.num_of_default_variables = br.ReadInt32();
			cffn.num_of_for_cycles = br.ReadInt32();
            //members[offset] = cffn;
            AddMember(cffn, offset);            
			int num_var = br.ReadInt32();
			if (cffn.return_value_type != null) num_var--;
            for (int i = 0; i < num_var; i++)
            {
                local_variable lv = GetLocalVariable(cffn);
                if (lv != cffn.return_variable)
                    cffn.var_definition_nodes_list.AddElement(lv);
            }
            int num_consts = br.ReadInt32();
            for (int i=0; i < num_consts; i++)
            {
            	cffn.constants.AddElement(GetFunctionConstant(cffn));
            }
            int num_nest_funcs = br.ReadInt32();
            for (int i = 0; i < num_nest_funcs; i++)
            {
                cffn.functions_nodes_list.AddElement(GetNestedFunction());
            }
            //br.ReadInt32();//code;
            cffn.loc = ReadDebugInfo();
            cffn.function_code = GetCode(br.ReadInt32());
			return cffn;
		}
		public SymbolInfo(common_in_function_function_node value)
		{
			//_name_information_type=name_information_type.nit_common_in_function_function;
			_sym_info=value;
			_access_level=access_level.al_public;
			_symbol_kind=get_function_kind(value);
		}
		public common_function_node create_function(string name,location def_loc, bool add_symbol_info)
		{
			if (converting_block() == block_type.compiled_type_block)
			{
				_compiled_tn = compiled_type_node.get_type_node(_compiled_tn.compiled_type,this.syntax_tree_visitor.SymbolTable);
			}
			check_function_name(name, def_loc);
            common_function_node cfn = null;
			switch (converting_block())
			{
				case block_type.function_block:
				{
                    common_function_node top_func = _func_stack.top();
                    SymbolTable.Scope scope = convertion_data_and_alghoritms.symbol_table.CreateScope(top_func.scope);
					common_in_function_function_node ciffn;
					ciffn=new common_in_function_function_node(name,def_loc,top_func,scope);
					top_func.functions_nodes_list.AddElement(ciffn);
                    _last_created_function = new SymbolInfo(ciffn);
                    if (add_symbol_info)
                        top_func.scope.AddSymbol(name, _last_created_function);
                    cfn=ciffn;
					break;
				}
				case block_type.type_block:
				{
                    if (!extension_method)
                    {
                        common_method_node cmmn;
                        SymbolTable.Scope scope = convertion_data_and_alghoritms.symbol_table.CreateClassMethodScope(_cmn.scope, _ctn.Scope);
                        //TODO:сделать static и virtual.
                        //TODO: interface and implementation scopes.
                        cmmn = new common_method_node(name, def_loc, _ctn, SemanticTree.polymorphic_state.ps_common, _fal, scope);

                        _last_created_function = new SymbolInfo(cmmn);
                        if (add_symbol_info)
                            _ctn.Scope.AddSymbol(name, _last_created_function);
                        _ctn.methods.AddElement(cmmn);

                        cfn = cmmn;
                    }
                    else
                    {
                        common_namespace_function_node cnfnn;
                        SymbolTable.Scope scope = convertion_data_and_alghoritms.symbol_table.CreateClassMethodScope(_cmn.scope, _ctn.scope);
                        cnfnn = new common_namespace_function_node(name, def_loc, _cmn, scope);
                        //_cmn.functions.AddElement(cnfnn);
                        syntax_tree_visitor.compiled_unit.namespaces[0].functions.AddElement(cnfnn);
                        cnfnn.ConnectedToType = _ctn;
                        _last_created_function = new SymbolInfo(cnfnn);
                        if (add_symbol_info)
                            _ctn.scope.AddSymbol(name, _last_created_function);
                        cfn = cnfnn;
                    }
					break;
				}
                case block_type.compiled_type_block:
                {
                    //string cname = compiler_string_consts.GetConnectedFunctionName(_compiled_tn.name, name);
                    common_namespace_function_node cnfnn;
                    SymbolTable.Scope scope = convertion_data_and_alghoritms.symbol_table.CreateClassMethodScope(_cmn.scope, _compiled_tn.scope);
                    cnfnn = new common_namespace_function_node(name, def_loc, _cmn, scope);
                    //_cmn.functions.AddElement(cnfnn);
                    syntax_tree_visitor.compiled_unit.namespaces[0].functions.AddElement(cnfnn);
                    cnfnn.ConnectedToType = _compiled_tn;
                    _last_created_function = new SymbolInfo(cnfnn);
                    if (add_symbol_info)
                        _compiled_tn.scope.AddSymbol(name, _last_created_function);
                    SymbolInfo sss = _compiled_tn.find_in_type("Hello");
                    cfn = cnfnn;
                    //if(_compiled_tn.compiled_type.IsPrimitive)
                    //    syntax_tree_visitor.WarningsList.Add(new PascalABCCompiler.Errors.CompilerWarning
                    break;
                }
				case block_type.namespace_block:
				{
					common_namespace_function_node cnfnn;
                    SymbolTable.Scope scope = convertion_data_and_alghoritms.symbol_table.CreateScope(_cmn.scope);
					cnfnn=new common_namespace_function_node(name,def_loc,_cmn,scope);
					_cmn.functions.AddElement(cnfnn);
					_last_created_function=new SymbolInfo(cnfnn);
                    if (add_symbol_info)                    
					    _cmn.scope.AddSymbol(name,_last_created_function);
					cfn=cnfnn;
					break;
				}
			}
			_func_stack.push(cfn);
			return cfn;
		}