Esempio n. 1
0
        public override AstNode Visit(DereferenceOperation node)
        {
            // Begin the node.
            builder.BeginNode(node);

            // Get the pointer expression.
            Expression pointer = node.GetPointer();
            pointer.Accept(this);

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

            return builder.EndNode();
        }
Esempio n. 2
0
        public override AstNode Visit(DereferenceOperation node)
        {
            // Evaluate the pointer.
            Expression pointerExpr = node.GetPointer();
            pointerExpr.Accept(this);

            // Get the pointer type.
            IChelaType pointerType = pointerExpr.GetNodeType();
            if(pointerType.IsReference())
                pointerType = DeReferenceType(pointerType);

            // Constant pointer aren't problems.
            if(pointerType.IsConstant())
                pointerType = DeConstType(pointerType);

            // Must be a pointer.
            if(!pointerType.IsPointer())
                Error(node, "expected pointer expression.");

            // Set the coercion type.
            node.SetCoercionType(pointerType);

            // Create the "variable".
            IChelaType slotType = DePointerType(pointerType);
            PointedSlot slot = new PointedSlot(slotType);
            node.SetNodeType(ReferenceType.Create(slotType));
            node.SetNodeValue(slot);

            return node;
        }