Exemplo n.º 1
0
 private void VisitNonStaticPropertyReference(non_static_property_reference en)
 {
     VisitExpression(en.expression);
     for (int i = 0; i < en.fact_parametres.Count; i++)
         VisitExpression(en.fact_parametres[i]);
 }
 private addressed_expression address_expression_reciving(SyntaxTree.ident id_right, SymbolInfo si,
     expression_node en)
 {
     if (si != null && si.sym_info != null &&
         si.sym_info.semantic_node_type == semantic_node_type.indefinite_definition_node)
     {
         return new indefinite_reference(si.sym_info as indefinite_definition_node, get_location(id_right));
     }
 	definition_node dn = null;
 	if (!internal_is_assign)
         dn = context.check_name_node_type(id_right.name, si, get_location(id_right),
         general_node_type.variable_node, general_node_type.property_node, general_node_type.event_node);
     else
         dn = context.check_name_node_type(id_right.name, si, get_location(id_right),
         general_node_type.variable_node, general_node_type.property_node, general_node_type.event_node, general_node_type.constant_definition);
     if (dn.general_node_type == general_node_type.constant_definition)
     {
         AddError(get_location(id_right), "CAN_NOT_ASSIGN_TO_CONSTANT_OBJECT");
     }
     switch (dn.general_node_type)
     {
         case general_node_type.variable_node:
             {
                 return create_class_field_reference(en, dn, id_right);
             }
         case general_node_type.property_node:
             {
                 property_node pn = (property_node)dn;
                 if (pn.polymorphic_state == SemanticTree.polymorphic_state.ps_static)
                 {
                     AddError(new CanNotReferenceToStaticPropertyWithExpression(pn, get_location(id_right), pn.comprehensive_type));
                 }
                 try_convert_typed_expression_to_function_call(ref en);
                 non_static_property_reference pr = new non_static_property_reference(pn, en, get_location(id_right));
                 return pr;
             }
         case general_node_type.event_node:
             {
                 if (dn.semantic_node_type == semantic_node_type.compiled_event)
                 {
                     compiled_event ce = (compiled_event)dn;
                     if (ce.is_static)
                     {
                         //throw new NonStaticAndStaticEvevnt();
                     }
                     nonstatic_event_reference ser = new nonstatic_event_reference(en, ce, get_location(id_right));
                     return ser;
                 }
                 else if (dn.semantic_node_type == semantic_node_type.common_event)
                 {
                     common_event ce = (common_event)dn;
                     if (ce.is_static)
                     {
                         //throw new NonStaticAndStaticEvevnt();
                     }
                     nonstatic_event_reference ser = new nonstatic_event_reference(en, ce, get_location(id_right));
                     return ser;
                 }
                 break;
             }
     	default : return null;
     }
     throw new CompilerInternalError("Undefined expression to address reciving");
 }
 private void VisitNonStaticPropertyReference(non_static_property_reference expr)
 {
     VisitExpression(expr.expression);
     WritePropertyReference((common_property_node)expr.property);
     bw.Write(expr.fact_parametres.Count);
     for (int i = 0; i < expr.fact_parametres.Count; i++)
         VisitExpression(expr.fact_parametres[i]);
 }
 private addressed_expression ident_address_reciving(SymbolInfo si, SyntaxTree.ident _ident)
 {
     location lloc = get_location(_ident);
     definition_node dn = null;
     if (!internal_is_assign)
         dn = context.check_name_node_type(_ident.name, si, lloc,
         general_node_type.variable_node, general_node_type.property_node, general_node_type.event_node);
     else
         dn = context.check_name_node_type(_ident.name, si, lloc,
         general_node_type.variable_node, general_node_type.property_node, general_node_type.event_node, general_node_type.constant_definition);
     if (dn.general_node_type == general_node_type.constant_definition)
         AddError(get_location(_ident), "CAN_NOT_ASSIGN_TO_CONSTANT_OBJECT");
     switch (dn.general_node_type)
     {
         case general_node_type.variable_node:
             {
                 local_variable lv = dn as local_variable;
                 if (lv != null && (lv.function is common_method_node))
                 {
                     //self variable
                     if ((lv.function as common_method_node).self_variable == lv)
                         AddError(lloc, "VARIABLE_{0}_READONLY", lv.name);
                 }
                 return create_variable_reference(dn, lloc);
             }
         case general_node_type.property_node:
             {
                 property_node pn = (property_node)dn;
                 if (pn.polymorphic_state == SemanticTree.polymorphic_state.ps_static)
                 {
                     static_property_reference spr = new static_property_reference(pn, lloc);
                     return spr;
                 }
                 //this_node thisnode=new this_node(context.converted_type,lloc);
                 if (pn.comprehensive_type.Scope == null && pn is compiled_property_node)
                 	(pn.comprehensive_type as compiled_type_node).init_scope();
                 non_static_property_reference nspr = new non_static_property_reference(pn, GetCurrentObjectReference(pn.comprehensive_type.Scope, pn, lloc), lloc);
                 return nspr;
             }
         case general_node_type.event_node:
             {
                 if (dn.semantic_node_type == semantic_node_type.compiled_event)
                 {
                     compiled_event ce = (compiled_event)dn;
                     if (ce.is_static)
                     {
                         static_event_reference ser = new static_event_reference(ce, get_location(_ident));
                         return ser;
                     }
                     nonstatic_event_reference nser = new nonstatic_event_reference(
                         GetCurrentObjectReference(ce.comprehensive_type.Scope, ce, lloc), ce, lloc);
                     return nser;
                 }
                 else if (dn.semantic_node_type == semantic_node_type.common_event)
                 {
                 	common_event ce = (common_event)dn;
                 	if (ce.is_static)
                     {
                         static_event_reference ser = new static_event_reference(ce, get_location(_ident));
                         return ser;
                     }
                     nonstatic_event_reference nser = new nonstatic_event_reference(
                         GetCurrentObjectReference(ce.comprehensive_type.Scope, ce, lloc), ce, lloc);
                     return nser;
                 }
                 else if (dn.semantic_node_type == semantic_node_type.common_namespace_event)
                 {
                     common_namespace_event cne = (common_namespace_event)dn;
                     static_event_reference ser = new static_event_reference(cne, get_location(_ident));
                     return ser;
                 }
                 break;
             }
     }
     return null;
 }
 private void check_property_params(non_static_property_reference pr, location loc)
 {
     if (pr.property.parameters.Count != pr.fact_parametres.Count)
     {
         AddError(loc, "PROPERTY_{0}_REFERENCE_WITH_INVALID_PARAMS_COUNT", pr.property.name);
     }
 }
        public override void visit(SyntaxTree.indexer _indexer)
        {
            //SSM 11/02/16 - нет, это глупость
            /*if (_indexer.dereferencing_value is SyntaxTree.question_colon_expression) // то разбросать индекс по компонентам
            {
                var q = _indexer.dereferencing_value as SyntaxTree.question_colon_expression;
                var nodeToVisit = new SyntaxTree.question_colon_expression(q.condition, new indexer(q.ret_if_true as addressed_value, _indexer.indexes, _indexer.source_context),
                    new indexer(q.ret_if_false as addressed_value, _indexer.indexes, _indexer.source_context), _indexer.source_context);
                visit(nodeToVisit);
                return;
            }*/
            //end SSM 11/02/16

            //lroman
            if (_indexer.dereferencing_value is closure_substituting_node)
            {
                var nodeToVisit = new indexer(((closure_substituting_node) _indexer.dereferencing_value).substitution,
                                              _indexer.indexes);
                visit(nodeToVisit);
                return;
            }

            motivation mot = motivation_keeper.motivation;
            SyntaxTree.ident idi = _indexer.dereferencing_value as SyntaxTree.ident;
            if (idi != null)
            {
                SymbolInfo si = context.find(idi.name);
                if (si == null)
                {
                    AddError(new UndefinedNameReference(idi.name, get_location(idi)));
                }
                if (si.sym_info.general_node_type == general_node_type.type_node)
                {
                    indexer_as_type_indexes((type_node)si.sym_info, _indexer.indexes, mot, get_location(idi));
                    return;
                }
                if (si.sym_info.general_node_type == general_node_type.property_node)
                {
                    property_node pn = (property_node)si.sym_info;
                    if (pn.polymorphic_state == SemanticTree.polymorphic_state.ps_static)
                    {
                        static_property_reference spr = new static_property_reference(pn, get_location(idi));
                        indexer_as_property_indexes(spr, _indexer.indexes, mot, get_location(idi));
                        return;
                    }
                    else
                    {
                        this_node thisnode = new this_node(pn.comprehensive_type, get_location(_indexer));
                        location loc111 = get_location(idi);
                        non_static_property_reference nspr = new non_static_property_reference(pn, thisnode, loc111);
                        indexer_as_property_indexes(nspr, _indexer.indexes, mot, loc111);
                        return;
                    }
                }
                expression_node en = ident_value_reciving(si, idi);
              
                indexer_as_expression_index(en, _indexer.indexes, mot, get_location(idi));
                return;
            }
            else
            {
                SyntaxTree.dot_node dotnd = _indexer.dereferencing_value as SyntaxTree.dot_node;
                if (dotnd != null)
                {
                    SyntaxTree.ident id = dotnd.right as SyntaxTree.ident;
                    semantic_node sn = convert_semantic_strong(dotnd.left);
                    switch (sn.general_node_type)
                    {
                        case general_node_type.type_node:
                            {
                                type_node ttp = (type_node)sn;
                                SymbolInfo si = ttp.find_in_type(id.name, context.CurrentScope);
                                if (si == null)
                                {
                                    AddError(new UndefinedNameReference(id.name, get_location(id)));
                                }
                                if (si.sym_info.general_node_type == general_node_type.property_node)
                                {
                                    property_node pn = (property_node)si.sym_info;
                                    static_property_reference spr = new static_property_reference(pn, get_location(id));
                                    indexer_as_property_indexes(spr, _indexer.indexes, mot, get_location(dotnd));
                                    return;
                                }
                                expression_node exp1 = create_static_expression(ttp, id, si);
                                indexer_as_expression_index(exp1, _indexer.indexes, mot, get_location(id));
                                return;
                            }
                        case general_node_type.namespace_node:
                        case general_node_type.unit_node:
                            {
                                SymbolInfo si = null;
                                if (sn is namespace_node)
                                    si = ((namespace_node)sn).find(id.name);
                                else
                                    si = ((unit_node)sn).find_only_in_namespace(id.name);
                                if (si == null)
                                {
                                    AddError(new UndefinedNameReference(id.name, get_location(id)));
                                }
                                location lloc = get_location(id);
                                if (si.sym_info.general_node_type == general_node_type.type_node)
                                {
                                    type_node tn = (type_node)si.sym_info;
                                    indexer_as_type_indexes(tn, _indexer.indexes, mot, lloc);
                                    return;
                                }
                                expression_node exp2 = ident_value_reciving(si, id);
                                indexer_as_expression_index(exp2, _indexer.indexes, mot, get_location(id));
                                return;
                            }
                        case general_node_type.expression:
                            {
                                expression_node ex = (expression_node)sn;
                                SymbolInfo si = ex.type.find_in_type(id.name, context.CurrentScope);
                                if (si == null)
                                {
                                    AddError(new UndefinedNameReference(id.name, get_location(id)));
                                }
                                if (si.sym_info.general_node_type == general_node_type.property_node)
                                {
                                    property_node pn = (property_node)si.sym_info;
                                    if (pn.polymorphic_state == SemanticTree.polymorphic_state.ps_static)
                                    {
                                        AddError(new CanNotReferenceToStaticPropertyWithExpression(pn, get_location(dotnd), ex.type));
                                    }
                                    location lloc11 = get_location(dotnd);
                                    try_convert_typed_expression_to_function_call(ref ex);
                                    non_static_property_reference nspr = new non_static_property_reference(pn, ex, lloc11);
                                    indexer_as_property_indexes(nspr, _indexer.indexes, mot, lloc11);
                                    return;
                                }
                                expression_node en2 = expression_value_reciving(id, si, ex, false);
                                indexer_as_expression_index(en2, _indexer.indexes, mot, get_location(id));
                                return;
                            }
                    }
                }
                else
                {
                    expression_node expr = convert_strong(_indexer.dereferencing_value);
                    indexer_as_expression_index(expr, _indexer.indexes, mot, get_location(_indexer.dereferencing_value));
                    return;
                }
            }
            /*expression_node left=convert_strong(_indexer.dereferencing_value);
            foreach(SyntaxTree.expression exp in _indexer.indexes.expressions)
            {
                expression_node right=convert_strong(exp);
                SymbolInfo si=left.type.find_in_type(compiler_string_consts.indexer_name);
                definition_node dn=check_name_node_type(compiler_string_consts.indexer_name,si,get_location(exp),
                    general_node_type.function_node);
                expression_nodeArrayList exprs=new expression_nodeArrayList();
                exprs.Add(right);
                function_node fn=convertion_data_and_alghoritms.select_function(exprs,si,get_location(exp));
                base_function_call_with_method bfc=create_not_static_method_call(fn,left,get_location(exp),false);
                bfc.parameters.AddRange(exprs);
                left=bfc;
            }*/
            /*switch (mot)
            {
                case motivation.address_reciving:
                {
                    return_addressed_value(left);
                    return;
                }
                case motivation.expression_evaluation:
                {
                    return_value(left);
                    return;
                }
                case motivation.semantic_node_reciving:
                {
                    return_semantic_value(left);
                    return;
                }		
            }*/
        }
        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 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 expression_node CreateNonStaticPropertyReference()
 {
     expression_node obj = CreateExpression();
     property_node prop = GetPropertyByOffset();
     non_static_property_reference nspr = new non_static_property_reference(prop,obj,null);
     int num = br.ReadInt32();
     for (int i = 0; i < num; i++)
         nspr.fact_parametres.AddElement(CreateExpression());
     return nspr;
 }
