public void for_assignment(object lr0, object lr2)
 {
     if (lr0 is ident && lr2 is ident && ((ident)lr2).name.Contains("__lambda__"))
     {
         string            type_name = "";
         var_def_statement vds       = find_var_statements(((ident)lr0).name);
         if (vds != null)
         {
             type_name = ((named_type_reference)vds.vars_type).names[0].name;
         }
         if (type_name != "")
         {
             int ii = 0;
             while (ii < pascalABC_type_declarations.Count &&
                    ((type_declaration)pascalABC_type_declarations[ii]).type_name.name != type_name)
             {
                 ii++;
             }
             if (ii < pascalABC_type_declarations.Count)
             {
                 type_definition            td  = ((type_declaration)pascalABC_type_declarations[ii]).type_def;
                 function_lambda_definition fld = find_pascalABC_lambda_name(((ident)lr2).name);
                 fld.return_type = ((function_header)td).return_type;
                 for (int k = 0; k < fld.formal_parameters.params_list.Count && k < ((function_header)td).parameters.params_list.Count; k++)
                 {
                     fld.formal_parameters.params_list[k].vars_type = ((function_header)td).parameters.params_list[k].vars_type;
                 }
             }
             pascalABC_var_statements.Remove(vds);
         }
     }
 }
            public for_node NewForStmt(bool opt_var, ident identifier, type_definition for_stmt_decl_or_assign,
                                       expression expr1, for_cycle_type fc_type, expression expr2, token_info opt_tk_do, statement stmt,
                                       LexLocation loc)
            {
                var nfs = new for_node(identifier, expr1, expr2, stmt, fc_type, null, for_stmt_decl_or_assign,
                                       opt_var != false, loc);

                if (opt_tk_do == null)
                {
                    file_position    fp      = expr2.source_context.end_position;
                    syntax_tree_node err_stn = stmt;
                    if (err_stn == null)
                    {
                        err_stn = expr2;
                    }
                    parsertools.errors.Add(new PABCNETUnexpectedToken(parsertools.CurrentFileName,
                                                                      StringResources.Get("TKDO"),
                                                                      new SourceContext(fp.line_num, fp.column_num + 1, fp.line_num, fp.column_num + 1, 0, 0),
                                                                      err_stn));
                }

                if (!opt_var && for_stmt_decl_or_assign == null)
                {
                    parsertools.AddWarningFromResource("USING_UNLOCAL_FOR_VARIABLE", identifier.source_context);
                }
                return(nfs);
            }
Exemple #3
0
 public SymInfoSyntax(ident Id, SymKind SK, type_definition Td = null, Attributes Attr = 0)
 {
     this.Id   = Id;
     this.Td   = Td;
     this.SK   = SK;
     this.Attr = Attr;
 }
 public void AddSymbols(List <ident> names, SymKind kind, type_definition td = null, Attributes attr = 0)
 {
     foreach (var n in names)
     {
         AddSymbol(n, kind, td, attr);
     }
 }
Exemple #5
0
        private expression convert_cast_expression(ICSharpCode.NRefactory.Ast.CastExpression expr)
        {
            type_definition td  = get_type_reference(expr.CastTo);
            expression      exp = get_expression(expr.Expression);

            return(new typecast_node(exp as addressed_value, td, op_typecast.typecast));
        }
            public static var_statement CreateVarStatementNode(string idName, type_definition varType, expression initValue)
            {
                var id     = new ident(idName);
                var idlist = new ident_list(id);
                var vdef   = new var_def_statement(idlist, varType, initValue, definition_attribute.None, false, null);

                return(new var_statement(vdef, null));
            }
 private static where_definition GetWhereRestriction(type_definition restriction, ident templateName)
 {
     return  // where
            (new where_definition(
                 //      ConstraintTC :
                 new ident_list(templateName),
                 new where_type_specificator_list(new List <type_definition> {
         //                  IConstraint<T, C>,
         restriction,
         //                                        constructor
         new declaration_specificator(DeclarationSpecificator.WhereDefConstructor, "constructor")
     })));
 }
            public typecast_node NewAsIsExpr(syntax_tree_node term, op_typecast typecast_op,
                                             type_definition simple_or_template_type_reference, LexLocation loc)
            {
                var naie = new typecast_node((addressed_value)term, simple_or_template_type_reference, typecast_op,
                                             loc);

                if (!(term is addressed_value))
                {
                    parsertools.errors.Add(new bad_operand_type(parsertools.CurrentFileName, term.source_context,
                                                                naie));
                }
                return(naie);
            }
