Exemplo n.º 1
0
        public static procedure_definition BuildToStringFuncForAutoClass(List <ident> names)
        {
            var pal = new procedure_attributes_list(proc_attribute.attr_override);
            var fp  = new formal_parameters();
            var ff  = new function_header("ToString", "string", fp, pal);

            var      cleft  = new char_const('(');
            var      cright = new char_const(')');
            var      ccomma = new char_const(',');
            bin_expr ex     = new bin_expr(cleft, cright, Operators.Plus);

            for (var i = 0; i < names.Count; i++)
            {
                var dn     = new dot_node(names[i], new ident("ToString"));
                var asnode = new typecast_node(names[i], new named_type_reference("object"), op_typecast.as_op);
                var eqnode = new bin_expr(asnode, new nil_const(), Operators.Equal);
                var expr   = new question_colon_expression(eqnode, new string_const("nil"), dn);
                ex.left = new bin_expr(ex.left, expr, Operators.Plus);
                if (i < names.Count - 1)
                {
                    ex.left = new bin_expr(ex.left, ccomma, Operators.Plus);
                }
            }
            var ass = new assign("Result", ex);

            return(BuildShortProcFuncDefinitionNoSC(ff, ass));
        }
 public LambdaResultTypeInferrer(function_header lambdaHeader, proc_block lambdaBody, syntax_tree_visitor syntaxTreeVisitor)
 {
     this.lambdaBody        = lambdaBody;
     this.lambdaHeader      = lambdaHeader;
     this.syntaxTreeVisitor = syntaxTreeVisitor;
     resultExpressionsTypes = new List <Tuple <type_node, expression, expression_node> >();
 }
Exemplo n.º 3
0
            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);
            }
Exemplo n.º 4
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);
        }
        public procedure_definition lambda(function_lambda_definition _function_lambda_definition)
        {
            procedure_definition _func_def     = new procedure_definition();
            method_name          _method_name1 = new method_name(null, null, new ident(_function_lambda_definition.lambda_name), null);
            //parsertools.create_source_context(_method_name1, _method_name1.meth_name, _method_name1.meth_name);
            function_header _function_header1 = new function_header();

            object rt1 = new object();

            _function_header1.name = _method_name1;
            if (_function_header1.name.meth_name is template_type_name)
            {
                _function_header1.template_args = (_function_header1.name.meth_name as template_type_name).template_args;
                ident id = new ident(_function_header1.name.meth_name.name);
                //parsertools.create_source_context(id, _function_header1.name.meth_name, _function_header1.name.meth_name);
                _function_header1.name.meth_name = id;
            }

            formal_parameters fps = new PascalABCCompiler.SyntaxTree.formal_parameters();

            _function_header1.parameters = _function_lambda_definition.formal_parameters;//fps;

            /*SyntaxTree.named_type_reference _named_type_reference = new SyntaxTree.named_type_reference();
             * SyntaxTree.ident idtype = new SyntaxTree.ident("object");
             * _named_type_reference.source_context = idtype.source_context;
             * _named_type_reference.names.Add(idtype);
             * rt1 = _named_type_reference;
             * _function_header1.return_type = (SyntaxTree.type_definition)_named_type_reference;*/
            _function_header1.return_type = _function_lambda_definition.return_type;

            _function_header1.of_object     = false;
            _function_header1.class_keyword = false;
            token_info _token_info = new token_info("function");
            //_token_info.source_context = parsertools.GetTokenSourceContext();
            //parsertools.create_source_context(_function_header1, _token_info, _token_info);

            block          _block1 = new block(null, null);
            statement_list sl1     = new statement_list();

            sl1.subnodes.Add(_function_lambda_definition.proc_body);
            _block1.program_code  = sl1;
            _func_def.proc_header = _function_header1;
            _func_def.proc_body   = (proc_block)_block1;
            if (_function_lambda_definition.defs != null)
            {
                if (((block)_func_def.proc_body).defs == null)
                {
                    ((block)_func_def.proc_body).defs = new declarations();
                }
                for (int l = 0; l < _function_lambda_definition.defs.Count; l++)
                {
                    ((block)_func_def.proc_body).defs.defs.Add(_function_lambda_definition.defs[l] as procedure_definition);
                }
            }
            _function_lambda_definition.proc_definition = _func_def;
            //parsertools.create_source_context(_func_def, _function_header1, _function_header1);
            return(_func_def);
        }
Exemplo n.º 6
0
 public override void visit(function_header _function_header)
 {
     prepare_node(_function_header.name, "name");
     prepare_node(_function_header.parameters, "parameters");
     prepare_node(_function_header.proc_attributes, "attributes");
     prepare_node(_function_header.template_args, "template_params");
     prepare_node(_function_header.where_defs, "where_defs");
     prepare_node(_function_header.return_type, "return_type");
 }
Exemplo n.º 7
0
 public override void visit(function_header fh)
 {
     if (first_time_visit_function_header)
     {
         DefaultVisit(fh);
         first_time_visit_function_header = false;
     }
     // DO NOTHING
 }
