Esempio n. 1
0
        public override AstNode Visit(CastOperation node)
        {
            // First expand the value.
            Expression value = node.GetValue();
            value = (Expression)value.Accept(this);
            node.SetValue(value);

            // Check if result is constant.
            IChelaType nodeType = node.GetNodeType();
            if(!nodeType.IsConstant())
                return node;

            // Cast the constant.
            IChelaType valueType = value.GetNodeType();
            if(valueType == nodeType)
                return value;

            ConstantValue valueConstant = (ConstantValue)value.GetNodeValue();
            return valueConstant.Cast(nodeType).ToAstNode(node.GetPosition());
        }
Esempio n. 2
0
 public override AstNode Visit(CastOperation node)
 {
     // Visit recursively.
     node.GetValue().Accept(this);
     return node;
 }
Esempio n. 3
0
        public override AstNode Visit(CastOperation node)
        {
            // Begin the node.
            builder.BeginNode(node);

            // Get the target type and value.
            //Expression target = node.GetTarget();
            Expression value = node.GetValue();

            // Visit them.
            //target.Accept(this);
            value.Accept(this);

            // Get their types.
            IChelaType targetType = node.GetNodeType();
            IChelaType valueType = value.GetNodeType();
            if(targetType != valueType)
                Cast(node, value.GetNodeValue(), valueType, targetType, true);

            return builder.EndNode();
        }
Esempio n. 4
0
        public override AstNode Visit(CastOperation node)
        {
            // Get the target type and value.
            Expression target = node.GetTarget();
            Expression value = node.GetValue();

            // Set the type hint to the target.
            target.SetHints(Expression.TypeHint);

            // Visit them.
            target.Accept(this);
            value.Accept(this);

            // Get the target type.
            IChelaType targetType = target.GetNodeType();
            targetType = ExtractActualType(target, targetType);
            if(targetType.IsPassedByReference())
                targetType = ReferenceType.Create(targetType);

            // Perform constant result check.
            IChelaType valueType = value.GetNodeType();
            if(valueType.IsConstant() &&
               targetType.IsPrimitive())
            {
                valueType = DeConstType(valueType);
                if(valueType.IsPrimitive())
                    targetType = ConstantType.Create(targetType);
            }

            // TODO: Check if it is possible to perform the cast.

            // Set the node type.
            node.SetNodeType(targetType);

            return node;
        }