Ejemplo n.º 1
0
        public override AstNode Visit(IsExpression node)
        {
            // Begin the node.
            builder.BeginNode(node);

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

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

            // Perform coercion.
            IChelaType valueType = value.GetNodeType();
            IChelaType coercionType = node.GetCoercionType();
            if(valueType != coercionType)
                Cast(node, value.GetNodeValue(), valueType, coercionType);

            // Perform the type comparison.
            IChelaType targetType = node.GetTargetType();
            if(targetType != valueType)
            {
                builder.CreateIsA(targetType);
            }
            else
            {
                builder.CreatePop();
                builder.CreateLoadBool(true);
            }

            return builder.EndNode();
        }
Ejemplo n.º 2
0
        public override AstNode Visit(IsExpression node)
        {
            // Get the target type and value.
            Expression compare = node.GetCompare();
            Expression value = node.GetValue();

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

            // The value must be a reference.
            IChelaType valueType = value.GetNodeType();

            // De-ref the value.
            valueType = DeReferenceType(valueType);
            valueType = DeReferenceType(valueType);
            if(valueType.IsPassedByReference())
                node.SetCoercionType(ReferenceType.Create(valueType));
            else if(valueType.IsFirstClass() || valueType.IsPlaceHolderType())
                node.SetCoercionType(valueType);
            else
                Error(node, "expected an object instead of {0}", valueType.GetDisplayName());

            // Get the target type.
            IChelaType targetType = compare.GetNodeType();
            targetType = ExtractActualType(compare, targetType);

            // Store the target type.
            node.SetTargetType(targetType);

            // Set the node type.
            node.SetNodeType(ChelaType.GetBoolType());

            return node;
        }