Esempio n. 1
0
        internal static ExprAndTypeNode ExprAndType(Kind k, ExprNode expr, TypeNode type, Symbol s)
        {
            ExprAndTypeNode res = new ExprAndTypeNode();

            res.kind  = k;
            res.start = s.pos;
            res.end   = s.endpos;
            res.expr  = expr;
            res.type  = type;
            return(res);
        }
Esempio n. 2
0
        internal static TypeNode type_from_expr(ExprNode expr)
        {
            Symbol s = new Symbol();

            s.pos    = expr.start;
            s.endpos = expr.end;

            switch (expr.kind)
            {
            case Kind.Identifier:
                return(Make.TypeName((IdentNode)expr, s));

            case Kind.Dot:
            case Kind.TypeDot:
                string id = String.Empty;
                while (expr.kind == Kind.Dot)
                {
                    IdentNode idn = ((BinaryNode)expr).right as IdentNode;
                    id   = "." + idn.identifier + id;
                    expr = ((BinaryNode)expr).left;
                }
                if (expr.kind == Kind.TypeDot)
                {
                    // types like: int.A
                    ExprAndTypeNode etn = (ExprAndTypeNode)expr;
                    id = (etn.type as BaseType).typeid.ToString().Substring(1) + "." + (etn.expr as IdentNode).identifier + id;
                    return(Make.TypeName(Make.Ident(id, s), s));
                }
                else if (expr.kind == Kind.Identifier)
                {
                    // types like: a.b.c
                    ((IdentNode)expr).identifier += id;
                    return(Make.TypeName((IdentNode)expr, s));
                }
                return(null);

            case Kind.DimmedExpr:
                TypeExprNode ten = (TypeExprNode)expr;
                return(Make.OneArrayType(type_from_expr(ten.expr), ten.spec, s));
            }
            return(null);
        }
Esempio n. 3
0
 internal static ExprAndTypeNode ExprAndType( Kind k, ExprNode expr, TypeNode type, Symbol s )
 {
     ExprAndTypeNode res = new ExprAndTypeNode();
     res.kind = k;
     res.start = s.pos;
     res.end = s.endpos;
     res.expr = expr;
     res.type = type;
     return res;
 }