public virtual void ShouldDecodeFalse()
        {
            var boolType = new BoolType();
            var result   = boolType.Decode <bool>("0000000000000000000000000000000000000000000000000000000000000000");

            Assert.Equal(false, result);
        }
예제 #2
0
            public override void addKnownField(string name, StringType @string, Annotation annotation)
            {
                switch (name)
                {
                case "age":
                    unchecked { new f4(V64.get(), this); }
                    return;

                case "name":
                    unchecked { new f5(@string, this); }
                    return;

                case "seen":
                    unchecked { new f6(BoolType.get(), this); }
                    return;

                case "someintegersinalist":
                    unchecked { new f7(new ListType <int>(I32.get()), this); }
                    return;

                case "somemap":
                    unchecked { new f8(new MapType <string, string>(@string, @string), this); }
                    return;

                case "somereference":
                    unchecked { new f9(([email protected])(((SkillState)Owner).NoSerializedDatas()), this); }
                    return;
                }
            }
        public virtual void ShouldEncodeTrue()
        {
            var boolType = new BoolType();
            var result   = boolType.Encode(true).ToHex();

            Assert.Equal("0000000000000000000000000000000000000000000000000000000000000001", result);
        }
        public virtual void ShouldEncodeFalse()
        {
            var boolType = new BoolType();
            var result   = boolType.Encode(false).ToHex();

            Assert.Equal("0000000000000000000000000000000000000000000000000000000000000000", result);
        }
예제 #5
0
        public UIElement Visit(BoolType type)
        {
            CheckBox cbIO = new CheckBox();

            cbIO.IsChecked = false;
            return(cbIO);
        }
        public virtual void ShouldDecodeTrue()
        {
            var boolType = new BoolType();
            var result   = boolType.Decode <bool>("0000000000000000000000000000000000000000000000000000000000000001");

            Assert.Equal(true, result);
        }
예제 #7
0
        /// <summary>
        ///     Checks the statement for semantical errors
        /// </summary>
        public override void CheckStatement()
        {
            if (ListExpression != null)
            {
                if (ListExpression.Ref is Parameter)
                {
                    Root.AddError("Cannot change the list value which is a parameter (" + ListExpression + ")");
                }

                Collection targetListType = ListExpression.GetExpressionType() as Collection;
                if (targetListType != null)
                {
                    if (Condition != null)
                    {
                        Condition.CheckExpression();
                        BoolType conditionType = Condition.GetExpressionType() as BoolType;
                        if (conditionType == null)
                        {
                            Root.AddError("Condition does not evaluates to boolean");
                        }
                    }
                }
                else
                {
                    Root.AddError("Cannot determine type of " + ListExpression);
                }
            }
            else
            {
                Root.AddError("List should be specified");
            }
        }
        private IExpressionData getVariable(IObject Data)
        {
            IExpressionData expressionData = null;

            if (Data is VariableData)
            {
                VariableData data = (VariableData)Data;
                if (typeof(Double) == data.type)
                {
                    expressionData = new DoubleType((double)data.value);
                }
                else if (data.type == typeof(String))
                {
                    expressionData = new StringType((string)data.value);
                }
                else if (data.type == typeof(Boolean))
                {
                    expressionData = new BoolType((bool)data.value);
                }
                else
                {
                    throw new Exception("Unknown data type, Expression evaluate");
                }
            }
            else if (Data is ArrayIndex || Data is ArrayObject)
            {
                expressionData = new ObjectType(Data);
            }
            return(expressionData);
        }
예제 #9
0
파일: SpreadSheet.cs 프로젝트: mulova/i18n
 public bool GetBooleanCellValue()
 {
     if (b == BoolType.Null)
     {
         b = BoolTypeEx.Parse(str);
     }
     return(b.IsTrue());
 }
예제 #10
0
 private void executeBranch(Environment env)
 {
     if (BoolType.IsTrue(env.DataStack.Pop()))
     {
         TrueBranchWord.Execute(env);
     }
     else
     {
         FalseBranchWord.Execute(env);
     }
 }
