Esempio n. 1
0
        public override AstNode Visit(SizeOfExpression node)
        {
            // Visit the type expression.
            Expression typeExpr = node.GetTypeExpression();
            typeExpr.Accept(this);

            // Select the type to use.
            IChelaType theType = typeExpr.GetNodeType();
            if(theType.IsMetaType())
                theType = ExtractActualType(typeExpr, theType);

            if(theType.IsReference() || theType.IsPassedByReference())
                Error(node, "cannot use sizeof with reference types.");

            // Store the type as the coercion one.
            node.SetCoercionType(theType);

            // Select if the type is constant or not.
            if(theType.IsPointer() || theType == ChelaType.GetSizeType() ||
               theType == ChelaType.GetPtrDiffType())
                node.SetNodeType(ChelaType.GetIntType());
            else
                node.SetNodeType(ConstantType.Create(ChelaType.GetIntType()));

            return node;
        }