public expression_node visit(expression expr)
        {
            expr.visit(syntax_tree_visitor);

            /*addressed_expression ad = ret_semantic as addressed_expression;
             * if (ad != null && ad.is_addressed)
             * {
             *  if (convertion_data_and_alghoritms.check_for_constant(ad))
             *      ad.is_addressed = false;
             * }*/

            //Надеюсь, это сильно не скажется на производительности, хотя в другом случае этот же код просто будет разбросан по всем метдам syntax_tree_visitor-а.
            base_function_call bfc = ret_semantic as base_function_call;

            if (bfc != null)
            {
                if (bfc.simple_function_node.compile_time_executor != null)
                {
                    expression_node ex = bfc.simple_function_node.compile_time_executor(bfc.location, bfc.parameters.ToArray());
                    if (ex != null)
                    {
                        return(ex);
                    }
                }
            }

            return(ret_semantic as expression_node);
        }
Example #2
0
 public override void visit(ASTVisitor prefix, ASTVisitor postfix)
 {
     prefix(this);
     expr.visit(prefix, postfix);
     List.visit(sections, prefix, postfix);
     postfix(this);
 }
Example #3
0
    static int TypeArgumentCount(expression ast)
    {
        ArgumentCounter c = new ArgumentCounter();
        ASTVisitor      v = new ASTVisitor(c.fn);

        ast.visit(v);
        return(c.Count);
    }
Example #4
0
    static expression fix_cast(expression e1, expression e2)
    {
        // the first two cases are simple optimizations for the common case.
        if (e1 is cast_expression)
        {
            if (e2 is invocation_expression)
            {
                return(e1);
            }
            return(e2);
        }
        else if (e2 is cast_expression)
        {
            if (e1 is invocation_expression)
            {
                return(e2);
            }
            return(e1);
        }
        else
        {
            //
            // This is to handle the pathological case of (a+(b)-c)
            // or worse, ((a+b)+c-(d)e)
            //
            // The code is complicated because neither parse is rooted with a cast...
            //
            CastCounter c1 = new CastCounter();
            ASTVisitor  a1 = new ASTVisitor(c1.fn);
            e1.visit(a1);

            CastCounter c2 = new CastCounter();
            ASTVisitor  a2 = new ASTVisitor(c2.fn);
            e2.visit(a2);

            if (c1.Count == c2.Count + 1)
            {
                return(e1);
            }
            else if (c1.Count == c2.Count - 1)
            {
                return(e2);
            }
            else
            {
                // fall off into error message.
            }
        }
        throw new System.Exception("failed to disambiguate expressions");
    }
 public int32_const Convert(expression expr)
 {
     if (expr == null)
     {
         return(null);
     }
     try
     {
         expr.visit(this);
     }
     catch
     {
         return(null);
     }
     if (intStack.Count == 1)
     {
         int32_const i = new int32_const(intStack.Pop());
         i.source_context = expr.source_context;
         return(i);
     }
     return(null);
 }