private void WriteGenericNamespaceFunctionReference(generic_namespace_function_instance_node func)
 {
     bw.Write((byte)PCUConsts.common_namespace_generic);
     WriteFunctionReference(func.original_function as common_namespace_function_node);
     WriteTypeList(func.instance_params);
 }
예제 #2
0
        public static function_node get_function_instance(function_node orig, List<type_node> param_types)
        {
            List<generic_function_instance_info> _generic_instances = get_function_instances(orig);
            function_node founded_inst = find_function_instance(_generic_instances, param_types);
            if (founded_inst != null) return founded_inst;
            for (int i=0; i<param_types.Count; i++)
            {
                if (param_types[i] is delegated_methods)
                {
                    base_function_call bfc = (param_types[i] as delegated_methods).proper_methods[0];
                    var context = SystemLibrary.SystemLibrary.syn_visitor.context;
                    common_type_node del =
                        type_constructor.instance.create_delegate(context.get_delegate_type_name(), bfc.simple_function_node.return_value_type, bfc.simple_function_node.parameters, context.converted_namespace, null);
                    context.converted_namespace.types.AddElement(del);
                    param_types[i] = del;
                }
            }
            //Создаём новую псевдо-инстанцию
            common_function_node new_func = null;
            SemanticTree.IGenericFunctionInstance new_inst = null;
            if (orig.semantic_node_type == semantic_node_type.common_namespace_function_node)
            {
                generic_namespace_function_instance_node nnode = new generic_namespace_function_instance_node(orig as common_namespace_function_node, param_types);
                nnode.ConnectedToType = (orig as common_namespace_function_node).ConnectedToType;
                new_func = nnode;
                new_inst = nnode;
            }
            else
            {
                generic_method_instance_node ctnode = new generic_method_instance_node(orig, param_types);
                new_func = ctnode;
                new_inst = ctnode;
            }
            common_function_node common_orig = orig as common_function_node;
            if (common_orig != null)
            {
                new_func.num_of_default_variables = common_orig.num_of_default_variables;
            }

            var shouldAddToAllTypeInstances = true;
            if (LambdaHelper.processingLambdaParametersForTypeInference != 0)
            {
                foreach (var par in param_types)
                {
                    if (par is lambda_any_type_node)
                    {
                        shouldAddToAllTypeInstances = false;
                        break;
                    }
                }
            }

            if (shouldAddToAllTypeInstances) //lroman// Если зашли сюда при выведении типов параметров лямбды, то функция инстанцироваться может с типом lambda_any_type_node. Поэтому, если выводим типы. То данную инстанцию не добавляем 
            {
                _generic_instances.Add(new generic_function_instance_info(param_types, new_func));
                all_function_instances.Add(new_inst);
            }
            return new_func;
        }