예제 #11
0
        protected override bool BeforeEachCycleAction(Environment env)
        {
            WhileTestWord.Execute(env);

            if (env.IsExitMode)
            {
                return(false);
            }

            return(BoolType.IsTrue(env.DataStack.Pop()));
        }
 /// <summary>
 /// These method is called passing firstOperand a left operand in a binary arithmetical operation.
 /// The second operand is encapsulated as secondOperand, in every instances of the class.
 /// The first Operand is a BoolType so the second must be promotable to an expression where a + or
 /// - made sense with a boolean value.
 /// Implements a double dispatch pattern.
 /// </summary>
 /// <param name="firstOperand">The left operand of the operation is a BoolType.</param>
 /// <returns>A TypeExpression if the operation makes sense, otherwise if showMessages is true, an error is raised</returns>
 public override object Exec(BoolType firstOperand, object arg)
 {
     if (this.binaryOperator.Equals(ArithmeticOperator.Plus) && (bool)this.secondOperand.AcceptOperation(new EquivalentOperation(StringType.Instance), arg))
     {
         return(StringType.Instance);
     }
     if (this.showErrorMessage) //TODO: REvisar ESta SIgnaTURA
     {
         ErrorManager.Instance.NotifyError(new TypePromotionError(firstOperand.FullName, this.secondOperand.FullName, this.binaryOperator.ToString(), this.location));
     }
     return(null);
 }
예제 #13
0
        private void doExit(Environment env)
        {
            if (!ReadsFlag || BoolType.IsTrue(env.DataStack.Pop()))
            {
                if (BeforeAction != null)
                {
                    BeforeAction(env);
                }

                env.ActiveExitWordName = Name;
            }
        }
예제 #14
0
        public void ParseShouldReturnOptionBoolSome(string stringBool, bool expectedBool)
        {
            // Arrange
            var           value    = stringBool;
            Option <bool> expected = Some(expectedBool);

            // Act
            var result = BoolType.Parse(value);

            // Assert
            result.Should().Be(expected);
        }
예제 #15
0
        public void ParseShouldReturnOptionBoolNone()
        {
            // Arrange
            var           value    = "not an logical boolean";
            Option <bool> expected = None;

            // Act
            var result = BoolType.Parse(value);

            // Assert
            result.Should().Be(expected);
        }
예제 #16
0
        public override void OnEnter()
        {
            base.OnEnter();

            var _db = databoxObject.Value as DataboxObject;

            if (useOwnerInstanceID)
            {
                entryID = Owner.gameObject.GetInstanceID().ToString();
            }

            DataboxType _data = null;

            switch (dataType)
            {
            case DataType.Float:
                _data = new FloatType();
                break;

            case DataType.Int:
                _data = new IntType();
                break;

            case DataType.Bool:
                _data = new BoolType();
                break;

            case DataType.String:
                _data = new StringType();
                break;

            case DataType.Color:
                _data = new ColorType();
                break;

            case DataType.Quaternion:
                _data = new QuaternionType();
                break;

            case DataType.Vector2:
                _data = new Vector2Type();
                break;

            case DataType.Vector3:
                _data = new Vector3Type();
                break;
            }

            _db.AddData(tableID, entryID, valueID, _data);

            Finish();
        }
예제 #17
0
            public override void addKnownField(string name, StringType @string, Annotation annotation)
            {
                switch (name)
                {
                case "bool":
                    unchecked { new f0(([email protected])(((SkillState)Owner).ZBooleans()), this); }
                    return;

                case "boolean":
                    unchecked { new f1(BoolType.get(), this); }
                    return;
                }
            }
예제 #18
0
        // -------------------------------------------------------------------------------
        // SetBool
        // -------------------------------------------------------------------------------
        public static bool SetBool(bool original, BoolType boolType)
        {
            if (boolType == BoolType.True)
            {
                return(true);
            }
            else if (boolType == BoolType.False)
            {
                return(false);
            }

            return(original);
        }
예제 #19
0
        /// <summary>
        ///     Checks the statement for semantical errors
        /// </summary>
        public override void CheckStatement()
        {
            if (ListExpression != null)
            {
                if (ListExpression.Ref is Parameter)
                {
                    Root.AddError("Cannot change the list value which is a parameter (" + ListExpression + ")");
                }

                Collection targetListType = ListExpression.GetExpressionType() as Collection;
                if (targetListType != null)
                {
                    Type elementType = Value.GetExpressionType();
                    if (elementType != targetListType.Type)
                    {
                        Root.AddError("Inserted element type does not corresponds to list type");
                    }

                    if (Condition != null)
                    {
                        Condition.CheckExpression();
                        BoolType conditionType = Condition.GetExpressionType() as BoolType;
                        if (conditionType == null)
                        {
                            Root.AddError("Condition does not evaluates to boolean");
                        }
                    }
                    else
                    {
                        Root.AddError("Condition should be provided");
                    }
                }
                else
                {
                    Root.AddError("Cannot determine collection type of " + ListExpression);
                }
            }
            else
            {
                Root.AddError("List should be specified");
            }

            if (Value != null)
            {
                Value.CheckExpression();
            }
            else
            {
                Root.AddError("Value should be specified");
            }
        }
 public override object Exec(BoolType firstOperand, object arg)
 {
     if (relationalOperator == RelationalOperator.Equal || relationalOperator == RelationalOperator.NotEqual)
     {
         if ((int)secondOperand.AcceptOperation(new PromotionLevelOperation(firstOperand), arg) != -1)
         {
             return(BoolType.Instance);
         }
         if (showErrorMessage)
         {
             ErrorManager.Instance.NotifyError(new TypePromotionError(secondOperand.FullName, firstOperand.FullName, location));
             return(null);
         }
     }
     return(ReportError(firstOperand));
 }
