internal typed_expression make_delegate_wrapper(expression_node obj, function_node func, location loc, bool is_static) { base_function_call_list fnl = create_possible_delegates_list(obj, func, loc, is_static); if (fnl.Count == 0) { if (is_static) { AddError(loc, "EXPECTED_STATIC_METHOD"); } else { AddError(loc, "EXPECTED_NON_STATIC_METHOD"); } } delegated_methods dm = new delegated_methods(); dm.proper_methods.AddRange(fnl); typed_expression te = new typed_expression(dm, loc); return te; }
public override void visit(SyntaxTree.ident_with_templateparams _ident_with_templateparams) { SyntaxTree.expression ex = _ident_with_templateparams.name; SyntaxTree.ident id_ex = _ident_with_templateparams.name as SyntaxTree.ident; dot_node dn = _ident_with_templateparams.name as dot_node; int par_count = _ident_with_templateparams.template_params.params_list.Count; if (id_ex != null) { SymbolInfo type_si = context.find(id_ex.name + compiler_string_consts.generic_params_infix + par_count.ToString()); if (type_si != null) { return_value(get_generic_instance(type_si, _ident_with_templateparams.template_params.params_list)); return; } type_si = context.find(id_ex.name); if (type_si != null && type_si.sym_info.general_node_type == general_node_type.template_type) { template_class tc = type_si.sym_info as template_class; List<type_node> tpars = visit_type_list(_ident_with_templateparams.template_params.params_list); return_value(instance_any(tc, tpars, get_location(_ident_with_templateparams))); return; } } else if (dn != null && dn.right is ident) { semantic_node sn = convert_semantic_strong(dn.left); id_ex = dn.right as SyntaxTree.ident; type_node tn = null; namespace_node nn = null; unit_node un = null; switch (sn.general_node_type) { case general_node_type.expression: tn = (sn as expression_node).type; break; case general_node_type.type_node: tn = sn as type_node; break; case general_node_type.namespace_node: nn = sn as namespace_node; break; case general_node_type.unit_node: un = sn as unit_node; break; default: AddError(get_location(dn.left), "EXPECTED_ANOTHER_KIND_OF_OBJECT"); break; } SymbolInfo type_si = null; if (tn != null) type_si = tn.find_in_type(id_ex.name + compiler_string_consts.generic_params_infix + par_count.ToString()); else if (nn != null) type_si = nn.find(id_ex.name + compiler_string_consts.generic_params_infix + par_count.ToString()); else if (un != null) type_si = un.find_only_in_namespace(id_ex.name + compiler_string_consts.generic_params_infix + par_count.ToString()); if (type_si != null) { return_value(get_generic_instance(type_si, _ident_with_templateparams.template_params.params_list)); return; } if (tn != null) type_si = tn.find_in_type(id_ex.name); else if (nn != null) type_si = nn.find(id_ex.name); else if (un != null) type_si = un.find_only_in_namespace(id_ex.name); if (type_si != null && type_si.sym_info.general_node_type == general_node_type.template_type) { template_class tc = type_si.sym_info as template_class; List<type_node> tpars = visit_type_list(_ident_with_templateparams.template_params.params_list); return_value(instance_any(tc, tpars, get_location(_ident_with_templateparams))); return; } } expression_node adr = ret.visit(ex); typed_expression te = adr as typed_expression; if (te != null) { delegated_methods dm = te.type as delegated_methods; if (dm != null) { List<type_node> ptypes = visit_type_list(_ident_with_templateparams.template_params.params_list); base_function_call_list bfcl = new base_function_call_list(); common_method_node cnode; compiled_function_node comp_node; function_node fnode; int generic_count = 0; foreach (base_function_call bfc in dm.proper_methods) { if (bfc.simple_function_node.is_generic_function) { generic_count++; } } bool one_function = false; switch (generic_count) { case 0: AddError(get_location(_ident_with_templateparams), "TRIANGLE_BRACKETS_NOT_ALLOWED_WITH_COMMON_FUNCTIONS"); break; case 1: one_function = true; break; default: one_function = false; break; } foreach (base_function_call bfc in dm.proper_methods) { if (!bfc.simple_function_node.is_generic_function) { continue; } switch (bfc.semantic_node_type) { case semantic_node_type.common_namespace_function_call: common_namespace_function_node cnfn = bfc.simple_function_node.get_instance(ptypes, one_function, get_location(_ident_with_templateparams)) as common_namespace_function_node; if (cnfn != null) { bfcl.AddElement(new common_namespace_function_call(cnfn, bfc.location)); } break; case semantic_node_type.common_method_call: cnode = bfc.simple_function_node.get_instance(ptypes, one_function, get_location(_ident_with_templateparams)) as common_method_node; if (cnode != null) { bfcl.AddElement(new common_method_call(cnode, (bfc as common_method_call).obj, bfc.location)); } break; case semantic_node_type.compiled_function_call: fnode = bfc.simple_function_node.get_instance(ptypes, one_function, get_location(_ident_with_templateparams)); cnode = fnode as common_method_node; if (cnode != null) { bfcl.AddElement(new common_method_call(cnode, (bfc as compiled_function_call).obj, bfc.location)); } else { comp_node = fnode as compiled_function_node; if (comp_node != null) { bfcl.AddElement(new compiled_function_call(comp_node, (bfc as compiled_function_call).obj, bfc.location)); } } break; case semantic_node_type.common_static_method_call: case semantic_node_type.compiled_static_method_call: fnode = bfc.simple_function_node.get_instance(ptypes, one_function, get_location(_ident_with_templateparams)); cnode = fnode as common_method_node; if (cnode != null) { bfcl.AddElement(new common_static_method_call(cnode, bfc.location)); } else { comp_node = fnode as compiled_function_node; if (comp_node != null) { bfcl.AddElement(new compiled_static_method_call(comp_node, bfc.location)); } } break; } } if (bfcl.Count == 0) { AddError(get_location(_ident_with_templateparams.template_params), "NO_FUNCTIONS_{0}_CAN_BE_USED_WITH_THIS_SPECIFICATION", dm.proper_methods[0].function.name); } delegated_methods dm1 = new delegated_methods(); dm1.proper_methods.AddRange(bfcl); typed_expression te1 = new typed_expression(dm1, te.location); return_value(te1); return; } } AddError(get_location(_ident_with_templateparams.name), "TRIANGLE_BRACKETS_NOT_AWAITED"); }
/// <summary> /// Временный узел, который используется при выведении типов параметров /// </summary> /// <param name="def"></param> /// <param name="visitor"></param> /// <returns></returns> public static typed_expression GetTempFunctionNodeForTypeInference(SyntaxTree.function_lambda_definition def, syntax_tree_visitor visitor) { var res = new common_namespace_function_node(def.lambda_name, null, null, null); if (def.return_type != null) res.return_value_type = visitor.convert_strong(def.return_type); else res.return_value_type = null; res.parameters.clear(); if (def.formal_parameters != null && def.formal_parameters.params_list.Count != 0) { for (int i = 0; i < def.formal_parameters.params_list.Count; i++) for (int j = 0; j < def.formal_parameters.params_list[i].idents.idents.Count; j++) { var new_param = new common_parameter(null, SemanticTree.parameter_type.value, res, concrete_parameter_type.cpt_none, null); new_param.type = visitor.convert_strong(def.formal_parameters.params_list[i].vars_type); res.parameters.AddElement(new_param); } } var hhh = new delegated_methods(); hhh.proper_methods.AddElement(new common_namespace_function_call(res, null)); return new typed_expression(hhh, null); }