Пример #1
0
        public virtual SqlFragment GetMultiSetOperator(MultiSetType type)
        {
            switch (type)
            {
            case MultiSetType.Union: return(SqlTermUnion);

            case MultiSetType.UnionAll: return(SqlTermUnionAll);

            case MultiSetType.Except: return(SqlTermExcept);

            case MultiSetType.Intersect: return(SqlTermIntersect);

            default:
                Util.Throw($"Invalid MultiSetType value: {type}");
                return(null);
            }
        }
Пример #2
0
        void TypeAndToken(out IToken tok, out Type ty)
        {
            Contract.Ensures(Contract.ValueAtReturn(out tok)!=null); Contract.Ensures(Contract.ValueAtReturn(out ty) != null);
            tok = Token.NoToken;  ty = new BoolType();  /*keep compiler happy*/
            List<Type> gt; List<Type> tupleArgTypes = null;

            switch (la.kind) {
            case 6: {
            Get();
            tok = t;
            break;
            }
            case 7: {
            Get();
            tok = t;  ty = new CharType();
            break;
            }
            case 9: {
            Get();
            tok = t;  ty = new NatType();
            break;
            }
            case 8: {
            Get();
            tok = t;  ty = new IntType();
            break;
            }
            case 10: {
            Get();
            tok = t;  ty = new RealType();
            break;
            }
            case 11: {
            Get();
            tok = t;  ty = new ObjectType();
            break;
            }
            case 13: {
            Get();
            tok = t;  gt = new List<Type>();
            if (la.kind == 52) {
                GenericInstantiation(gt);
            }
            if (gt.Count > 1) {
             SemErr("set type expects only one type argument");
            }
            ty = new SetType(true, gt.Count == 1 ? gt[0] : null);

            break;
            }
            case 14: {
            Get();
            tok = t;  gt = new List<Type>();
            if (la.kind == 52) {
                GenericInstantiation(gt);
            }
            if (gt.Count > 1) {
             SemErr("set type expects only one type argument");
            }
            ty = new SetType(false, gt.Count == 1 ? gt[0] : null);

            break;
            }
            case 15: {
            Get();
            tok = t;  gt = new List<Type>();
            if (la.kind == 52) {
                GenericInstantiation(gt);
            }
            if (gt.Count > 1) {
             SemErr("multiset type expects only one type argument");
            }
            ty = new MultiSetType(gt.Count == 1 ? gt[0] : null);

            break;
            }
            case 16: {
            Get();
            tok = t;  gt = new List<Type>();
            if (la.kind == 52) {
                GenericInstantiation(gt);
            }
            if (gt.Count > 1) {
             SemErr("seq type expects only one type argument");
            }
            ty = new SeqType(gt.Count == 1 ? gt[0] : null);

            break;
            }
            case 12: {
            Get();
            tok = t;  ty = new UserDefinedType(tok, tok.val, null);
            break;
            }
            case 17: {
            Get();
            tok = t;  gt = new List<Type>();
            if (la.kind == 52) {
                GenericInstantiation(gt);
            }
            if (gt.Count == 0) {
             ty = new MapType(true, null, null);
            } else if (gt.Count != 2) {
             SemErr("map type expects two type arguments");
             ty = new MapType(true, gt[0], gt.Count == 1 ? new InferredTypeProxy() : gt[1]);
            } else {
             ty = new MapType(true, gt[0], gt[1]);
            }

            break;
            }
            case 18: {
            Get();
            tok = t;  gt = new List<Type>();
            if (la.kind == 52) {
                GenericInstantiation(gt);
            }
            if (gt.Count == 0) {
             ty = new MapType(false, null, null);
            } else if (gt.Count != 2) {
             SemErr("imap type expects two type arguments");
             ty = new MapType(false, gt[0], gt.Count == 1 ? new InferredTypeProxy() : gt[1]);
            } else {
             ty = new MapType(false, gt[0], gt[1]);
            }

            break;
            }
            case 5: {
            Get();
            tok = t;  gt = null;
            if (la.kind == 52) {
                gt = new List<Type>();
                GenericInstantiation(gt);
            }
            int dims = tok.val.Length == 5 ? 1 : int.Parse(tok.val.Substring(5));
            ty = theBuiltIns.ArrayType(tok, dims, gt, true);

            break;
            }
            case 50: {
            Get();
            tok = t; tupleArgTypes = new List<Type>();
            if (StartOf(3)) {
                Type(out ty);
                tupleArgTypes.Add(ty);
                while (la.kind == 22) {
                    Get();
                    Type(out ty);
                    tupleArgTypes.Add(ty);
                }
            }
            Expect(51);
            if (tupleArgTypes.Count == 1) {
             // just return the type 'ty'
            } else {
             var dims = tupleArgTypes.Count;
             var tmp = theBuiltIns.TupleType(tok, dims, true);  // make sure the tuple type exists
             ty = new UserDefinedType(tok, BuiltIns.TupleTypeName(dims), dims == 0 ? null : tupleArgTypes);
            }

            break;
            }
            case 1: {
            Expression e; tok = t;
            NameSegmentForTypeName(out e);
            tok = t;
            while (la.kind == 27) {
                Get();
                Expect(1);
                tok = t; List<Type> typeArgs = null;
                if (la.kind == 52) {
                    typeArgs = new List<Type>();
                    GenericInstantiation(typeArgs);
                }
                e = new ExprDotName(tok, e, tok.val, typeArgs);
            }
            ty = new UserDefinedType(e.tok, e);
            break;
            }
            default: SynErr(164); break;
            }
            if (la.kind == 30) {
            Type t2;
            Get();
            tok = t;
            Type(out t2);
            if (tupleArgTypes != null) {
             gt = tupleArgTypes;
            } else {
             gt = new List<Type>{ ty };
            }
            ty = new ArrowType(tok, gt, t2);
            theBuiltIns.CreateArrowTypeDecl(gt.Count);

            }
        }