예제 #21
0
        public static AtomType Consume(Parser parser)
        {
            AtomType atomType = null;

            switch (parser.LookAhead().Type)
            {
            case TokenInfo.TokenType.BOOL:
                parser.Eat(TokenInfo.TokenType.BOOL);
                atomType = new BoolType();
                break;

            case TokenInfo.TokenType.CHAR:
                parser.Eat(TokenInfo.TokenType.CHAR);
                atomType = new CharType();
                break;

            case TokenInfo.TokenType.DOUBLE:
                parser.Eat(TokenInfo.TokenType.DOUBLE);
                atomType = new DoubleType();
                break;

            case TokenInfo.TokenType.INT:
                parser.Eat(TokenInfo.TokenType.INT);
                atomType = new IntType();
                break;

            case TokenInfo.TokenType.STRING:
                parser.Eat(TokenInfo.TokenType.STRING);
                atomType = new StringType();
                break;

            case TokenInfo.TokenType.VOID:
                parser.Eat(TokenInfo.TokenType.VOID);
                atomType = new VoidType();
                break;

            default:
                break;
            }

            if (atomType == null)
            {
                throw new ParserError(new FailedConsumer(), parser.Cursor);
            }

            return(atomType);
        }
        public override string GenerateForTypicalWrapper(
            ObjectGeneration objGen,
            TypeGeneration typeGen,
            Accessor dataAccessor,
            Accessor packageAccessor)
        {
            BoolType b = typeGen as BoolType;

            if (b.BoolAsMarker == null)
            {
                return($"{dataAccessor}[0] == 1");
            }
            else
            {
                return("true");
            }
        }
예제 #23
0
 public static string BoolToString(bool p_bValue, BoolType p_boolType)
 {
     switch (p_boolType)
     {
         case BoolType.TrueFalse:
             return p_bValue ? "True" : "False";
         case BoolType.YesNo:
             return p_bValue ? "Yes" : "No";
         case BoolType.OnOff:
             return p_bValue ? "On" : "Off";
         case BoolType.IstinaLog:
             return p_bValue ? "Истина" : "Ложь";
         case BoolType.DaNet:
             return p_bValue ? "Да" : "Нет";
     }
     return p_bValue.ToString();
 }