Exemple #9
0
        private void CheckIfCanBeMatched(expression matchedExpression, type_definition targetType)
        {
            var type       = convert_strong(targetType);
            var expression = convert_strong(matchedExpression).type;

            if (type_table.is_derived(type, expression) ||
                type_table.is_derived(expression, type) ||
                AreTheSameType(type, expression) ||
                type.IsInterface && expression.IsInterface)
            {
                return;
            }

            AddError(get_location(matchedExpression), "EXPRESSION_OF_TYPE_{0}_CANNOT_BE_MATCHED_AGAINST_PATTERN_WITH_TYPE_{1}", expression.name, type.name);
        }
Exemple #10
0
        private void CheckIfCanBeMatched(expression matchedExpression, type_definition targetType)
        {
            var type       = convert_strong(targetType);
            var expression = convert_strong(matchedExpression);

            if (expression is typed_expression)
            {
                try_convert_typed_expression_to_function_call(ref expression);
            }

            var expressionType = expression.type;

            if (type_table.is_derived(type, expressionType) ||
                type_table.is_derived(expressionType, type) ||
                AreTheSameType(type, expressionType) ||
                type.IsInterface ||
                expressionType.IsInterface || type.is_generic_parameter || expressionType.is_generic_parameter)
            {
                return;
            }

            AddError(get_location(matchedExpression), "EXPRESSION_OF_TYPE_{0}_CANNOT_BE_MATCHED_AGAINST_PATTERN_WITH_TYPE_{1}", expressionType.name, type.name);
        }
            public static procedure_definition CreateFunctionDefinitionNode(method_name methName, formal_parameters formalPars, bool ofObject, bool classKeyword, statement procBody, type_definition returnType, SourceContext sc)
            {
                procedure_definition procDef = new procedure_definition();

                function_header procHeader = new function_header();

                procHeader.name           = methName;
                procHeader.source_context = sc;
                if (procHeader.name.meth_name is template_type_name)
                {
                    procHeader.template_args = (procHeader.name.meth_name as template_type_name).template_args;
                    ident id = new ident(procHeader.name.meth_name.name);
                    procHeader.name.meth_name = id;
                }
                procHeader.parameters    = formalPars;
                procHeader.of_object     = ofObject;
                procHeader.class_keyword = classKeyword;
                procHeader.return_type   = returnType;

                statement_list stmtList = new statement_list();

                stmtList.subnodes.Add(procBody);

                block bl = new block(null, null);

                bl.program_code = stmtList;

                procDef.proc_header = procHeader;
                procDef.proc_body   = (proc_block)bl;

                return(procDef);
            }
 public virtual void visit(type_definition _type_definition)
 {
     DefaultVisit(_type_definition);
 }
		public virtual void post_do_visit(type_definition _type_definition)
		{
		}
		public override void visit(type_definition _type_definition)
		{
			DefaultVisit(_type_definition);
			pre_do_visit(_type_definition);
			visit(type_definition.attr_list);
			post_do_visit(_type_definition);
		}
        void semantic_check_for_new_range(SyntaxTree.diapason_expr_new diap, type_definition td, ident id)
        {
            var from = diap.left;
            var to   = diap.right;

            var semfrom = convert_strong(from);
            var b       = convertion_data_and_alghoritms.can_convert_type(semfrom, SystemLibrary.SystemLibrary.integer_type);
            var b1      = false;

            if (!b)
            {
                b1 = convertion_data_and_alghoritms.can_convert_type(semfrom, SystemLibrary.SystemLibrary.char_type);
            }
            if (!b && !b1)
            {
                AddError(get_location(from), "INTEGER_OR_CHAR_VALUE_EXPECTED");
            }

            var semto = convert_strong(to);
            var c     = convertion_data_and_alghoritms.can_convert_type(semto, SystemLibrary.SystemLibrary.integer_type);
            var c1    = false;

            if (!c)
            {
                c1 = convertion_data_and_alghoritms.can_convert_type(semto, SystemLibrary.SystemLibrary.char_type);
            }
            if (!c && !c1)
            {
                AddError(get_location(to), "INTEGER_OR_CHAR_VALUE_EXPECTED");
            }

            if (b != c || c1 != b1)
            {
                AddError(get_location(to), "INCOMPATIBLE_DIAPASON_BOUNDS_TYPES");
            }

            if (td != null && !(td is no_type_foreach))
            {
                // то мы определили тип явно в заголовке
                var semtype = convert_strong(td);
                var d       = convertion_data_and_alghoritms.can_convert_type(semtype, SystemLibrary.SystemLibrary.integer_type);
                var d1      = false;
                if (!d)
                {
                    d1 = convertion_data_and_alghoritms.can_convert_type(semtype, SystemLibrary.SystemLibrary.char_type);
                }
                if (!d && !d1)
                {
                    AddError(get_location(td), "INTEGER_OR_CHAR_VALUE_EXPECTED");
                }
                if (b != d || b1 != d1)
                {
                    AddError(get_location(id), "INCOMPATIBLE_TYPES_OF_ELEMENT_AND_DIAPASON");
                }
            }
            else if (td == null)
            {
                var semid = convert_strong(id);
                var e     = convertion_data_and_alghoritms.can_convert_type(semid, SystemLibrary.SystemLibrary.integer_type);
                var e1    = false;
                if (!e)
                {
                    e1 = convertion_data_and_alghoritms.can_convert_type(semid, SystemLibrary.SystemLibrary.char_type);
                }
                if (!e && !e1)
                {
                    AddError(get_location(id), "INTEGER_OR_CHAR_VALUE_EXPECTED");
                }

                if (b != e || b1 != e1)
                {
                    AddError(get_location(id), "INCOMPATIBLE_TYPES_OF_ELEMENT_AND_DIAPASON");
                }
            }
        }
 public static procedure_definition CreateFunctionDefinitionNode(string methName, formal_parameters formalPars, bool classKeyword, statement procBody, type_definition returnType)
 {
     return(InternalCreateFunctionDefinitionNode(methName, formalPars, classKeyword, procBody, returnType, null));
 }
 public virtual void AddSymbol(ident name, SymKind kind, type_definition td = null, Attributes attr = 0)
 {
     Current.Symbols.Add(new SymInfoSyntax(name, kind, td, attr));
 }
 public type_node visit(type_definition type_def)
 {
     type_def.visit(syntax_tree_visitor);
     return(ret_semantic as type_node);
 }
        public ident func_decl_lambda(object lr0, object lr2)
        {
            statement_list    _statement_list    = (statement_list)lr2;
            expression_list   _expression_list   = new expression_list();
            ident_list        _i_l               = new ident_list();
            formal_parameters _formal_parameters = new formal_parameters();

            if (lr0 != null)
            {
                List <object> ar = (List <object>)lr0;
                for (int i = 0; i < ar.Count; i++)
                {
                    if (ar[i] is ident)
                    {
                        _i_l.idents.Add((ident)ar[i]);
                    }
                    else
                    {
                        _i_l.idents.Add(((var_def_statement)ar[i]).vars.idents[0]);
                    }
                }

                for (int i = 0; i < _i_l.idents.Count; i++)
                {
                    _expression_list.expressions.Add(_i_l.idents[i]);
                }

                for (int i = 0; i < ar.Count; i++)
                {
                    ident_list _ident_list = new ident_list();
                    ident      id          = _i_l.idents[i];
                    _ident_list.idents.Add(id);
                    string           name_param        = id.name;
                    typed_parameters _typed_parameters = null;
                    int k = 0;
                    {
                        named_type_reference _named_type_reference = new named_type_reference();
                        type_definition      t_d = new type_definition();
                        if (ar[i] is ident)
                        {
                            ident idtype = new ident("object");
                            _named_type_reference.names.Add(idtype);
                            t_d = (type_definition)_named_type_reference;
                        }
                        else
                        {
                            t_d = ((var_def_statement)ar[i]).vars_type;
                        }
                        _typed_parameters = new typed_parameters(_ident_list, t_d, parametr_kind.none, null);
                        //parsertools.create_source_context(_typed_parameters, _ident_list, t_d);
                    }
                    _formal_parameters.params_list.Add(_typed_parameters);
                }
            }
            //////////////////////////
            named_type_reference _named_type_reference1 = new named_type_reference();
            ident idtype1 = new ident("object");

            _named_type_reference1.source_context = idtype1.source_context;
            _named_type_reference1.names.Add(idtype1);
            /////////////////////////////
            lambda_num++;
            function_lambda_definition _procedure_definition = new function_lambda_definition();

            _procedure_definition.formal_parameters = _formal_parameters;
            _procedure_definition.return_type       = (type_definition)_named_type_reference1;
            _procedure_definition.ident_list        = _i_l;
            _procedure_definition.proc_body         = null;
            _procedure_definition.parameters        = _expression_list;
            _procedure_definition.lambda_name       = "__lambda__" + lambda_num;
            //new function_lambda_definition(_formal_parameters, (type_definition)_named_type_reference1, _i_l, null, _expression_list, "lambda" + lambda_num);
            object rt = _i_l;

            _procedure_definition.proc_body = _statement_list;

            //////////////////////////////vnutrennie lambda
            if (_procedure_definition.defs == null)
            {
                _procedure_definition.defs = new List <declaration>();
            }
            while (pascalABC_lambda_definitions.Count > 0 && pascalABC_lambda_definitions[pascalABC_lambda_definitions.Count - 1] != null)
            {
                _procedure_definition.defs.Add(lambda((function_lambda_definition)pascalABC_lambda_definitions[pascalABC_lambda_definitions.Count - 1]));
                pascalABC_lambda_definitions.RemoveAt(pascalABC_lambda_definitions.Count - 1);
            }
            if (pascalABC_lambda_definitions.Count > 0 && pascalABC_lambda_definitions[pascalABC_lambda_definitions.Count - 1] == null)
            {
                pascalABC_lambda_definitions.RemoveAt(pascalABC_lambda_definitions.Count - 1);
            }
            pascalABC_lambda_definitions.Add(_procedure_definition);
            ///////////////////////////////////////////////
            //parsertools.create_source_context(_procedure_definition, _expression_list, rt);
            ident _name = new ident(_procedure_definition.lambda_name);

            if (lr0 != null)
            {
                _name.source_context = _i_l.idents[0].source_context;
            }
            return(_name);
        }
		public override void visit(type_definition _type_definition)
		{
			executer.visit(_type_definition);
			if (_type_definition.attr_list != null)
				this.visit((dynamic)_type_definition.attr_list);
			if (_type_definition.attributes != null)
				this.visit((dynamic)_type_definition.attributes);
		}
