示例#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());
        }
示例#2
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();
        }