예제 #24
0
    public void MQTTEvent(string payload)
    {
        bool     state    = false;
        BoolType boolType = null;

        // TODO: This should be cleaned up to deal with more complex types
        try
        {
            boolType = JsonUtility.FromJson <BoolType>(payload);
            if (reverseTrigger)
            {
                state = !boolType.value;
            }
            else
            {
                state = boolType.value;
            }
        }
        catch (Exception e)
        {
            Debug.Log("error: " + e);
        }

        //If gameobject has a light component, match state
        if (this.GetComponent <Light>())
        {
            this.GetComponent <Light>().enabled = state;
        }
        // Do the same for any child light entities if they exist
        for (int i = 0; i < this.transform.childCount; i++)
        {
            if (this.transform.GetChild(i).gameObject.GetComponent <Light>())
            {
                this.transform.GetChild(i).gameObject.GetComponent <Light>().enabled = state;
            }
        }
        // If an triggerAnimation is provided, activate it
        if (triggerAnimation != "")
        {
            AnimateObject(triggerAnimationAnimation, state);
        }
    }
        public override async Task GenerateCopyIn(
            FileGeneration fg,
            ObjectGeneration objGen,
            TypeGeneration typeGen,
            Accessor frameAccessor,
            Accessor itemAccessor,
            Accessor errorMaskAccessor,
            Accessor translationMaskAccessor)
        {
            BoolType b = typeGen as BoolType;

            if (b.BoolAsMarker == null)
            {
                await base.GenerateCopyIn(fg, objGen, typeGen, frameAccessor, itemAccessor, errorMaskAccessor, translationMaskAccessor);
            }
            else
            {
                fg.AppendLine($"{itemAccessor} = true;");
            }
        }
        /// <summary>
        /// Tipos básicos não possuem transformações especiais.
        /// </summary>
        /// <param name="valueTypes"></param>
        /// <returns></returns>
        private static TypeBase GetTypeFromValue(TypeRef valueTypes)
        {
            if (valueTypes == null)
            {
                return(null);
            }

            switch (valueTypes.AsString().ToLower())
            {
            case "byte[]":
            case "string":
                return(StringType.Create());

            case "int":
                return(IntegerType.Create());

            case "int?":
                return(IntegerType.CreateNullable());

            case "datetime":
                return(DateType.Create());

            case "datetime?":
                return(DateType.CreateNullable());

            case "long":
                return(LongType.Create());

            case "long?":
                return(LongType.CreateNullable());

            case "bool":
                return(BoolType.Create());

            case "bool?":
                return(BoolType.CreateNullable());

            default:
                throw new ArgumentOutOfRangeException("valueTypes", "Não foi possível determinar o tipo da propriedade!");
            }
        }
        public override async Task GenerateWrite(
            FileGeneration fg,
            ObjectGeneration objGen,
            TypeGeneration typeGen,
            Accessor writerAccessor,
            Accessor itemAccessor,
            Accessor errorMaskAccessor,
            Accessor translationMaskAccessor,
            Accessor converterAccessor)
        {
            BoolType b = typeGen as BoolType;

            if (b.BoolAsMarker == null)
            {
                await base.GenerateWrite(
                    fg,
                    objGen,
                    typeGen,
                    writerAccessor,
                    itemAccessor,
                    errorMaskAccessor,
                    translationMaskAccessor,
                    converterAccessor);
            }
            else
            {
                var data = typeGen.GetFieldData();
                using (var args = new ArgsWrapper(fg,
                                                  $"{this.NamespacePrefix}{GetTranslatorInstance(typeGen, getter: true)}.WriteAsMarker"))
                {
                    args.Add($"writer: {writerAccessor}");
                    args.Add($"item: {ItemWriteAccess(typeGen, itemAccessor)}");
                    if (data.RecordType.HasValue &&
                        data.HandleTrigger)
                    {
                        args.Add($"header: recordTypeConverter.ConvertToCustom({objGen.RecordTypeHeaderName(data.RecordType.Value)})");
                    }
                }
            }
        }
 public BooleanBinaryTranslationGeneration()
     : base(expectedLen: 1)
 {
     this.AdditionalCopyInParams.Add((o, t) =>
     {
         BoolType b = t as BoolType;
         if (b.ByteLength != 1)
         {
             return(TryGet <string> .Succeed($"byteLength: {b.ByteLength}"));
         }
         return(TryGet <string> .Failure);
     });
     this.AdditionalWriteParams.Add((o, t) =>
     {
         BoolType b = t as BoolType;
         if (b.ByteLength != 1)
         {
             return(TryGet <string> .Succeed($"byteLength: {b.ByteLength}"));
         }
         return(TryGet <string> .Failure);
     });
 }
예제 #29
0
 public bool IsModified()
 {
     if (modified == BoolType.Null)
     {
         FileInfo file     = new FileInfo(fullPath);
         FileInfo metafile = new FileInfo(fullPath + ".meta");
         if (metafile.Exists)
         {
             string newMetaHash = GetMetaDigest(metafile);
             modified = modified.Or(metaHash != newMetaHash);
             metaHash = newMetaHash;
         }
         else
         {
             metaHash = string.Empty;
         }
         if (!modified.IsTrue() && timestamp == file.LastWriteTimeUtc.Ticks)
         {                 // fast check
             modified = BoolType.False;
         }
         else
         {
             timestamp = file.LastWriteTimeUtc.Ticks;
             using (var s = file.Open(FileMode.Open, FileAccess.Read))
             {
                 string newAssetHash = s.ComputeHash();
                 modified  = modified.Or(assetHash != newAssetHash);
                 assetHash = newAssetHash;
             }
         }
     }
     if (modified.IsTrue())
     {
         version++;
     }
     return(modified.IsTrue());
 }
        /// <summary>
        /// Returns a value that indicates a promotion level.
        /// </summary>
        /// <param name="firstOperand">WriteType to promotion.</param>
        /// <returns>Returns a promotion value.</returns>
        public override object Exec(BoolType firstOperand, object arg)
        {
            // * Bool type and type variable
            if (TypeExpression.As <BoolType>(this.secondOperand) != null)
            {
                return(0);
            }

            // * WriteType variable
            TypeVariable typeVariable = this.secondOperand as TypeVariable;

            if (typeVariable != null && typeVariable.Substitution == null)
            {
                // * A free variable is complete promotion
                return(0);
            }

            // * Union type
            UnionType unionType = TypeExpression.As <UnionType>(this.secondOperand);

            if (unionType != null)
            {
                return(unionType.SuperType(firstOperand));
            }

            // * Field type and bounded type variable
            FieldType fieldType = TypeExpression.As <FieldType>(this.secondOperand);

            if (fieldType != null)
            {
                return(firstOperand.AcceptOperation(new PromotionLevelOperation(fieldType.FieldTypeExpression), arg));
            }

            // * Use the BCL object oriented approach
            return(firstOperand.AsClassType().AcceptOperation(this, arg));
        }
