private void dot_node_as_type_ident(type_node tn, SyntaxTree.ident id_right, motivation mot) { SymbolInfo si_right = tn.find_in_type(id_right.name, context.CurrentScope); if (si_right == null) { AddError(new MemberIsNotDeclaredInType(id_right, get_location(id_right), tn)); } switch (mot) { case motivation.address_reciving: { return_addressed_value(create_addressed_with_type_expression(tn, id_right, si_right)); return; } case motivation.expression_evaluation: { return_value(create_static_expression(tn, id_right, si_right)); return; } case motivation.semantic_node_reciving: { if (si_right.sym_info.general_node_type == general_node_type.type_node) return_semantic_value(si_right.sym_info as type_node); else return_semantic_value(create_static_expression(tn, id_right, si_right)); return; } } throw new CompilerInternalError("Invalid motivation"); }
private void dot_node_as_namespace_ident(namespace_node nn, SyntaxTree.ident id_right, motivation mot) { SymbolInfo si_right = nn.find(id_right.name); if (si_right == null) { AddError(new MemberIsNotDeclaredInNamespace(id_right, get_location(id_right), nn)); } switch (mot) { case motivation.address_reciving: { return_addressed_value(ident_address_reciving(si_right, id_right)); return; } case motivation.expression_evaluation: { return_value(ident_value_reciving(si_right, id_right)); return; } case motivation.semantic_node_reciving: { return_semantic_value(ident_semantic_reciving(si_right, id_right)); return; } } throw new CompilerInternalError("Unsupported motivation"); }
private void indexer_as_property_indexes(static_property_reference spr, SyntaxTree.expression_list parameters, motivation mot, location loc) { /*if (spr.property.parameters.Count==0) { switch(mot) { case motivation.expression_evaluation: case motivation.semantic_node_reciving: { function_node fn=spr.property.get_function; base_function_call_with_method bfc=convertion_data_and_alghoritms.create_simple_function_call(fn,loc,new expression_node[0]); return_value(bfc); return; } case motivation.address_reciving: { return_addressed_value(spr); return; } } throw new CompilerInternalError("Unsupported motivation"); }*/ if (spr.property.parameters.Count != 0) { if (parameters.expressions.Count != spr.property.parameters.Count) { AddError(loc, "PROPERTY_{0}_REFERENCE_WITH_INVALID_PARAMS_COUNT", spr.property.name); } for (int i = 0; i < parameters.expressions.Count; i++) { expression_node exp = convert_strong(parameters.expressions[i]); exp = convertion_data_and_alghoritms.convert_type(exp, spr.property.parameters[i].type); spr.fact_parametres.AddElement(exp); } } switch (mot) { case motivation.expression_evaluation: case motivation.semantic_node_reciving: { function_node fn = spr.property.get_function; if (fn == null) { AddError(new ThisPropertyCanNotBeReaded(spr.property, loc)); } //expression_node bfc=convertion_data_and_alghoritms.create_simple_function_call(fn,loc,spr.fact_params.ToArray()); base_function_call bfc = create_static_method_call(fn, loc, spr.property.comprehensive_type, false); bfc.parameters.AddRange(spr.fact_parametres); if (spr.property.parameters.Count != 0) { return_value(bfc); return; } indexer_as_expression_index(bfc, parameters, mot, loc); return; } case motivation.address_reciving: { if (spr.property.parameters.Count != 0) { return_addressed_value(spr); return; } function_node fn = spr.property.get_function; if (fn == null) { AddError(new ThisPropertyCanNotBeReaded(spr.property, loc)); } base_function_call bfc = create_static_method_call(fn, loc, spr.property.comprehensive_type, false); bfc.parameters.AddRange(spr.fact_parametres); indexer_as_expression_index(bfc, parameters, mot, loc); return; } } throw new CompilerInternalError("Unsupported motivation"); }
private void indexer_as_property_indexes(non_static_property_reference nspr, SyntaxTree.expression_list parameters, motivation mot, location loc) { if (nspr.property.parameters.Count != 0) { if (parameters.expressions.Count != nspr.property.parameters.Count) { internal_interface ii = nspr.property.comprehensive_type.get_internal_interface(internal_interface_kind.bounded_array_interface); if (ii != null) { //bounded_array_interface dii = (bounded_array_interface)ii; expression_node exp = convert_strong(parameters.expressions[0]); exp = convertion_data_and_alghoritms.convert_type(exp, nspr.property.parameters[0].type); nspr.fact_parametres.AddElement(exp); base_function_call bfc = null; for (int i = 1; i < parameters.expressions.Count; i++) { bfc = create_not_static_method_call(nspr.property.get_function, nspr.expression, exp.location, false); bfc.parameters.AddRange(nspr.fact_parametres); location lloc = get_location(parameters.expressions[i]); ii = bfc.type.get_internal_interface(internal_interface_kind.bounded_array_interface); if (ii == null) { AddError(lloc, "{0}_DIMENSIONAL_ARRAY_CAN_NOT_HAVE_{1}_AND_MORE_INDEXING", i, i+1); } bounded_array_interface bii = (bounded_array_interface)ii; exp = convert_strong(parameters.expressions[i]); exp = convertion_data_and_alghoritms.convert_type(exp, bii.index_type); nspr = new non_static_property_reference(bii.index_property, bfc, lloc); nspr.fact_parametres.AddElement(exp); } } else { AddError(loc, "PROPERTY_{0}_REFERENCE_WITH_INVALID_PARAMS_COUNT", nspr.property.name); } } else { //String 1 based if (parameters.expressions.Count == 1 && nspr.property.comprehensive_type == SystemLibrary.SystemLibrary.string_type && !SemanticRules.NullBasedStrings) { nspr.fact_parametres.AddElement( ConstructDecExpr( convertion_data_and_alghoritms.convert_type( convert_strong(parameters.expressions[0]), nspr.property.parameters[0].type), null)); } else for (int i = 0; i < parameters.expressions.Count; i++) { expression_node exp = convert_strong(parameters.expressions[i]); exp = convertion_data_and_alghoritms.convert_type(exp, nspr.property.parameters[i].type); nspr.fact_parametres.AddElement(exp); } } } switch (mot) { case motivation.expression_evaluation: case motivation.semantic_node_reciving: { function_node fn = nspr.property.get_function; if (fn == null) { AddError(new ThisPropertyCanNotBeReaded(nspr.property, loc)); } base_function_call bfc = create_not_static_method_call(fn, nspr.expression, loc, false); bfc.parameters.AddRange(nspr.fact_parametres); if (nspr.property.parameters.Count != 0) { return_value(bfc); return; } indexer_as_expression_index(bfc, parameters, mot, loc); return; } case motivation.address_reciving: { if (nspr.property.parameters.Count != 0) { return_addressed_value(nspr); return; } function_node fn = nspr.property.get_function; if (fn == null) { AddError(new ThisPropertyCanNotBeReaded(nspr.property, loc)); } base_function_call bfc = create_not_static_method_call(fn, nspr.expression, loc, false); bfc.parameters.AddRange(nspr.fact_parametres); indexer_as_expression_index(bfc, parameters, mot, loc); return; } } throw new CompilerInternalError("Unsupported motivation"); }
//private bool motivation_set=false; public void reset() { _mot = motivation.expression_evaluation; }
private void indexer_as_type_indexes(type_node type, SyntaxTree.expression_list parameters, motivation mot, location loc) { if (type.default_property_node == null) { if (type.semantic_node_type != semantic_node_type.delegated_method) { AddError(loc, "NO_DEFAULT_PROPERTY_TO_TYPE_{0}", type.PrintableName); } else { AddError(loc, "NO_DEFAULT_PROPERTY_TO_FUNCTION_TYPE"); } } if (type.default_property_node.polymorphic_state != SemanticTree.polymorphic_state.ps_static) { AddError(new CanNotReferenceToNonStaticPropertyWithType(type.default_property_node, loc, type)); } static_property_reference spr = new static_property_reference(type.default_property_node, loc); indexer_as_property_indexes(spr, parameters, mot, loc); return; }
public void set_motivation_to_expect_address() { _mot = motivation.address_reciving; }
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."); }
/// <summary> /// синоним reset() /// </summary> public void set_motivation_to_expect_expression_evaluation() { _mot = motivation.expression_evaluation; }
public void set_motivation_to_expect_semantic_node() { _mot=motivation.semantic_node_reciving; }
public void set_motivation_to_expect_address() { _mot=motivation.address_reciving; }
/// <summary> /// синоним reset() /// </summary> public void set_motivation_to_expect_expression_evaluation() { _mot=motivation.expression_evaluation; }
private void dot_node_as_unit_ident(common_unit_node cun, SyntaxTree.ident id_right, motivation mot) { dot_node_as_namespace_ident(cun.namespaces[0], id_right, mot); }
public void set_motivation_to_expect_semantic_node() { _mot = motivation.semantic_node_reciving; }
private void dot_node_as_ident_dot_ident(SyntaxTree.ident id_left, SyntaxTree.ident id_right, motivation mot) { SymbolInfo si_left = context.find(id_left.name); if (si_left == null) { AddError(new UndefinedNameReference(id_left.name, get_location(id_left))); } definition_node dn = context.check_name_node_type(id_left.name, si_left, get_location(id_left), general_node_type.constant_definition, general_node_type.function_node, general_node_type.namespace_node, general_node_type.property_node, general_node_type.type_node, general_node_type.variable_node, general_node_type.unit_node); switch (dn.general_node_type) { case general_node_type.constant_definition: case general_node_type.function_node: case general_node_type.property_node: case general_node_type.variable_node: { expression_node ex_nd = ident_value_reciving(si_left, id_left); dot_node_as_expression_dot_ident(ex_nd, id_right, mot, id_left); return; } case general_node_type.namespace_node: { //throw new CompilerInternalError("Unsupported now."); namespace_node nn = dn as namespace_node; dot_node_as_namespace_ident(nn, id_right, mot); return; } case general_node_type.type_node: { type_node tn = dn as type_node; dot_node_as_type_ident(tn, id_right, mot); return; } case general_node_type.unit_node: { //throw new NotSupportedError(get_location(id_left)); dot_node_as_unit_ident((common_unit_node)dn, id_right, mot); return; } } return; }
private void indexer_as_expression_index(expression_node expr, SyntaxTree.expression_list parameters, motivation mot, location loc) { try_convert_typed_expression_to_function_call(ref expr); // SSM 10.01.16 Tuple t[i] var ent = expr.type as compiled_type_node; if (ent== null) { var eeee = expr.type as compiled_generic_instance_type_node; if (eeee!= null) ent = eeee.original_generic as compiled_type_node; } if (ent != null) { var t = ent.compiled_type; if (t.FullName.StartsWith("System.Tuple")) { expression eee = parameters.expressions[0]; if (parameters.expressions.Count > 1) AddError(get_location(eee), "TUPLE_CAN_HAVE_ONLY_ONE_INDEX"); var cn = convert_strong_to_constant_node(eee); var v = cn as int_const_node; if (v != null) { if (v.constant_value<0 || v.constant_value >= t.GetGenericArguments().Count()) AddError(cn.location, "TUPLE_INDEX_OUT_OF_RANGE_{0}", t.GetGenericArguments().Count()-1); var dn = new dot_node(new semantic_addr_value(expr), new ident("Item" + (v.constant_value + 1).ToString(), eee.source_context),new SourceContext(loc.begin_line_num,loc.begin_column_num,loc.end_line_num,loc.end_column_num)); visit(dn); return; } else AddError(cn.location, "TUPLE_INDEX_MUST_BE_INTEGER_CONSTANT"); } } // end SSM 09.01.16 Tuple t[i] if (expr.type.type_special_kind == SemanticTree.type_special_kind.array_kind) { internal_interface ii = expr.type.get_internal_interface(internal_interface_kind.unsized_array_interface); array_internal_interface aii = (array_internal_interface)ii; int rank = aii.rank; //TODO: Многомерные массивы. expression_node ind_expr = convert_strong(parameters.expressions[0]); ind_expr = additional_indexer_convertion(ind_expr, expr.type); simple_array_indexing sai = new simple_array_indexing(expr, ind_expr, aii.element_type, loc); if (rank == 1) for (int i = 1; i < parameters.expressions.Count; i++) { ii = sai.type.get_internal_interface(internal_interface_kind.unsized_array_interface); location lloc = get_location(parameters.expressions[i]); if (ii == null) { AddError(lloc, "{0}_DIMENSIONAL_ARRAY_CAN_NOT_HAVE_{1}_AND_MORE_INDEXING", i, i+1); } aii = (array_internal_interface)ii; ind_expr = convert_strong(parameters.expressions[i]); ind_expr = additional_indexer_convertion(ind_expr, sai.type); sai = new simple_array_indexing(sai, ind_expr, aii.element_type, lloc); } else { if (rank != parameters.expressions.Count) AddError(get_location(parameters), "{0}_DIMENSIONAL_ARRAY_CAN_NOT_HAVE_{1}_AND_MORE_INDEXING", rank, rank + 1); List<expression_node> lst = new List<expression_node>(); for (int i = 0; i < parameters.expressions.Count; i++) { location lloc = get_location(parameters.expressions[i]); ind_expr = convert_strong(parameters.expressions[i]); ind_expr = additional_indexer_convertion(ind_expr, sai.type); lst.Add(ind_expr); } sai = new simple_array_indexing(expr, lst[0], aii.element_type, get_location(parameters)); sai.expr_indices = lst.ToArray(); } switch (mot) { case motivation.address_reciving: { return_addressed_value(sai); break; } case motivation.expression_evaluation: { return_value(sai); break; } case motivation.semantic_node_reciving: { return_semantic_value(sai); break; } } return; } else if (expr.type.type_special_kind == SemanticTree.type_special_kind.short_string) { if (parameters.expressions.Count != 1) AddError(loc, "INVALID_PARAMETER_COUNT_IN_INDEXER"); expression_node ind_expr = convert_strong(parameters.expressions[0]); ind_expr = additional_indexer_convertion(ind_expr, expr.type); //expression_node en = convertion_data_and_alghoritms.create_simple_function_call(SystemLibrary.SystemLibInitializer.GetCharInShortStringProcedure.sym_info as function_node,loc,ind_expr,new int_const_node((expr.type as short_string_type_node).Length,null)); switch (mot) { case motivation.address_reciving: { simple_array_indexing sai = new simple_array_indexing(expr, ind_expr, SystemLibrary.SystemLibrary.char_type, loc); return_addressed_value(sai); //return_addressed_value(convertion_data_and_alghoritms.create_simple_function_call(SystemLibrary.SystemLibInitializer.SetCharInShortStringProcedure.sym_info as function_node,loc,expr,ind_expr) as common_namespace_function_call); break; } case motivation.expression_evaluation: { return_value(convertion_data_and_alghoritms.create_simple_function_call(SystemLibrary.SystemLibInitializer.GetCharInShortStringProcedure.sym_info as function_node,loc,expr,ind_expr,new int_const_node((expr.type as short_string_type_node).Length,null))); break; } case motivation.semantic_node_reciving: { return_semantic_value(convertion_data_and_alghoritms.create_simple_function_call(SystemLibrary.SystemLibInitializer.GetCharInShortStringProcedure.sym_info as function_node,loc,expr,ind_expr,new int_const_node((expr.type as short_string_type_node).Length,null))); break; } } return; } /*else if (expr.type.type_special_kind == SemanticTree.type_special_kind.array_wrapper) { internal_interface ii = expr.type.get_internal_interface(internal_interface_kind.bounded_array_interface); array_internal_interface aii = (array_internal_interface)ii; //TODO: Многомерные массивы. expression_node ind_expr = convert_strong(parameters.expressions[0]); ind_expr = additional_indexer_convertion(ind_expr, expr.type); simple_array_indexing sai = new simple_array_indexing(expr, ind_expr, aii.element_type, loc); for (int i = 1; i < parameters.expressions.Count; i++) { ii = sai.type.get_internal_interface(internal_interface_kind.bounded_array_interface); location lloc = get_location(parameters.expressions[i]); if (ii == null) { throw new NDimensionalArrayCanNotHaveNPlusOneIndexer(lloc, expr, i); } aii = (array_internal_interface)ii; ind_expr = convert_strong(parameters.expressions[i]); ind_expr = create_simple_function_call(SystemLibrary.SystemLibrary.int_sub, cmc.location, ind_expr, new int_const_node(ii.ordinal_type_interface.ordinal_type_to_int(bai.ordinal_type_interface.lower_value),cmc.location)); ind_expr = additional_indexer_convertion(ind_expr, sai.type); sai = new simple_array_indexing(sai, ind_expr, aii.element_type, lloc); } switch (mot) { case motivation.address_reciving: { return_addressed_value(sai); break; } case motivation.expression_evaluation: { return_value(sai); break; } case motivation.semantic_node_reciving: { return_semantic_value(sai); break; } } return; if (factparams[i].semantic_node_type == semantic_node_type.common_method_call) { common_method_call cmc = (common_method_call)factparams[i]; internal_interface ii = cmc.obj.type.get_internal_interface(internal_interface_kind.bounded_array_interface); if (ii != null) { if (cmc.function_node.name == compiler_string_consts.get_val_pascal_array_name) { bounded_array_interface bai = (bounded_array_interface)ii; class_field cf = bai.int_array; expression_node left = new class_field_reference(cf, cmc.obj, cmc.location); expression_node right = cmc.parameters[0]; //right = convert_type(right, SystemLibrary.SystemLibrary.integer_type); right = convert_type(right, (ii as bounded_array_interface).ordinal_type_interface.elems_type); right = create_simple_function_call(SystemLibrary.SystemLibrary.int_sub, cmc.location, right, new int_const_node(bai.ordinal_type_interface.ordinal_type_to_int(bai.ordinal_type_interface.lower_value),cmc.location)); factparams[i] = new simple_array_indexing(left, right, cmc.type, cmc.location); is_pascal_array_ref = true; } } } }*/ if (expr.type.default_property_node == null) { if (expr.type.semantic_node_type != semantic_node_type.delegated_method) { AddError(loc, "NO_DEFAULT_PROPERTY_TO_TYPE_{0}", expr.type.PrintableName); } else { AddError(loc, "NO_DEFAULT_PROPERTY_TO_FUNCTION_TYPE"); } } if (expr.type.default_property_node.polymorphic_state == SemanticTree.polymorphic_state.ps_static) { AddError(new CanNotReferenceToStaticPropertyWithExpression(expr.type.default_property_node, loc, expr.type)); } non_static_property_reference nspr = new non_static_property_reference(expr.type.default_property_node, expr, loc); indexer_as_property_indexes(nspr, parameters, mot, loc); //eto vrode rabotaet normalno. no imet v vidu if (expr.type.type_special_kind == SemanticTree.type_special_kind.array_wrapper) { expression_node en = ret.get_expression(); if (en is non_static_property_reference) { non_static_property_reference cmc = (non_static_property_reference)en; internal_interface ii = cmc.expression.type.get_internal_interface(internal_interface_kind.bounded_array_interface); if (ii != null) { //if (cmc.function_node.name == compiler_string_consts.get_val_pascal_array_name) { bounded_array_interface bai = (bounded_array_interface)ii; class_field cf = bai.int_array; expression_node left = new class_field_reference(cf, cmc.expression, cmc.location); expression_node right = cmc.fact_parametres[0]; //right = convert_type(right, SystemLibrary.SystemLibrary.integer_type); right = convertion_data_and_alghoritms.convert_type(right, (ii as bounded_array_interface).ordinal_type_interface.elems_type); right = convertion_data_and_alghoritms.create_simple_function_call(SystemLibrary.SystemLibrary.int_sub, cmc.location, right, new int_const_node(bai.ordinal_type_interface.ordinal_type_to_int(bai.ordinal_type_interface.lower_value), cmc.location)); en = new simple_array_indexing(left, right, cmc.type, cmc.location); //is_pascal_array_ref = true; } } } else { common_method_call cmc = (common_method_call)en; internal_interface ii = cmc.obj.type.get_internal_interface(internal_interface_kind.bounded_array_interface); if (ii != null) { //if (cmc.function_node.name == compiler_string_consts.get_val_pascal_array_name) { bounded_array_interface bai = (bounded_array_interface)ii; class_field cf = bai.int_array; expression_node left = new class_field_reference(cf, cmc.obj, cmc.location); expression_node right = cmc.parameters[0]; //right = convert_type(right, SystemLibrary.SystemLibrary.integer_type); right = convertion_data_and_alghoritms.convert_type(right, (ii as bounded_array_interface).ordinal_type_interface.elems_type); right = convertion_data_and_alghoritms.create_simple_function_call(SystemLibrary.SystemLibrary.int_sub, cmc.location, right, new int_const_node(bai.ordinal_type_interface.ordinal_type_to_int(bai.ordinal_type_interface.lower_value), cmc.location)); en = new simple_array_indexing(left, right, cmc.type, cmc.location); //is_pascal_array_ref = true; } } } return_value(en); } return; }
private void dot_node_as_dot_node_dot_ident(SyntaxTree.dot_node left_dot, SyntaxTree.ident id_right, motivation mot) { semantic_node sn = convert_semantic_strong(left_dot); switch (sn.general_node_type) { case general_node_type.expression: { expression_node en = (expression_node)sn; dot_node_as_expression_dot_ident(en, id_right, mot, left_dot); return; } case general_node_type.namespace_node: { //throw new CompilerInternalError("Not supported"); /***************modified********************/ namespace_node nn = (namespace_node)sn; dot_node_as_namespace_ident(nn, id_right, mot); return; /*******************************************/ } case general_node_type.type_node: { type_node tn = (type_node)sn; dot_node_as_type_ident(tn, id_right, mot); return; } case general_node_type.unit_node: { throw new CompilerInternalError("Not supported"); } } throw new CompilerInternalError("Invalid left dot node kind"); }
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."); }