Exemple #1
0
 private void VisitCommonStaticMethodCall(common_static_method_call en)
 {
     for (int i = 0; i < en.parameters.Count; i++)
     {
         VisitExpression(en.parameters[i]);
     }
 }
Exemple #2
0
 private void VisitCommonStaticMethodCall(common_static_method_call en)
 {
 	for (int i = 0; i < en.parameters.Count; i++)
         VisitExpression(en.parameters[i]);
 }
		private void VisitCommonStaticMethodCall(common_static_method_call expr)
		{
			WriteMethodReference(expr.function_node);
            //ssyy
            if (expr.last_result_function_call)
            {
                bw.Write((byte)1);
            }
            else
            {
                bw.Write((byte)0);
            }
            //\ssyy
            bw.Write(expr.parameters.Count);
			foreach (expression_node e in expr.parameters)
				VisitExpression(e);
		}
 private base_function_call create_not_static_method_call(function_node fn, expression_node en, location loc, bool procedure_allowed)
 {
     try_convert_typed_expression_to_function_call(ref en);
     if ((!procedure_allowed) && (fn.return_value_type == null))
     {
         AddError(loc, "FUNCTION_EXPECTED_PROCEDURE_{0}_MEET", fn);
     }
     if (fn.semantic_node_type == semantic_node_type.common_method_node)
     {
         common_method_node cmn = (common_method_node)fn;
         if (cmn.is_constructor)
         {
             AddError(loc, "CAN_NOT_CALL_CONSTRUCTOR_AS_PROCEDURE");
         }
         if (cmn.original_function != null && cmn.original_function is compiled_function_node && (cmn.original_function as compiled_function_node).ConnectedToType != null)
         {
             common_static_method_call csmc = new common_static_method_call(cmn, loc);
             return csmc;
         }
         if (cmn.polymorphic_state == SemanticTree.polymorphic_state.ps_static)
         {
             AddError(new CanNotCallStaticMethodWithExpression(en, fn));
         }
         
         common_method_call cmc = new common_method_call(cmn, en, loc);
         cmc.virtual_call = !inherited_ident_processing;
         return cmc;
     }
     if (fn.semantic_node_type == semantic_node_type.compiled_function_node)
     {
         compiled_function_node cfn = (compiled_function_node)fn;
         if (cfn.ConnectedToType != null)
         {
             compiled_static_method_call csmc = new compiled_static_method_call(cfn, loc);
             return csmc;
         }
         else
         {
             if (cfn.polymorphic_state == SemanticTree.polymorphic_state.ps_static)
             {
                 if (!cfn.is_extension_method)
                     AddError(new CanNotCallStaticMethodWithExpression(en, fn));
                 else
                     return new compiled_static_method_call(cfn, loc);
             }
             compiled_function_call cfc = new compiled_function_call(cfn, en, loc);
             cfc.virtual_call = !inherited_ident_processing;
             return cfc;
         }
     }
     if (fn.semantic_node_type == semantic_node_type.compiled_constructor_node)
     {
         AddError(loc, "CAN_NOT_CALL_CONSTRUCTOR_AS_PROCEDURE");
     }
     if (fn.semantic_node_type == semantic_node_type.common_namespace_function_node && (fn as common_namespace_function_node).ConnectedToType != null)
     {
     	common_namespace_function_call cnfc = new common_namespace_function_call(fn as common_namespace_function_node,loc);
     	//cnfc.parameters.AddElement(en);
     	return cnfc;
     }
     if (fn.semantic_node_type == semantic_node_type.indefinite_definition_node)
     {
         indefinite_function_call ifc = new indefinite_function_call(fn, loc);
         return ifc;
     }
     throw new CompilerInternalError("Invalid method kind");
 }
 private base_function_call create_static_method_call(function_node fn, location loc, type_node tn, bool procedure_allowed)
 {
     if ((!procedure_allowed) && (fn.return_value_type == null))
     {
         AddError(loc, "FUNCTION_EXPECTED_PROCEDURE_{0}_MEET", fn.name);
     }
     if (fn.semantic_node_type == semantic_node_type.common_method_node)
     {
         common_method_node cmn = (common_method_node)fn;
         if (cmn.polymorphic_state != SemanticTree.polymorphic_state.ps_static)
         {
             //ssyy изменил
             if (!cmn.is_constructor)
             {
                 AddError(new CanNotCallNonStaticMethodWithClass(tn, loc, fn));
             }
             if (cmn.cont_type.IsAbstract)
             	ErrorsList.Add(new SimpleSemanticError(loc, "ABSTRACT_CONSTRUCTOR_{0}_CALL", cmn.name));
             common_constructor_call csmc2 = new common_constructor_call(cmn, loc);
             return csmc2;
             //if (cmn.pascal_associated_constructor==null)
             //{
             //	throw new CanNotCallNonStaticMethodWithClass(tn,loc,fn);
             //}
             //common_constructor_call csmc2=new common_constructor_call(cmn.pascal_associated_constructor,loc);
             //return csmc2;
             //\ssyy
         }
         common_static_method_call csmc = new common_static_method_call(cmn, loc);
         return csmc;
     }
     if (fn.semantic_node_type == semantic_node_type.compiled_function_node)
     {
         compiled_function_node cfn = (compiled_function_node)fn;
         if (cfn.polymorphic_state != SemanticTree.polymorphic_state.ps_static)
         {
             AddError(new CanNotCallNonStaticMethodWithClass(tn, loc, fn));
         }
         compiled_static_method_call csmc2 = new compiled_static_method_call(cfn, loc);
         return csmc2;
     }
     if (fn.semantic_node_type == semantic_node_type.compiled_constructor_node)
     {
         compiled_constructor_node ccn = (compiled_constructor_node)fn;
         compiled_constructor_call ccc = new compiled_constructor_call(ccn, loc);
         return ccc;
     }
     if (fn.semantic_node_type == semantic_node_type.basic_function_node)
     {
         return new basic_function_call(fn as basic_function_node, loc);
     }
     if (fn.semantic_node_type == semantic_node_type.common_namespace_function_node && (fn as common_namespace_function_node).ConnectedToType != null)
     {
     	return new common_namespace_function_call(fn as common_namespace_function_node,loc);
     }
     if (fn.semantic_node_type == semantic_node_type.indefinite_definition_node)
     {
         return new indefinite_function_call(fn, loc);
     }
     throw new CompilerInternalError("Invalid method kind");
 }
 private function_node GenerateSetMethod(common_property_node cpn, common_method_node accessor, location loc)
 {
     common_method_node cmn = new common_method_node(
         "set_" + cpn.name, loc, cpn.common_comprehensive_type,
         cpn.polymorphic_state, cpn.field_access_level, null);
     cpn.common_comprehensive_type.methods.AddElement(cmn);
     //cmn.return_value_type = cpn.property_type;
     cmn.is_overload = true;
     foreach (common_parameter cp in accessor.parameters)
     {
         common_parameter new_cp = new common_parameter(cp.name, cp.type, cp.parameter_type, cp.common_function, cp.concrete_parameter_type, cp.default_value, loc);
         cmn.parameters.AddElement(new_cp);
     }
     expression_node meth_call;
     if (cpn.polymorphic_state == SemanticTree.polymorphic_state.ps_common)
     {
         meth_call = new common_method_call(accessor, new this_node(cpn.common_comprehensive_type, loc), loc);
         foreach (common_parameter cp in cmn.parameters)
         {
             (meth_call as common_method_call).parameters.AddElement(new common_parameter_reference(cp, 0, loc));
         }
     }
     else
     {
         meth_call = new common_static_method_call(accessor, loc);
         foreach (common_parameter cp in cmn.parameters)
         {
             (meth_call as common_static_method_call).parameters.AddElement(new common_parameter_reference(cp, 0, loc));
         }
     }
     cmn.function_code = meth_call;
     cpn.common_comprehensive_type.scope.AddSymbol("set_" + cpn.name, new SymbolInfo(cmn));
     return cmn;
 }
        private base_function_call_list convert_functions_to_calls(expression_node obj, function_node_list fnl, location loc, bool is_static)
        {
            base_function_call_list ret = new base_function_call_list();
            foreach (function_node fnode in fnl)
            {
                base_function_call bfc = null;
                switch (fnode.semantic_node_type)
                {
                    case semantic_node_type.common_namespace_function_node:
                        {
                            common_namespace_function_node cmfn = fnode as common_namespace_function_node;
                            common_namespace_function_call cnfc = new common_namespace_function_call(cmfn, loc);
                            if (cmfn.ConnectedToType != null)
                                cnfc.parameters.AddElement(obj);
                            if (cmfn.is_generic_function && !cmfn.is_generic_function_instance && cmfn.ConnectedToType != null && cmfn.parameters.Count == 1)
                            {
                                expressions_list parameters = new expressions_list();
                                parameters.AddElement(obj);
                                function_node inst = null;
                                try
                                {
                                    inst = generic_convertions.DeduceFunction(cmfn, parameters, true, loc);
                                }
                                catch
                                {
                                    continue;
                                }
                                cnfc = new common_namespace_function_call((common_namespace_function_node)inst, loc);
                                if (cmfn.ConnectedToType != null)
                                    cnfc.parameters.AddElement(obj);
                            }
                            /*if (cmfn.parameters.Count >= 1 && cmfn.parameters[cmfn.parameters.Count - 1].is_params)
                            {
                                convertion_data_and_alghoritms.select_function(cnfc.parameters, new SymbolInfo(cmfn), loc);
                                
                            }*/
                            bfc = cnfc;
                            break;
                        }
                    case semantic_node_type.basic_function_node:
                        {
                            //Может здесь стоит и выругаться, но я не буду пока этого делать.
                            break;
                        }
                    case semantic_node_type.common_in_function_function_node:
                        {
                            common_in_function_function_node ciffn = fnode as common_in_function_function_node;
                            int depth = convertion_data_and_alghoritms.symbol_table.GetRelativeScopeDepth(ciffn.scope,
                                context.top_function.scope);
                            common_in_function_function_call ciffc = new common_in_function_function_call(ciffn, depth, loc);
                            bfc = ciffc;
                            break;
                        }
                    case semantic_node_type.common_method_node:
                        {
                            common_method_node cmn = fnode as common_method_node;
                            //Если cmn конструктор - то плохо, но его не должно сюда попасть.
                            if (cmn.polymorphic_state != SemanticTree.polymorphic_state.ps_static)
                            {
                                if (!is_static)
                                {
                                    if (obj == null)
                                        obj = GetCurrentObjectReference(cmn.cont_type.Scope, cmn, loc);//new this_node(context.converted_type, loc);
                                    common_method_call cmc = new common_method_call(cmn, obj, loc);
                                    cmc.virtual_call = !inherited_ident_processing;
                                    bfc = cmc;
                                }
                                //ssyy!!! Мне сложно понять предназначение данного кода, но, по-видимому,
                                //следует его переписать так.
                                else if (cmn.is_constructor)
                                {
                                    if (cmn.parameters.Count == 0)
                                    {
                                    	if (cmn.cont_type.IsAbstract)
                                            AddError(loc, "ABSTRACT_CONSTRUCTOR_{0}_CALL", cmn.cont_type.name);
                                    	ret.clear();
                                        ret.AddElement(new common_constructor_call(cmn, loc));
                                        return ret;
                                    }
                                }
                            }
                            else
                            {
                                if (is_static)
                                {
                                    common_static_method_call csmc = new common_static_method_call(cmn, loc);
                                    bfc = csmc;
                                }
                            }
                            break;
                        }
                    case semantic_node_type.compiled_function_node:
                        {
                            compiled_function_node cfn = fnode as compiled_function_node;
                            if (cfn.cont_type.Scope == null && cfn is compiled_function_node)
                        	(cfn.cont_type as compiled_type_node).init_scope();
                            
                            if (cfn.polymorphic_state == SemanticTree.polymorphic_state.ps_static)
                            {
                                //ispravleno ibond
                            	//if (is_static)
                                {

                                    if (cfn.is_generic_function && !cfn.is_generic_function_instance && cfn.ConnectedToType != null && cfn.parameters.Count == 1)
                                    {
                                        expressions_list parameters = new expressions_list();
                                        parameters.AddElement(obj);
                                        function_node inst = null;
                                        try
                                        {
                                            inst = generic_convertions.DeduceFunction(cfn, parameters, true, loc);
                                        }
                                        catch
                                        {
                                            continue;
                                        }
                                        if (inst is common_namespace_function_node)
                                            bfc = new common_namespace_function_call((common_namespace_function_node)inst, loc);
                                        else if (inst is compiled_function_node)
                                            bfc = new compiled_static_method_call((compiled_function_node)inst, loc);
                                        else
                                            bfc = new compiled_static_method_call(cfn, loc);
                                    }
                                    else
                                    {
                                        compiled_static_method_call csmc = new compiled_static_method_call(cfn, loc);
                                        bfc = csmc;
                                        
                                    }
                                    if (cfn.ConnectedToType != null)
                                        bfc.parameters.AddElement(obj);
                                }
                            }
                            else
                            {
                                if (!is_static)
                                {
                                    if (obj == null)
                                        obj = GetCurrentObjectReference(cfn.cont_type.Scope, cfn, loc);//new this_node(context.converted_type, loc);
                                    compiled_function_call cfc = new compiled_function_call(cfn, obj, loc);
                                    cfc.virtual_call = !inherited_ident_processing;
                                    bfc = cfc;
                                }
                            }
                            break;
                        }
                    case semantic_node_type.compiled_constructor_node:
                        {
                            //Этот код мы вроде не должны вызывать, но если он все-же вызовется.
                            compiled_constructor_node ccn = fnode as compiled_constructor_node;
                            compiled_constructor_call ccc = new compiled_constructor_call(ccn, loc);
                            bfc = ccc;
                            break;
                        }
                    default:
                        {
                            throw new CompilerInternalError("Undefined method type.");
                        }
                }
                if (bfc != null)
                {
                    ret.AddElement(bfc);
                }
            }
            return ret;
        }
		private common_static_method_call create_common_static_method_call(common_method_node cmn,SemanticTree.ILocation loc,
			params expression_node[] exprs)
		{
#if (DEBUG)
			if (cmn.polymorphic_state!=SemanticTree.polymorphic_state.ps_static)
			{
				throw new CompilerInternalError("Not static method can not be called as static");
			}
#endif
			common_static_method_call csmc=new common_static_method_call(cmn,loc_to_loc(loc));
			csmc.parameters.AddRange(exprs);
			return csmc;
		}
 private expression_node CreateStaticMethodCall()
 {
 	common_method_node meth = GetMethodByOffset();
     common_static_method_call cmc = new common_static_method_call(meth,null);
     //ssyy
     cmc.last_result_function_call = br.ReadByte() == 1;
     int num = br.ReadInt32();
     for (int i = 0; i < num; i++)
         cmc.parameters.AddElement(CreateExpression());
     return cmc;
 }