예제 #31
0
        void FunctionDecl(DeclModifierData dmod, bool isWithinAbstractModule, out Function/*!*/ f)
        {
            Contract.Ensures(Contract.ValueAtReturn(out f)!=null);
            Attributes attrs = null;
            IToken/*!*/ id = Token.NoToken;  // to please compiler
            List<TypeParameter/*!*/> typeArgs = new List<TypeParameter/*!*/>();
            List<Formal/*!*/> formals = new List<Formal/*!*/>();
            Type/*!*/ returnType = new BoolType();
            List<Expression/*!*/> reqs = new List<Expression/*!*/>();
            List<Expression/*!*/> ens = new List<Expression/*!*/>();
            List<FrameExpression/*!*/> reads = new List<FrameExpression/*!*/>();
            List<Expression/*!*/> decreases;
            Expression body = null;
            bool isPredicate = false; bool isIndPredicate = false; bool isCoPredicate = false;
            bool isFunctionMethod = false;
            IToken bodyStart = Token.NoToken;
            IToken bodyEnd = Token.NoToken;
            IToken signatureEllipsis = null;
            bool missingOpenParen;
            bool isTwoState = false;

            if (la.kind == 44) {
            Get();
            isTwoState = true;
            }
            if (la.kind == 41) {
            Get();
            if (la.kind == 90) {
                Get();
                if (isTwoState) { SemErr(t, "twostate functions are supported only as a ghosts, not as function methods"); }
                else { isFunctionMethod = true; }

            }
            AllowedDeclModifiers allowed = AllowedDeclModifiers.AlreadyGhost | AllowedDeclModifiers.Static;
            if (!isTwoState) { allowed |= AllowedDeclModifiers.Protected; }
            string caption = "Functions";
            if (isFunctionMethod) {
             allowed |= AllowedDeclModifiers.Extern;
             caption = "Function methods";
            }
            CheckDeclModifiers(dmod, caption, allowed);

            while (la.kind == 50) {
                Attribute(ref attrs);
            }
            NoUSIdent(out id);
            if (la.kind == 54 || la.kind == 56) {
                if (la.kind == 56) {
                    GenericParameters(typeArgs);
                }
                Formals(true, isFunctionMethod, isTwoState, formals);
                Expect(22);
                Type(out returnType);
            } else if (la.kind == 63) {
                Get();
                signatureEllipsis = t;
            } else SynErr(171);
            } else if (la.kind == 42) {
            Get();
            isPredicate = true;
            if (la.kind == 90) {
                Get();
                if (isTwoState) { SemErr(t, "twostate predicates are supported only as a ghosts, not as predicate methods"); }
                else { isFunctionMethod = true; }

            }
            AllowedDeclModifiers allowed = AllowedDeclModifiers.AlreadyGhost | AllowedDeclModifiers.Static;
            if (!isTwoState) { allowed |= AllowedDeclModifiers.Protected; }
            string caption = "Predicates";
            if (isFunctionMethod) {
             allowed |= AllowedDeclModifiers.Extern;
             caption = "Predicate methods";
            }
            CheckDeclModifiers(dmod, caption, allowed);

            while (la.kind == 50) {
                Attribute(ref attrs);
            }
            NoUSIdent(out id);
            if (StartOf(11)) {
                if (la.kind == 56) {
                    GenericParameters(typeArgs);
                }
                missingOpenParen = true;
                if (la.kind == 54) {
                    Formals(true, isFunctionMethod, isTwoState, formals);
                    missingOpenParen = false;
                }
                if (missingOpenParen) { errors.Warning(t, "with the new support of higher-order functions in Dafny, parentheses-less predicates are no longer supported; in the new syntax, parentheses are required for the declaration and uses of predicates, even if the predicate takes no additional arguments"); }
                if (la.kind == 22) {
                    Get();
                    SemErr(t, "predicates do not have an explicitly declared return type; it is always bool");
                }
            } else if (la.kind == 63) {
                Get();
                signatureEllipsis = t;
            } else SynErr(172);
            } else if (la.kind == 43) {
            Contract.Assert(!isTwoState);  // the IsFunctionDecl check checks that "twostate" is not followed by "inductive"

            Get();
            Expect(42);
            isIndPredicate = true;
            CheckDeclModifiers(dmod, "Inductive predicates",
             AllowedDeclModifiers.AlreadyGhost | AllowedDeclModifiers.Static | AllowedDeclModifiers.Protected);

            while (la.kind == 50) {
                Attribute(ref attrs);
            }
            NoUSIdent(out id);
            if (la.kind == 54 || la.kind == 56) {
                if (la.kind == 56) {
                    GenericParameters(typeArgs);
                }
                Formals(true, isFunctionMethod, false, formals);
                if (la.kind == 22) {
                    Get();
                    SemErr(t, "inductive predicates do not have an explicitly declared return type; it is always bool");
                }
            } else if (la.kind == 63) {
                Get();
                signatureEllipsis = t;
            } else SynErr(173);
            } else if (la.kind == 46) {
            Contract.Assert(!isTwoState);  // the IsFunctionDecl check checks that "twostate" is not followed by "copredicate"

            Get();
            isCoPredicate = true;
            CheckDeclModifiers(dmod, "Copredicates",
             AllowedDeclModifiers.AlreadyGhost | AllowedDeclModifiers.Static | AllowedDeclModifiers.Protected);

            while (la.kind == 50) {
                Attribute(ref attrs);
            }
            NoUSIdent(out id);
            if (la.kind == 54 || la.kind == 56) {
                if (la.kind == 56) {
                    GenericParameters(typeArgs);
                }
                Formals(true, isFunctionMethod, false, formals);
                if (la.kind == 22) {
                    Get();
                    SemErr(t, "copredicates do not have an explicitly declared return type; it is always bool");
                }
            } else if (la.kind == 63) {
                Get();
                signatureEllipsis = t;
            } else SynErr(174);
            } else SynErr(175);
            decreases = isIndPredicate || isCoPredicate ? null : new List<Expression/*!*/>();
            while (StartOf(12)) {
            FunctionSpec(reqs, reads, ens, decreases);
            }
            if (la.kind == 50) {
            FunctionBody(out body, out bodyStart, out bodyEnd);
            }
            if (!isWithinAbstractModule && DafnyOptions.O.DisallowSoundnessCheating && body == null && ens.Count > 0 &&
               !Attributes.Contains(attrs, "axiom") && !Attributes.Contains(attrs, "imported")) {
              SemErr(t, "a function with an ensures clause must have a body, unless given the :axiom attribute");
            }
            EncodeExternAsAttribute(dmod, ref attrs, id, /* needAxiom */ true);
            IToken tok = theVerifyThisFile ? id : new IncludeToken(id);
            if (isTwoState && isPredicate) {
              f = new TwoStatePredicate(tok, id.val, dmod.IsStatic, typeArgs, formals,
                                    reqs, reads, ens, new Specification<Expression>(decreases, null), body, attrs, signatureEllipsis);
            } else if (isTwoState) {
              f = new TwoStateFunction(tok, id.val, dmod.IsStatic, typeArgs, formals, returnType,
                                   reqs, reads, ens, new Specification<Expression>(decreases, null), body, attrs, signatureEllipsis);
            } else if (isPredicate) {
              f = new Predicate(tok, id.val, dmod.IsStatic, dmod.IsProtected, !isFunctionMethod, typeArgs, formals,
                            reqs, reads, ens, new Specification<Expression>(decreases, null), body, Predicate.BodyOriginKind.OriginalOrInherited, attrs, signatureEllipsis);
            } else if (isIndPredicate) {
              f = new InductivePredicate(tok, id.val, dmod.IsStatic, dmod.IsProtected, typeArgs, formals,
                                     reqs, reads, ens, body, attrs, signatureEllipsis);
            } else if (isCoPredicate) {
              f = new CoPredicate(tok, id.val, dmod.IsStatic, dmod.IsProtected, typeArgs, formals,
                              reqs, reads, ens, body, attrs, signatureEllipsis);
            } else {
              f = new Function(tok, id.val, dmod.IsStatic, dmod.IsProtected, !isFunctionMethod, typeArgs, formals, returnType,
                           reqs, reads, ens, new Specification<Expression>(decreases, null), body, attrs, signatureEllipsis);
            }
            f.BodyStartTok = bodyStart;
            f.BodyEndTok = bodyEnd;
            theBuiltIns.CreateArrowTypeDecl(formals.Count);
            if (isIndPredicate || isCoPredicate) {
             // also create an arrow type for the corresponding prefix predicate
             theBuiltIns.CreateArrowTypeDecl(formals.Count + 1);
            }
        }