Пример #3
0
        void TypeAndToken(out IToken tok, out Type ty, bool inExpressionContext)
        {
            Contract.Ensures(Contract.ValueAtReturn(out tok)!=null); Contract.Ensures(Contract.ValueAtReturn(out ty) != null);
            tok = Token.NoToken;  ty = new BoolType();  /*keep compiler happy*/
            List<Type> gt; List<Type> tupleArgTypes = null;

            switch (la.kind) {
            case 7: {
            Get();
            tok = t;
            break;
            }
            case 8: {
            Get();
            tok = t;  ty = new CharType();
            break;
            }
            case 9: {
            Get();
            tok = t;  ty = new IntType();
            break;
            }
            case 10: {
            Get();
            tok = t;  ty = new UserDefinedType(tok, tok.val, null);
            break;
            }
            case 11: {
            Get();
            tok = t;  ty = new RealType();
            break;
            }
            case 6: {
            Get();
            tok = t;
            int w = StringToInt(tok.val.Substring(2), 0, "bitvectors that wide");
            ty = new BitvectorType(w);

            break;
            }
            case 12: {
            Get();
            tok = t;  ty = new ObjectType();
            break;
            }
            case 14: {
            Get();
            tok = t;
            OptGenericInstantiation(out gt, inExpressionContext);
            if (gt != null && gt.Count > 1) {
             SemErr("set type expects only one type argument");
            }
            ty = new SetType(true, gt != null ?gt[0] : null);

            break;
            }
            case 15: {
            Get();
            tok = t;
            OptGenericInstantiation(out gt, inExpressionContext);
            if (gt != null && gt.Count > 1) {
             SemErr("set type expects only one type argument");
            }
            ty = new SetType(false, gt != null ? gt[0] : null);

            break;
            }
            case 16: {
            Get();
            tok = t;
            OptGenericInstantiation(out gt, inExpressionContext);
            if (gt != null && gt.Count > 1) {
             SemErr("multiset type expects only one type argument");
            }
            ty = new MultiSetType(gt != null ? gt[0] : null);

            break;
            }
            case 17: {
            Get();
            tok = t;
            OptGenericInstantiation(out gt, inExpressionContext);
            if (gt != null && gt.Count > 1) {
             SemErr("seq type expects only one type argument");
            }
            ty = new SeqType(gt != null ? gt[0] : null);

            break;
            }
            case 13: {
            Get();
            tok = t;  ty = new UserDefinedType(tok, tok.val, null);
            break;
            }
            case 18: {
            Get();
            tok = t;
            OptGenericInstantiation(out gt, inExpressionContext);
            if (gt == null) {
             ty = new MapType(true, null, null);
            } else if (gt.Count != 2) {
             SemErr("map type expects two type arguments");
             ty = new MapType(true, gt[0], gt.Count == 1 ? new InferredTypeProxy() : gt[1]);
            } else {
             ty = new MapType(true, gt[0], gt[1]);
            }

            break;
            }
            case 19: {
            Get();
            tok = t;
            OptGenericInstantiation(out gt, inExpressionContext);
            if (gt == null) {
             ty = new MapType(false, null, null);
            } else if (gt.Count != 2) {
             SemErr("imap type expects two type arguments");
             ty = new MapType(false, gt[0], gt.Count == 1 ? new InferredTypeProxy() : gt[1]);
            } else {
             ty = new MapType(false, gt[0], gt[1]);
            }

            break;
            }
            case 5: {
            Get();
            tok = t;
            OptGenericInstantiation(out gt, inExpressionContext);
            int dims = StringToInt(tok.val.Substring(5), 1, "arrays of that many dimensions");
            ty = theBuiltIns.ArrayType(tok, dims, gt, true);

            break;
            }
            case 54: {
            Get();
            tok = t; tupleArgTypes = new List<Type>();
            if (StartOf(6)) {
                Type(out ty);
                tupleArgTypes.Add(ty);
                while (la.kind == 23) {
                    Get();
                    Type(out ty);
                    tupleArgTypes.Add(ty);
                }
            }
            Expect(55);
            if (tupleArgTypes.Count == 1) {
             // just return the type 'ty'
            } else {
             var dims = tupleArgTypes.Count;
             var tmp = theBuiltIns.TupleType(tok, dims, true);  // make sure the tuple type exists
             ty = new UserDefinedType(tok, BuiltIns.TupleTypeName(dims), dims == 0 ? null : tupleArgTypes);
            }

            break;
            }
            case 1: {
            Expression e;
            NameSegmentForTypeName(out e, inExpressionContext);
            tok = t;
            while (la.kind == 28) {
                Get();
                Expect(1);
                tok = t; List<Type> typeArgs;
                OptGenericInstantiation(out typeArgs, inExpressionContext);
                e = new ExprDotName(tok, e, tok.val, typeArgs);
            }
            ty = new UserDefinedType(e.tok, e);
            break;
            }
            default: SynErr(182); break;
            }
            if (IsArrow()) {
            Expect(32);
            tok = t; Type t2;
            Type(out t2);
            if (tupleArgTypes != null) {
             gt = tupleArgTypes;
            } else {
             gt = new List<Type>{ ty };
            }
            ty = new ArrowType(tok, gt, t2);
            theBuiltIns.CreateArrowTypeDecl(gt.Count);

            }
        }