Beispiel #1
0
        public override AstNode Visit(TypeNode node)
        {
            // Evaluate the type.
            IChelaType nodeType = null;
            switch(node.GetKind())
            {
            case TypeKind.Void:
                nodeType = ChelaType.GetVoidType();
                break;
            case TypeKind.Bool:
                nodeType = ChelaType.GetBoolType();
                break;
            case TypeKind.Byte:
                nodeType = ChelaType.GetByteType();
                break;
            case TypeKind.SByte:
                nodeType = ChelaType.GetSByteType();
                break;
            case TypeKind.Char:
                nodeType = ChelaType.GetCharType();
                break;
            case TypeKind.Double:
                nodeType = ChelaType.GetDoubleType();
                break;
            case TypeKind.Float:
                nodeType = ChelaType.GetFloatType();
                break;
            case TypeKind.Int:
                nodeType = ChelaType.GetIntType();
                break;
            case TypeKind.UInt:
                nodeType = ChelaType.GetUIntType();
                break;
            case TypeKind.Long:
                nodeType = ChelaType.GetLongType();
                break;
            case TypeKind.ULong:
                nodeType = ChelaType.GetULongType();
                break;
            case TypeKind.Short:
                nodeType = ChelaType.GetShortType();
                break;
            case TypeKind.UShort:
                nodeType = ChelaType.GetUShortType();
                break;
            case TypeKind.String:
                nodeType = ChelaType.GetStringType();
                break;
            case TypeKind.Object:
                nodeType = ChelaType.GetObjectType();
                break;
            case TypeKind.Size:
                nodeType = ChelaType.GetSizeType();
                break;
            case TypeKind.PtrDiff:
                nodeType = ChelaType.GetPtrDiffType();
                break;
            case TypeKind.Other:
                nodeType = node.GetOtherType();
                break;
            case TypeKind.Reference:
                nodeType = ReferenceType.Create(currentModule.TypeMap(node.GetOtherType()));
                break;
            default:
                throw new System.NotSupportedException();
            }

            // Vectorial type check.
            if(node.GetNumComponents() > 1)
            {
                if(!nodeType.IsPrimitive())
                    Error(node, "invalid vectorial type.");
                nodeType = VectorType.Create(nodeType, node.GetNumComponents());
            }
            else if(node.GetNumRows() > 1 || node.GetNumColumns() > 1)
            {
                if(!nodeType.IsPrimitive())
                    Error(node, "invalid matrix type.");
                nodeType = MatrixType.Create(nodeType, node.GetNumRows(), node.GetNumColumns());
            }

            // Set the node type.
            node.SetNodeType(MetaType.Create(currentModule.TypeMap(nodeType)));

            return node;
        }