private void dot_node_as_expression_dot_template_ident(expression_node en, SyntaxTree.ident_with_templateparams template_id_right, motivation mot, addressed_value syntax_node) { SyntaxTree.ident id_right = template_id_right.name as ident; if (en is typed_expression) try_convert_typed_expression_to_function_call(ref en); SymbolInfo si = en.type.find_in_type(id_right.name, context.CurrentScope); if (si == null) { AddError(new MemberIsNotDeclaredInType(id_right, get_location(id_right), en.type)); } try_convert_typed_expression_to_function_call(ref en); switch (mot) { case motivation.address_reciving: { return_addressed_value(address_expression_reciving(id_right, si, en)); return; } case motivation.expression_evaluation: { //en = expression_value_reciving(id_right, si, en, true); //try_convert_typed_expression_to_function_call(ref en); //return_value(en); if (si.sym_info is function_node && (si.sym_info as function_node).is_extension_method && !has_property(ref si) || si.sym_info is common_method_node && (si.sym_info as common_method_node).is_constructor || si.sym_info is compiled_constructor_node) { //dot_node dnode = new dot_node(syntax_node, template_id_right); template_id_right.name = new dot_node(syntax_node, id_right); method_call mc = new method_call(template_id_right, new expression_list()); mc.visit(this); return; } return_value(expression_value_reciving(id_right, si, en, true)); return; } case motivation.semantic_node_reciving: { if (si.sym_info is function_node && (si.sym_info as function_node).is_extension_method) has_property(ref si); return_semantic_value(expression_value_reciving(id_right, si, en, true)); return; } } throw new CompilerInternalError("Invalid motivation."); }
private void dot_node_as_expression_dot_ident(expression_node en, SyntaxTree.ident id_right, motivation mot, addressed_value syntax_node) { if (en is typed_expression) try_convert_typed_expression_to_function_call(ref en); SymbolInfo si = en.type.find_in_type(id_right.name, context.CurrentScope); if (si == null) { AddError(new MemberIsNotDeclaredInType(id_right, get_location(id_right), en.type)); } try_convert_typed_expression_to_function_call(ref en); /* if (en.semantic_node_type == semantic_node_type.typed_expression) { type_node tn11=en.type; delegated_methods dm11=tn11 as delegated_methods; if (dm11!=null) { en = dm11.empty_param_method; } } */ switch (mot) { case motivation.address_reciving: { return_addressed_value(address_expression_reciving(id_right, si, en)); return; } case motivation.expression_evaluation: { //en = expression_value_reciving(id_right, si, en, true); //try_convert_typed_expression_to_function_call(ref en); //return_value(en); if (si.sym_info is function_node && (si.sym_info as function_node).is_extension_method) { dot_node dnode = new dot_node(syntax_node, id_right); method_call mc = new method_call(dnode, new expression_list()); mc.visit(this); return; } return_value(expression_value_reciving(id_right, si, en, true)); return; } case motivation.semantic_node_reciving: { return_semantic_value(expression_value_reciving(id_right, si, en, true)); return; } } throw new CompilerInternalError("Invalid motivation."); }
public override void visit(dot_node _dot_node) { bool tmp = by_dot; by_dot = true; bool tmp2 = search_all; search_all = false; _dot_node.left.visit(this); search_all = tmp2; by_dot = tmp; if (returned_scope != null && returned_scope is ElementScope && (returned_scope as ElementScope).sc is ProcScope) { if (((returned_scope as ElementScope).sc as ProcScope).return_type != null) returned_scope = new ElementScope(((returned_scope as ElementScope).sc as ProcScope).return_type); else returned_scope = null; } else if (returned_scope != null && returned_scope is ProcScope) { ProcScope ps = returned_scope as ProcScope; if (ps.return_type == null) { if (ps.is_constructor) returned_scope = new ElementScope(ps.declaringType); else returned_scope = null; } else returned_scope = new ElementScope((returned_scope as ProcScope).return_type); } else if (returned_scope != null && returned_scope is ElementScope && (returned_scope as ElementScope).sc is ProcType) { TypeScope ts = ((returned_scope as ElementScope).sc as ProcType).target.return_type; if (ts != null) returned_scope = new ElementScope(ts); } if (returned_scope != null) { if (!search_all) { SymScope left_scope = returned_scope; if (_dot_node.right is ident) { SymScope tmp_tn = returned_scope; returned_scope = returned_scope.FindNameOnlyInType((_dot_node.right as ident).name); if (returned_scope != null && returned_scope is ElementScope) { if (left_scope is ElementScope) returned_scope = CheckForAccess(left_scope as ElementScope, returned_scope as ElementScope); else if (left_scope is TypeScope) returned_scope = CheckForAccess(left_scope as TypeScope, returned_scope as ElementScope); return; } if (returned_scope != null && returned_scope is ProcScope) { if ((returned_scope as ProcScope).return_type == null) { method_call mc = new method_call(_dot_node, new expression_list()); mc.visit(this); return; } if ((returned_scope as ProcScope).return_type != null) { CompiledMethodScope tmp_sc = returned_scope as CompiledMethodScope; returned_scope = new ElementScope(returned_scope as ProcScope); if (tmp_sc != null) returned_scope.topScope = tmp_sc.topScope; if (left_scope is ElementScope) returned_scope = CheckForAccess(left_scope as ElementScope, returned_scope as ElementScope); else if (left_scope is TypeScope) returned_scope = CheckForAccess(left_scope as TypeScope, returned_scope as ElementScope); return; } } if (tmp_tn is ElementScope && stv != null) { List<ProcScope> procs = stv.entry_scope.GetExtensionMethods((_dot_node.right as ident).name, (tmp_tn as ElementScope).sc as TypeScope); if (procs.Count > 0) { foreach (ProcScope ps in procs) { if (ps.parameters.Count == 0 || ps.parameters.Count == 1 && ps.is_extension && string.Compare(ps.parameters[0].Name,"self", true) == 0) { returned_scope = ps; return; } } returned_scope = procs[0]; return; } } } } else { SymScope left_scope = returned_scope; returned_scopes = returned_scope.FindOverloadNamesOnlyInType((_dot_node.right as ident).name); List<int> to_remove = new List<int>(); for (int i = 0; i < returned_scopes.Count; i++) { if (returned_scopes[i] is ElementScope && (returned_scopes[i] as ElementScope).sc is ProcType) { if (left_scope is ElementScope) returned_scopes[i] = CheckForAccess(left_scope as ElementScope, returned_scopes[i] as ElementScope); //if (ret_names[i] != null) //ret_names[i] = ((ret_names[i] as ElementScope).sc as ProcType).target; } else if (left_scope is ElementScope && returned_scopes[i] is ProcScope && (returned_scopes[i] as ProcScope).IsStatic) { returned_scopes[i] = null; } } returned_scopes.RemoveAll(x => x == null); if (returned_scope is ElementScope && stv != null) { List<ProcScope> procs = stv.entry_scope.GetExtensionMethods((_dot_node.right as ident).name,(returned_scope as ElementScope).sc as TypeScope); for (int i = 0; i < procs.Count; i++) returned_scopes.Add(procs[i]); } search_all = false; } } }