예제 #32
0
 public IValue Visit(BoolType boolType)
 {
     return(null);
 }
예제 #33
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);

            }
        }
예제 #34
0
 public virtual void ShouldDecodeFalse()
 {
     var boolType = new BoolType();
     var result = boolType.Decode<bool>("0000000000000000000000000000000000000000000000000000000000000000");
     Assert.Equal(false, result);
 }
예제 #35
0
 public virtual void ShouldEncodeFalse()
 {
     var boolType = new BoolType();
     var result = boolType.Encode(false).ToHex();
     Assert.Equal("0000000000000000000000000000000000000000000000000000000000000000", result);
 }
예제 #36
0
 public virtual void ShouldDecodeTrue()
 {
     var boolType = new BoolType();
     var result = boolType.Decode<bool>("0000000000000000000000000000000000000000000000000000000000000001");
     Assert.Equal(true, result);
 }
예제 #37
0
 public virtual void ShouldEncodeTrue()
 {
     var boolType = new BoolType();
     var result = boolType.Encode(true).ToHex();
     Assert.Equal("0000000000000000000000000000000000000000000000000000000000000001", result);
 }
예제 #38
0
파일: Parser.cs 프로젝트: dbremner/dafny
        void FunctionDecl(MemberModifiers mmod, bool isWithinAbstractModule, out Function/*!*/ f)
        {
            Contract.Ensures(Contract.ValueAtReturn(out f)!=null);
            Attributes attrs = null;
            IToken/*!*/ id = Token.NoToken;  // to please compiler
            List<TypeParameter/*!*/> typeArgs = new List<TypeParameter/*!*/>();
            List<Formal/*!*/> formals = new List<Formal/*!*/>();
            Type/*!*/ returnType = new BoolType();
            List<Expression/*!*/> reqs = new List<Expression/*!*/>();
            List<Expression/*!*/> ens = new List<Expression/*!*/>();
            List<FrameExpression/*!*/> reads = new List<FrameExpression/*!*/>();
            List<Expression/*!*/> decreases;
            Expression body = null;
            bool isPredicate = false; bool isIndPredicate = false; bool isCoPredicate = false;
            bool isFunctionMethod = false;
            IToken bodyStart = Token.NoToken;
            IToken bodyEnd = Token.NoToken;
            IToken signatureEllipsis = null;
            bool missingOpenParen;

            if (la.kind == 38) {
            Get();
            if (la.kind == 84) {
                Get();
                isFunctionMethod = true;
            }
            if (mmod.IsGhost) { SemErr(t, "functions cannot be declared 'ghost' (they are ghost by default)"); }

            while (la.kind == 46) {
                Attribute(ref attrs);
            }
            NoUSIdent(out id);
            if (la.kind == 50 || la.kind == 52) {
                if (la.kind == 52) {
                    GenericParameters(typeArgs);
                }
                Formals(true, isFunctionMethod, formals);
                Expect(21);
                Type(out returnType);
            } else if (la.kind == 59) {
                Get();
                signatureEllipsis = t;
            } else SynErr(153);
            } else if (la.kind == 39) {
            Get();
            isPredicate = true;
            if (la.kind == 84) {
                Get();
                isFunctionMethod = true;
            }
            if (mmod.IsGhost) { SemErr(t, "predicates cannot be declared 'ghost' (they are ghost by default)"); }

            while (la.kind == 46) {
                Attribute(ref attrs);
            }
            NoUSIdent(out id);
            if (StartOf(8)) {
                if (la.kind == 52) {
                    GenericParameters(typeArgs);
                }
                missingOpenParen = true;
                if (la.kind == 50) {
                    Formals(true, isFunctionMethod, formals);
                    missingOpenParen = false;
                }
                if (missingOpenParen) { errors.Warning(t, "with the new support of higher-order functions in Dafny, parentheses-less predicates are no longer supported; in the new syntax, parentheses are required for the declaration and uses of predicates, even if the predicate takes no additional arguments"); }
                if (la.kind == 21) {
                    Get();
                    SemErr(t, "predicates do not have an explicitly declared return type; it is always bool");
                }
            } else if (la.kind == 59) {
                Get();
                signatureEllipsis = t;
            } else SynErr(154);
            } else if (la.kind == 40) {
            Get();
            Expect(39);
            isIndPredicate = true;
            if (mmod.IsGhost) { SemErr(t, "inductive predicates cannot be declared 'ghost' (they are ghost by default)"); }

            while (la.kind == 46) {
                Attribute(ref attrs);
            }
            NoUSIdent(out id);
            if (la.kind == 50 || la.kind == 52) {
                if (la.kind == 52) {
                    GenericParameters(typeArgs);
                }
                Formals(true, isFunctionMethod, formals);
                if (la.kind == 21) {
                    Get();
                    SemErr(t, "inductive predicates do not have an explicitly declared return type; it is always bool");
                }
            } else if (la.kind == 59) {
                Get();
                signatureEllipsis = t;
            } else SynErr(155);
            } else if (la.kind == 42) {
            Get();
            isCoPredicate = true;
            if (mmod.IsGhost) { SemErr(t, "copredicates cannot be declared 'ghost' (they are ghost by default)"); }

            while (la.kind == 46) {
                Attribute(ref attrs);
            }
            NoUSIdent(out id);
            if (la.kind == 50 || la.kind == 52) {
                if (la.kind == 52) {
                    GenericParameters(typeArgs);
                }
                Formals(true, isFunctionMethod, formals);
                if (la.kind == 21) {
                    Get();
                    SemErr(t, "copredicates do not have an explicitly declared return type; it is always bool");
                }
            } else if (la.kind == 59) {
                Get();
                signatureEllipsis = t;
            } else SynErr(156);
            } else SynErr(157);
            decreases = isIndPredicate || isCoPredicate ? null : new List<Expression/*!*/>();
            while (StartOf(9)) {
            FunctionSpec(reqs, reads, ens, decreases);
            }
            if (la.kind == 46) {
            FunctionBody(out body, out bodyStart, out bodyEnd);
            }
            if (!isWithinAbstractModule && DafnyOptions.O.DisallowSoundnessCheating && body == null && ens.Count > 0 && !Attributes.Contains(attrs, "axiom") && !Attributes.Contains(attrs, "imported")) {
              SemErr(t, "a function with an ensures clause must have a body, unless given the :axiom attribute");
            }

            IToken tok = theVerifyThisFile ? id : new IncludeToken(id);
            if (isPredicate) {
              f = new Predicate(tok, id.val, mmod.IsStatic, mmod.IsProtected, !isFunctionMethod, typeArgs, formals,
                            reqs, reads, ens, new Specification<Expression>(decreases, null), body, Predicate.BodyOriginKind.OriginalOrInherited, attrs, signatureEllipsis);
            } else if (isIndPredicate) {
              f = new InductivePredicate(tok, id.val, mmod.IsStatic, mmod.IsProtected, typeArgs, formals,
                                     reqs, reads, ens, body, attrs, signatureEllipsis);
            } else if (isCoPredicate) {
              f = new CoPredicate(tok, id.val, mmod.IsStatic, mmod.IsProtected, typeArgs, formals,
                              reqs, reads, ens, body, attrs, signatureEllipsis);
            } else {
              f = new Function(tok, id.val, mmod.IsStatic, mmod.IsProtected, !isFunctionMethod, typeArgs, formals, returnType,
                           reqs, reads, ens, new Specification<Expression>(decreases, null), body, attrs, signatureEllipsis);
            }
            f.BodyStartTok = bodyStart;
            f.BodyEndTok = bodyEnd;
            theBuiltIns.CreateArrowTypeDecl(formals.Count);
            if (isIndPredicate || isCoPredicate) {
             // also create an arrow type for the corresponding prefix predicate
             theBuiltIns.CreateArrowTypeDecl(formals.Count + 1);
            }
        }