Exemple #21
0
 public virtual void visit(type_definition _type_definition)
 {
 }
		public virtual void visit(type_definition _type_definition)
		{
			DefaultVisit(_type_definition);
		}
Exemple #23
0
 public override void visit(type_definition _type_definition)
 {
     throw new NotImplementedException();
 }
 public override void visit(type_definition _type_definition)
 {
 }
 private static procedure_definition InternalCreateFunctionDefinitionNode(string methName, formal_parameters formalPars, bool classKeyword, statement procBody, type_definition returnType, SourceContext sc)
 {
     return(PascalABCCompiler.TreeConverter.LambdaHelper.SyntaxTreeNodesConstructor.CreateFunctionDefinitionNode(new method_name(methName),
                                                                                                                 formalPars,
                                                                                                                 false,
                                                                                                                 classKeyword,
                                                                                                                 procBody,
                                                                                                                 returnType,
                                                                                                                 sc));
 }
        public typecast_node NewAsIsConstexpr(expression constterm, op_typecast typecastop, type_definition tdef, LexLocation loc)
        {
            var naic = new typecast_node(constterm as addressed_value, tdef, typecastop, loc);

            if (!(constterm is addressed_value))
            {
                parsertools.errors.Add(new bad_operand_type(parsertools.CurrentFileName, constterm.source_context, naic));
            }
            return(naic);
        }
		public virtual void visit(type_definition _type_definition)
		{
		}
Exemple #28
0
 public static simple_property BuildSimpleReadWriteProperty(ident name, ident field, type_definition type)
 {
     return(new simple_property(name, type, new property_accessors(new read_accessor_name(field, null, null), new write_accessor_name(field, null, null))));
 }
Exemple #29
0
        public static procedure_definition BuildShortFuncDefinition(formal_parameters fp, procedure_attributes_list att, method_name name, type_definition result, expression ex, SourceContext headsc)
        {
            var ff = new function_header(fp, att, name, null, result, headsc);
            procedure_definition pd = BuildShortProcFuncDefinition(ff, new assign("Result", ex, ex.source_context));

            return(pd);
        }