Exemplo n.º 8
0
        /// <summary>
        /// Вывод типа возвращаемого значения лямбды
        /// </summary>
        public static void InferResultType(function_header funcHeader, proc_block procBody, syntax_tree_visitor visitor)
        {
            var retType = funcHeader.return_type as lambda_inferred_type;

            if (retType != null && retType.real_type is lambda_any_type_node)
            {
                retType.real_type = new LambdaResultTypeInferrer(funcHeader, procBody, visitor).InferResultType();
            }
        }
Exemplo n.º 9
0
 public override void visit(function_header _function_header)
 {
     if (_function_header.of_object)
     {
         text += "of object";
     }
     if (_function_header.class_keyword)
     {
         text += "class proc";
     }
 }
Exemplo n.º 10
0
        private procedure_header get_method_header(ICSharpCode.NRefactory.Ast.MethodDeclaration method)
        {
            procedure_header proc_header;

            if (is_void(method.TypeReference))
            {
                proc_header = new procedure_header();
            }
            else
            {
                proc_header = new function_header();
            }
            proc_header.name           = new method_name();
            proc_header.name.meth_name = new ident(method.Name);
            proc_header.source_context = get_source_context(method);
            if (proc_header is function_header)
            {
                (proc_header as function_header).return_type = get_type_reference(method.TypeReference);
            }
            proc_header.parameters      = get_parameters(method.Parameters);
            proc_header.proc_attributes = new procedure_attributes_list();
            if ((method.Modifier & ICSharpCode.NRefactory.Ast.Modifiers.Abstract) == ICSharpCode.NRefactory.Ast.Modifiers.Abstract)
            {
                proc_header.proc_attributes.proc_attributes.Add(new procedure_attribute(proc_attribute.attr_abstract));
            }
            if ((method.Modifier & ICSharpCode.NRefactory.Ast.Modifiers.Virtual) == ICSharpCode.NRefactory.Ast.Modifiers.Virtual)
            {
                proc_header.proc_attributes.proc_attributes.Add(new procedure_attribute(proc_attribute.attr_virtual));
            }
            if ((method.Modifier & ICSharpCode.NRefactory.Ast.Modifiers.Override) == ICSharpCode.NRefactory.Ast.Modifiers.Override)
            {
                proc_header.proc_attributes.proc_attributes.Add(new procedure_attribute(proc_attribute.attr_override));
            }
            //if ((method.Modifier & ICSharpCode.NRefactory.Ast.Modifiers.Overloads) == ICSharpCode.NRefactory.Ast.Modifiers.Overloads)
            //	proc_header.proc_attributes.proc_attributes.Add(new procedure_attribute(proc_attribute.attr_overload));
            if ((method.Modifier & ICSharpCode.NRefactory.Ast.Modifiers.New) == ICSharpCode.NRefactory.Ast.Modifiers.New)
            {
                proc_header.proc_attributes.proc_attributes.Add(new procedure_attribute(proc_attribute.attr_reintroduce));
            }
            if ((method.Modifier & ICSharpCode.NRefactory.Ast.Modifiers.Static) == ICSharpCode.NRefactory.Ast.Modifiers.Static)
            {
                proc_header.class_keyword = true;
            }
            return(proc_header);
        }
Exemplo n.º 11
0
 public override void visit(function_header _function_header)
 {
     AddPossibleComments(_function_header, true, false);
     _function_header.name.visit(this);
     if (_function_header.parameters != null)
     {
         _function_header.parameters.visit(this);
     }
     _function_header.return_type.visit(this);
     if (_function_header.proc_attributes != null)
     {
         _function_header.proc_attributes.visit(this);
     }
     if (_function_header.where_defs != null)
     {
         _function_header.where_defs.visit(this);
     }
 }
Exemplo n.º 12
0
		public override void visit(function_header _function_header)
		{
			executer.visit(_function_header);
			if (_function_header.return_type != null)
				this.visit((dynamic)_function_header.return_type);
			if (_function_header.parameters != null)
				this.visit((dynamic)_function_header.parameters);
			if (_function_header.proc_attributes != null)
				this.visit((dynamic)_function_header.proc_attributes);
			if (_function_header.name != null)
				this.visit((dynamic)_function_header.name);
			if (_function_header.template_args != null)
				this.visit((dynamic)_function_header.template_args);
			if (_function_header.where_defs != null)
				this.visit((dynamic)_function_header.where_defs);
			if (_function_header.attr_list != null)
				this.visit((dynamic)_function_header.attr_list);
			if (_function_header.attributes != null)
				this.visit((dynamic)_function_header.attributes);
		}
Exemplo n.º 13
0
 public override void visit(function_header h)
 {
     AddProcHeader(h);
 }
Exemplo n.º 14
0
 public virtual void visit(function_header _function_header)
 {
     DefaultVisit(_function_header);
 }
Exemplo n.º 15
0
		public virtual void post_do_visit(function_header _function_header)
		{
		}
Exemplo n.º 16
0
		public override void visit(function_header _function_header)
		{
			DefaultVisit(_function_header);
			pre_do_visit(_function_header);
			visit(function_header.return_type);
			post_do_visit(_function_header);
		}
		public virtual void visit(function_header _function_header)
		{
			DefaultVisit(_function_header);
		}
Exemplo n.º 18
0
		public virtual void visit(function_header _function_header)
		{
		}
Exemplo n.º 19
0
 public virtual void visit(function_header _function_header)
 {
 }
 public override void visit(function_header _function_header)
 {
     connect(_function_header);
 }