예제 #39
0
파일: Parser.cs 프로젝트: dbremner/dafny
        void TypeIdentOptional(out IToken/*!*/ id, out string/*!*/ identName, out Type/*!*/ ty, out bool isGhost)
        {
            Contract.Ensures(Contract.ValueAtReturn(out id)!=null);
            Contract.Ensures(Contract.ValueAtReturn(out ty)!=null);
            Contract.Ensures(Contract.ValueAtReturn(out identName)!=null);
            string name = null; id = Token.NoToken; ty = new BoolType()/*dummy*/; isGhost = false;
            if (la.kind == 73) {
            Get();
            isGhost = true;
            }
            if (StartOf(3)) {
            TypeAndToken(out id, out ty);
            if (la.kind == 21) {
                Get();
                UserDefinedType udt = ty as UserDefinedType;
                if (udt != null && udt.TypeArgs.Count == 0) {
                 name = udt.Name;
                } else {
                 SemErr(id, "invalid formal-parameter name in datatype constructor");
                }

                Type(out ty);
            }
            } else if (la.kind == 2) {
            Get();
            id = t; name = id.val;
            Expect(21);
            Type(out ty);
            } else SynErr(163);
            if (name != null) {
             identName = name;
            } else {
             identName = "#" + anonymousIds++;
            }
        }
예제 #40
0
파일: Parser.cs 프로젝트: dbremner/dafny
        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);

            }
        }