Exemplo n.º 10
0
        public override void visit(SyntaxTree.indexer _indexer)
        {
            //SSM 11/02/16 - нет, это глупость
            /*if (_indexer.dereferencing_value is SyntaxTree.question_colon_expression) // то разбросать индекс по компонентам
            {
                var q = _indexer.dereferencing_value as SyntaxTree.question_colon_expression;
                var nodeToVisit = new SyntaxTree.question_colon_expression(q.condition, new indexer(q.ret_if_true as addressed_value, _indexer.indexes, _indexer.source_context),
                    new indexer(q.ret_if_false as addressed_value, _indexer.indexes, _indexer.source_context), _indexer.source_context);
                visit(nodeToVisit);
                return;
            }*/
            //end SSM 11/02/16

            // SSM 18.08.16 - пробуем обработать захват enn[i] в yieldах где enn - поле класса и нуждается в переименовании
            // Так же ниже делает lroman
            if (_indexer.dereferencing_value is yield_unknown_ident)
            {
                var yui = (yield_unknown_ident)_indexer.dereferencing_value;
                var av = ProcessUnknownIdent(yui);
                var nodeToVisit = new indexer(av,_indexer.indexes);
                visit(nodeToVisit);
                return;
            }

            //lroman
            if (_indexer.dereferencing_value is closure_substituting_node)
            {
                var nodeToVisit = new indexer(((closure_substituting_node) _indexer.dereferencing_value).substitution,
                                              _indexer.indexes);
                visit(nodeToVisit);
                return;
            }

            var mot = motivation_keeper.motivation;
            motivation_keeper.reset();
            SyntaxTree.ident idi = _indexer.dereferencing_value as SyntaxTree.ident;
            if (idi != null)
            {
                SymbolInfo si = context.find(idi.name);
                if (si == null)
                {
                    AddError(new UndefinedNameReference(idi.name, get_location(idi)));
                }
                if (si.sym_info.general_node_type == general_node_type.type_node)
                {
                    indexer_as_type_indexes((type_node)si.sym_info, _indexer.indexes, mot, get_location(idi));
                    return;
                }
                if (si.sym_info.general_node_type == general_node_type.property_node)
                {
                    property_node pn = (property_node)si.sym_info;
                    if (pn.polymorphic_state == SemanticTree.polymorphic_state.ps_static)
                    {
                        static_property_reference spr = new static_property_reference(pn, get_location(idi));
                        indexer_as_property_indexes(spr, _indexer.indexes, mot, get_location(idi));
                        return;
                    }
                    else
                    {
                        this_node thisnode = new this_node(pn.comprehensive_type, get_location(_indexer));
                        location loc111 = get_location(idi);
                        non_static_property_reference nspr = new non_static_property_reference(pn, thisnode, loc111);
                        indexer_as_property_indexes(nspr, _indexer.indexes, mot, loc111);
                        return;
                    }
                }
                expression_node en = ident_value_reciving(si, idi);
              
                indexer_as_expression_index(en, _indexer.indexes, mot, get_location(idi));
                return;
            }
            else
            {
                SyntaxTree.dot_node dotnd = _indexer.dereferencing_value as SyntaxTree.dot_node;
                if (dotnd != null)
                {
                    SyntaxTree.ident id = dotnd.right as SyntaxTree.ident;
                    semantic_node sn = convert_semantic_strong(dotnd.left);
                    switch (sn.general_node_type)
                    {
                        case general_node_type.type_node:
                            {
                                type_node ttp = (type_node)sn;
                                SymbolInfo si = ttp.find_in_type(id.name, context.CurrentScope);
                                if (si == null)
                                {
                                    AddError(new UndefinedNameReference(id.name, get_location(id)));
                                }
                                if (si.sym_info.general_node_type == general_node_type.property_node)
                                {
                                    property_node pn = (property_node)si.sym_info;
                                    static_property_reference spr = new static_property_reference(pn, get_location(id));
                                    indexer_as_property_indexes(spr, _indexer.indexes, mot, get_location(dotnd));
                                    return;
                                }
                                expression_node exp1 = create_static_expression(ttp, id, si);
                                indexer_as_expression_index(exp1, _indexer.indexes, mot, get_location(id));
                                return;
                            }
                        case general_node_type.namespace_node:
                        case general_node_type.unit_node:
                            {
                                SymbolInfo si = null;
                                if (sn is namespace_node)
                                    si = ((namespace_node)sn).find(id.name);
                                else
                                    si = ((unit_node)sn).find_only_in_namespace(id.name);
                                if (si == null)
                                {
                                    AddError(new UndefinedNameReference(id.name, get_location(id)));
                                }
                                location lloc = get_location(id);
                                if (si.sym_info.general_node_type == general_node_type.type_node)
                                {
                                    type_node tn = (type_node)si.sym_info;
                                    indexer_as_type_indexes(tn, _indexer.indexes, mot, lloc);
                                    return;
                                }
                                expression_node exp2 = ident_value_reciving(si, id);
                                indexer_as_expression_index(exp2, _indexer.indexes, mot, get_location(id));
                                return;
                            }
                        case general_node_type.expression:
                            {
                                expression_node ex = (expression_node)sn;
                                SymbolInfo si = ex.type.find_in_type(id.name, context.CurrentScope);
                                if (si == null)
                                {
                                    AddError(new UndefinedNameReference(id.name, get_location(id)));
                                }
                                if (si.sym_info.general_node_type == general_node_type.property_node)
                                {
                                    property_node pn = (property_node)si.sym_info;
                                    if (pn.polymorphic_state == SemanticTree.polymorphic_state.ps_static)
                                    {
                                        AddError(new CanNotReferenceToStaticPropertyWithExpression(pn, get_location(dotnd), ex.type));
                                    }
                                    location lloc11 = get_location(dotnd);
                                    try_convert_typed_expression_to_function_call(ref ex);
                                    non_static_property_reference nspr = new non_static_property_reference(pn, ex, lloc11);
                                    indexer_as_property_indexes(nspr, _indexer.indexes, mot, lloc11);
                                    return;
                                }
                                expression_node en2 = expression_value_reciving(id, si, ex, false);
                                indexer_as_expression_index(en2, _indexer.indexes, mot, get_location(id));
                                return;
                            }
                    }
                }
                else
                {
                    expression_node expr = convert_strong(_indexer.dereferencing_value);
                    indexer_as_expression_index(expr, _indexer.indexes, mot, get_location(_indexer.dereferencing_value));
                    return;
                }
            }
        }