public override TypeNode EvaluateType(API api, TypeNode type, bool isStatic)
        {
            TypeNode expType = expresion.EvaluateType(api, null, isStatic);
            TypeNode t       = api.getTypeForIdentifier(Utils.getNameForType(targetCastType));
            string   rule    = t.ToString() + "," + expType.ToString();
            string   rule2   = t.getComparativeType() + "," + expType.ToString();
            string   rule3   = t.getComparativeType() + "," + expType.getComparativeType();

            if (rules.Contains(rule) || rules.Contains(rule2) || rules.Contains(rule3) || t.Equals(expType))
            {
                return(t);
            }
            if (!(t is ClassTypeNode))
            {
                Utils.ThrowError("There is no relation between " + expType.ToString() + " and " + t.ToString());
            }
            if (expType is ClassTypeNode)
            {
                if (api.checkRelationBetween(expType, t))
                {
                    return(t);
                }
            }
            if (!(expType is NullTypeNode))
            {
                Utils.ThrowError("There is no relation between " + expType.ToString() + " and " + t.ToString());
            }

            return(t);
        }
Ejemplo n.º 2
0
        public override TypeNode EvaluateType(API api, TypeNode type, bool isStatic)
        {
            TypeNode t1 = unaryExpression.EvaluateType(api, null, true);

            if (api.TokenPass(unaryOperator, TokenType.OP_SUM, TokenType.OP_SUBSTRACT, TokenType.OP_PLUS_PLUS, TokenType.OP_MINUS_MINUS))
            {
                if (t1.ToString() != Utils.Int && t1.ToString() != Utils.Float && t1.ToString() != Utils.Char)
                {
                    throw new SemanticException("Invalid pre unary expression. Cant apply " + unaryOperator.ToString() + " to " + t1.ToString() + " " + token.getLine());
                }
            }
            if (api.TokenPass(unaryOperator, TokenType.OP_BITWISE_NOT))
            {
                if (t1.ToString() != Utils.Char && t1.ToString() != Utils.Int)
                {
                    throw new SemanticException("Invalid pre unary expression. Cant apply " + unaryOperator.ToString() + " to " + t1.ToString() + " " + token.getLine());
                }
                if (t1.ToString() == Utils.Char)
                {
                    return(new IntTypeNode());
                }
            }
            if (api.TokenPass(unaryOperator, TokenType.OP_NOT))
            {
                if (t1.ToString() != Utils.Bool)
                {
                    throw new SemanticException("Invalid pre unary expression. Cant apply " + unaryOperator.ToString() + " to " + t1.ToString() + " " + token.getLine());
                }
            }
            return(t1);
        }