public override TranslationResult Translate(TranslationContext context)
        {
            var left = this.Left.Translate(new TranslationContext(context)
            {
                LValueNeeded = true
            });
            var right = this.Right.Translate(context.ChangePurityContext(PurityContext.Purifiable));

            List <Error> errors = CommonUtils.CombineErrors(left, right).ToList();

            StatementsSequenceSilvernode sequence;

            if (left.ArraysContainer != null)
            {
                errors.AddRange(left.ArraysContainer.Errors);
                errors.AddRange(left.ArraysIndex.Errors);
                var arrayWrite = context.Process.ArraysTranslator.ArrayWrite(this.OriginalNode, left.ArraysContainer.Silvernode,
                                                                             left.ArraysIndex.Silvernode, right.Silvernode);
                sequence = new StatementsSequenceSilvernode(null,
                                                            right.PrependTheseSilvernodes.Concat(new[] { arrayWrite }).ToArray());
            }
            else
            {
                var assignment = new AssignmentSilvernode(left.Silvernode, right.Silvernode, this.OriginalNode);
                sequence = new StatementsSequenceSilvernode(null,
                                                            right.PrependTheseSilvernodes.Concat(new[] { assignment }).ToArray());
            }
            return(TranslationResult.FromSilvernode(sequence, errors));
        }
Ejemplo n.º 2
0
        public override TranslationResult Translate(TranslationContext context)
        {
            var expr   = this.Expression.Translate(context.ChangePurityContext(PurityContext.Purifiable));
            var errors = new List <Error>();

            errors.AddRange(expr.Errors);

            if (context.IsFunctionOrPredicateBlock)
            {
                return(TranslationResult.FromSilvernode(expr.Silvernode, errors));
            }

            StatementsSequenceSilvernode statements = new StatementsSequenceSilvernode(this.OriginalNode);

            statements.List.AddRange(expr.PrependTheseSilvernodes);
            statements.List.Add(
                new AssignmentSilvernode(
                    new TextSilvernode(Constants.SilverReturnVariableName, this.OriginalNode),
                    expr.Silvernode, this.OriginalNode
                    ));
            statements.List.Add(
                new GotoSilvernode(Constants.SilverMethodEndLabel, this.OriginalNode)
                );
            return(TranslationResult.FromSilvernode(statements, errors));
        }
Ejemplo n.º 3
0
        public override TranslationResult Translate(TranslationContext context)
        {
            var symbol     = context.Semantics.GetDeclaredSymbol(this.variable);
            var identifier = context.Process.IdentifierTranslator.RegisterAndGetIdentifier(symbol);

            Error                  err;
            List <Error>           errors = new List <Error>();
            VarStatementSilvernode intro  =
                new VarStatementSilvernode(identifier,
                                           TypeTranslator.TranslateType(
                                               context.Semantics.GetSymbolInfo(this.typeSyntax).Symbol as ITypeSymbol, this.typeSyntax,
                                               out err), this.OriginalNode);

            if (err != null)
            {
                errors.Add(err);
            }
            if (this.initialValue == null)
            {
                return(TranslationResult.FromSilvernode(intro, errors));
            }

            // Add assignment if there is an initial value.
            var res = this.initialValue.Translate(context.ChangePurityContext(PurityContext.Purifiable));

            AssignmentSilvernode assignmentSilvernode =
                new AssignmentSilvernode(new IdentifierSilvernode(identifier), res.Silvernode, this.OriginalNode);

            errors.AddRange(res.Errors);
            return(TranslationResult.FromSilvernode(new StatementsSequenceSilvernode(this.OriginalNode,
                                                                                     intro,
                                                                                     new StatementsSequenceSilvernode(null, res.PrependTheseSilvernodes.ToArray()),
                                                                                     assignmentSilvernode), errors));
        }
        public override TranslationResult Translate(TranslationContext context)
        {
            Silvernode sn = null;

            switch (this.kind)
            {
            case LiteralKind.Boolean:
                sn = this.booleanValue ? new TextSilvernode("true", this.OriginalNode) : new TextSilvernode("false", this.OriginalNode);
                break;

            case LiteralKind.Int32:
                sn = new TextSilvernode(this.integerValue.ToString(), this.OriginalNode);
                break;

            case LiteralKind.Null:
                sn = new TextSilvernode("null", this.OriginalNode);
                break;
            }
            if (sn != null)
            {
                return(TranslationResult.FromSilvernode(sn));
            }
            else
            {
                return(TranslationResult.Error(this.OriginalNode, Diagnostics.SSIL101_UnknownNode, this.OriginalNode.Kind()));
            }
        }
Ejemplo n.º 5
0
        public override TranslationResult Translate(TranslationContext context)
        {
            var left = this.Expression.Translate(context);

            return(TranslationResult
                   .FromSilvernode(new PrefixUnaryExpressionSilvernode(this.Operator, left.Silvernode, this.OriginalNode),
                                   left.Errors)
                   .AndPrepend(left.PrependTheseSilvernodes));
        }
Ejemplo n.º 6
0
        public override TranslationResult Translate(TranslationContext context)
        {
            var translatedExpression = this.expression.Translate(context);
            // Statement form only.
            string @operator = this.direction == IncrementExpressionDirection.Increment ? "+" : "-";

            return(TranslationResult.FromSilvernode(
                       new AssignmentSilvernode(
                           translatedExpression.Silvernode,
                           new BinaryExpressionSilvernode(translatedExpression.Silvernode, @operator, new TextSilvernode("1"), this.OriginalNode), this.OriginalNode), translatedExpression.Errors));
        }
        public override TranslationResult Translate(TranslationContext context)
        {
            var symbol          = context.Semantics.GetDeclaredSymbol(this.Self);
            var identifier      = context.Process.IdentifierTranslator.RegisterAndGetIdentifier(symbol);
            var statementResult = this.Statement.Translate(context);
            StatementsSequenceSilvernode seq = new StatementsSequenceSilvernode(this.OriginalNode,
                                                                                new LabelSilvernode(identifier, this.OriginalNode),
                                                                                (StatementSilvernode)statementResult.Silvernode
                                                                                );

            return(TranslationResult.FromSilvernode(seq, statementResult.Errors));
        }
Ejemplo n.º 8
0
        public override TranslationResult Translate(TranslationContext context)
        {
            // see thesis for details

            if (error != null)
            {
                return(TranslationResult.Error(error));
            }
            List <Error> errors = new List <Error>();

            var temporaryHoldingVariable = context.Process.IdentifierTranslator.RegisterNewUniqueIdentifier();

            // ReSharper disable once UseObjectOrCollectionInitializer
            var arguments = new List <Silvernode>();
            var prepend   = new List <StatementSilvernode>();

            arguments.Add("Seq(");
            foreach (var arg in this.Arguments)
            {
                var res = arg.Translate(context.ChangePurityContext(PurityContext.Purifiable));
                arguments.Add(res.Silvernode);
                if (arg != this.Arguments.Last())
                {
                    arguments.Add(", ");
                }
                errors.AddRange(res.Errors);
                prepend.AddRange(res.PrependTheseSilvernodes);
            }
            arguments.Add(")");

            Silvernode arrayConstruction = new SimpleSequenceSilvernode(null, arguments.ToArray());

            prepend.AddRange(new StatementSilvernode[] {
                new VarStatementSilvernode(temporaryHoldingVariable, SilverType.Ref, this.OriginalNode),
                new SimpleSequenceStatementSilvernode(this.OriginalNode,
                                                      new IdentifierSilvernode(temporaryHoldingVariable), " := ", "new(",
                                                      ArraysTranslator.IntegerArrayContents, ")"),
                new AssignmentSilvernode(
                    new SimpleSequenceSilvernode(this.OriginalNode, new IdentifierSilvernode(temporaryHoldingVariable),
                                                 ".", ArraysTranslator.IntegerArrayContents), arrayConstruction, this.OriginalNode)
            });
            switch (context.PurityContext)
            {
            case PurityContext.PurityNotRequired:
            case PurityContext.Purifiable:
                return(TranslationResult.FromSilvernode(new IdentifierSilvernode(temporaryHoldingVariable), errors).AndPrepend(prepend));

            case PurityContext.PureOrFail:
                return(TranslationResult.Error(this.OriginalNode, Diagnostics.SSIL114_NotPureContext, "Array creation is inherently impure."));
            }
            throw new Exception("This should never be reached.");
        }
Ejemplo n.º 9
0
        public override TranslationResult Translate(TranslationContext context)
        {
            var left  = this.Left.Translate(context);
            var right = this.Right.Translate(context.ChangePurityContext(PurityContext.Purifiable));
            IEnumerable <Error> errors = CommonUtils.CombineErrors(left, right);

            return
                (TranslationResult.FromSilvernode(
                     new AssignmentSilvernode(
                         left.Silvernode,
                         new BinaryExpressionSilvernode(left.Silvernode, this.operation, right.Silvernode,
                                                        this.OriginalNode), this.OriginalNode), errors)
                 .AndPrepend(right.PrependTheseSilvernodes));
        }
        public override TranslationResult Translate(TranslationContext context)
        {
            if (!(this.Identifier is IdentifierExpressionSharpnode))
            {
                return(TranslationResult.Error(this.OriginalNode, Diagnostics.SSIL110_InvalidSyntax, "illegal goto target"));
            }
            IdentifierExpressionSharpnode identifierExpression = (IdentifierExpressionSharpnode)this.Identifier;
            ISymbol symbol     = identifierExpression.GetIdentifierSymbol(context);
            var     identifier = context.Process.IdentifierTranslator.GetIdentifierReference(symbol);

            return(TranslationResult.FromSilvernode(
                       new GotoSilvernode(identifier, this.OriginalNode)
                       ));
        }
Ejemplo n.º 11
0
        public override TranslationResult Translate(TranslationContext context)
        {
            var  constructorSymbol    = context.Semantics.GetSymbolInfo(this.OriginalNode).Symbol as IMethodSymbol;
            var  classSymbol          = constructorSymbol.ContainingType;
            bool isDefaultConstructor = constructorSymbol.IsImplicitlyDeclared;

            // Special case:
            if (classSymbol.GetQualifiedName() == SeqTranslator.SeqClassWithoutEndDot)
            {
                return(SeqTranslator.Constructor(this.Arguments, context, classSymbol.TypeArguments[0], this.OriginalNode));
            }

            var identifier = context.Process.IdentifierTranslator.RegisterNewUniqueIdentifier();

            // Normal case: As method call
            var arguments    = new List <Silvernode>();
            var errors       = new List <Error>();
            var prependThese = new List <StatementSilvernode>();

            foreach (var arg in this.Arguments)
            {
                var res = arg.Translate(context.ChangePurityContext(PurityContext.Purifiable));
                arguments.Add(res.Silvernode);
                errors.AddRange(res.Errors);
                prependThese.AddRange(res.PrependTheseSilvernodes);
            }

            Silvernode constructorCall = new CallSilvernode(context.Process.IdentifierTranslator.GetIdentifierReferenceWithTag(classSymbol, isDefaultConstructor ? Constants.InitializerTag : Constants.ConstructorTag),
                                                            arguments,
                                                            SilverType.Ref,
                                                            this.OriginalNode);

            prependThese.Add(new VarStatementSilvernode(identifier, SilverType.Ref, this.OriginalNode));
            prependThese.Add(new AssignmentSilvernode(new IdentifierSilvernode(identifier), constructorCall,
                                                      this.OriginalNode));

            switch (context.PurityContext)
            {
            case PurityContext.PurityNotRequired:
            case PurityContext.Purifiable:
                return(TranslationResult.FromSilvernode(new IdentifierSilvernode(identifier), errors).AndPrepend(
                           prependThese
                           ));

            case PurityContext.PureOrFail:
                return(TranslationResult.Error(this.OriginalNode, Diagnostics.SSIL114_NotPureContext, "Object creation is inherently impure."));
            }
            throw new System.Exception("This should never be reached.");
        }
Ejemplo n.º 12
0
        public TranslationResult Translate(TranslationContext context, IParameterSymbol symbol)
        {
            Error               err;
            ISymbol             parameterSymbol = context.Semantics.GetDeclaredSymbol(this.ParameterSyntax);
            Identifier          identifier      = context.Process.IdentifierTranslator.RegisterAndGetIdentifier(parameterSymbol);
            ParameterSilvernode ps = new ParameterSilvernode(identifier,
                                                             new TypeSilvernode(this.Type.TypeSyntax, TypeTranslator.TranslateType(symbol.Type, this.Type.TypeSyntax, out err)), this.OriginalNode);
            var errlist = new List <Error>();

            if (err != null)
            {
                errlist.Add(err);
            }
            return(TranslationResult.FromSilvernode(ps, errlist));
        }
Ejemplo n.º 13
0
        public override TranslationResult Translate(TranslationContext context)
        {
            // see thesis for details

            SymbolInfo symbolInfo   = context.Semantics.GetSymbolInfo(this.eaes);
            ISymbol    symbol       = symbolInfo.Symbol;
            string     accessorName = symbol?.GetQualifiedName();
            var        errors       = new List <Error>();
            var        container    = this.Container.Translate(context);
            var        index        = this.Index.Translate(context.ChangePurityContext(PurityContext.Purifiable));

            errors.AddRange(container.Errors);
            errors.AddRange(index.Errors);
            if (accessorName == SeqTranslator.SeqAccess)
            {
                return(TranslationResult.FromSilvernode(
                           new SimpleSequenceSilvernode(this.OriginalNode,
                                                        container.Silvernode,
                                                        "[",
                                                        index.Silvernode,
                                                        "]"
                                                        ), errors
                           ).AndPrepend(container.PrependTheseSilvernodes.Concat(index.PrependTheseSilvernodes)));
            }
            else
            {
                var typeInfo = context.Semantics.GetTypeInfo(Container.OriginalNode);
                var t        = typeInfo.Type;
                if (t.Kind == SymbolKind.ArrayType)
                {
                    // Let's assume that this is an array read.
                    // If this is an array write, the parent will usee ArraysContainer and ArraysIndex instead
                    var readsilvernode = context.Process.ArraysTranslator.ArrayRead(this.OriginalNode, container.Silvernode,
                                                                                    index.Silvernode);
                    TranslationResult read = TranslationResult.FromSilvernode(readsilvernode, errors).AndPrepend(container.PrependTheseSilvernodes.Concat(index.PrependTheseSilvernodes));
                    read.ArraysContainer = container;
                    read.ArraysIndex     = index;
                    return(read);
                }
                else
                {
                    return(TranslationResult.Error(this.OriginalNode,
                                                   Diagnostics.SSIL128_IndexersAreOnlyForSeqsAndArrays));
                }
            }
        }
Ejemplo n.º 14
0
        public override TranslationResult Translate(TranslationContext context)
        {
            List <StatementSilvernode> statements = new List <StatementSilvernode>();
            List <Error> diagnostics = new List <Error>();

            foreach (var declaration in this.Declarations)
            {
                var statementResult = declaration.Translate(context);
                if (statementResult.Silvernode != null)
                {
                    statements.Add(statementResult.Silvernode as StatementSilvernode);
                }
                diagnostics.AddRange(statementResult.Errors);
            }
            StatementsSequenceSilvernode statementsSequence = new StatementsSequenceSilvernode(this.OriginalNode, statements.ToArray());

            return(TranslationResult.FromSilvernode(statementsSequence, diagnostics));
        }
Ejemplo n.º 15
0
        public override TranslationResult Translate(TranslationContext context)
        {
            var expressionResult = this.InnerExpression.Translate(context);

            if (expressionResult.Silvernode is ExpressionSilvernode)
            {
                return(TranslationResult.FromSilvernode(
                           new ParenthesizedExpressionSilvernode((ExpressionSilvernode)expressionResult.Silvernode,
                                                                 this.OriginalNode),
                           expressionResult.Errors));
            }
            else
            {
                return(TranslationResult.FromSilvernode(
                           expressionResult.Silvernode,
                           expressionResult.Errors));
            }
        }
        public override TranslationResult Translate(TranslationContext context)
        {
            SymbolInfo   symbolInfo    = context.Semantics.GetSymbolInfo(this._syntax);
            ISymbol      symbol        = symbolInfo.Symbol;
            string       qualifiedName = symbol?.GetQualifiedName();
            string       operatorName  = qualifiedName == SeqTranslator.OperatorPlus ? "++" : this.Operator;
            var          left          = this.Left.Translate(context);
            var          right         = this.Right.Translate(context);
            List <Error> errors        = CommonUtils.CombineErrors(left, right).ToList();

            // Impure expressions cause error
            if (Right is SimpleAssignmentExpressionSharpnode ||
                Right is CompoundAssignmentExpressionSharpnode ||
                Right is IncrementExpressionSharpnode)
            {
                errors.Add(new Error(Diagnostics.SSIL131_AssignmentsNotInsideExpressions,
                                     Right.OriginalNode));
            }
            if (Left is SimpleAssignmentExpressionSharpnode ||
                Left is CompoundAssignmentExpressionSharpnode ||
                Left is IncrementExpressionSharpnode)
            {
                errors.Add(new Error(Diagnostics.SSIL131_AssignmentsNotInsideExpressions,
                                     Left.OriginalNode));
            }

            // Special case for Contract.Truth:
            if (this.Operator == "&&" &&
                left.Silvernode != null && left.Silvernode.ToString().Trim() == "true")
            {
                // This happens in contracts only, prepending is unnecessary
                return(TranslationResult.FromSilvernode(right.Silvernode, errors));
            }



            return(TranslationResult
                   .FromSilvernode(
                       new BinaryExpressionSilvernode(left.Silvernode, operatorName, right.Silvernode, this.OriginalNode),
                       errors)
                   .AndPrepend(left.PrependTheseSilvernodes.Concat(right.PrependTheseSilvernodes)));

            ;
        }
        public override TranslationResult Translate(TranslationContext context)
        {
            var exResult = this.Expression.Translate(context);

            if (exResult.Silvernode.IsContract())
            {
                return(exResult);
            }
            else if (exResult.Silvernode is CallSilvernode)
            {
                // It is a method call -- and the result is ignored.
                CallSilvernode call = (CallSilvernode)(exResult.Silvernode);
                if (call.Type != SilverType.Void)
                {
                    var tempVar  = context.Process.IdentifierTranslator.RegisterNewUniqueIdentifier();
                    var sequence = new StatementsSequenceSilvernode(this.OriginalNode,
                                                                    new VarStatementSilvernode(tempVar, call.Type, null),
                                                                    new AssignmentSilvernode(
                                                                        new IdentifierSilvernode(tempVar),
                                                                        call, null)
                                                                    );
                    return(TranslationResult.FromSilvernode(sequence, exResult.Errors));
                }
                else
                {
                    return(TranslationResult.FromSilvernode(call, exResult.Errors));
                }
            }
            else if (exResult.Silvernode is BinaryExpressionSilvernode)
            {
                return(exResult);
            }
            else if (exResult.Silvernode is AssignmentSilvernode)
            {
                return(exResult);
            }
            else if (exResult.Silvernode is StatementSilvernode)
            {
                return(exResult);
            }

            return(TranslationResult.Error(this.Expression.OriginalNode, Diagnostics.SSIL107_ThisExpressionCannotBeStatement));
        }
Ejemplo n.º 18
0
        public override TranslationResult Translate(TranslationContext context)
        {
            var classSymbol = context.Semantics.GetDeclaredSymbol(this.OriginalNode as ClassDeclarationSyntax);

            // Should translate at all?
            var attributes = classSymbol.GetAttributes();

            switch (VerificationSettings.ShouldVerify(attributes, context.VerifyUnmarkedItems))
            {
            case VerificationSetting.DoNotVerify:
                return(TranslationResult.FromSilvernode(new SinglelineCommentSilvernode($"Class {classSymbol.GetQualifiedName()} skipped.", this.OriginalNode)));

            case VerificationSetting.Contradiction:
                return(TranslationResult.Error(this.OriginalNode,
                                               Diagnostics.SSIL113_VerificationSettingsContradiction));
            }

            // Combine all members
            return(CommonUtils.GetHighlevelSequence(this.children.Select(child => child.Translate(context))));
        }
        public override TranslationResult Translate(TranslationContext context)
        {
            var errors = new List <Error>();
            var cres   = this.Condition.Translate(context);
            var a      = cres.Silvernode;

            errors.AddRange(cres.Errors);
            var trueres = this.WhenTrue.Translate(context);
            var b       = trueres.Silvernode;

            errors.AddRange(trueres.Errors);
            var falseres = this.WhenFalse.Translate(context);
            var c        = falseres.Silvernode;

            errors.AddRange(falseres.Errors);
            return(TranslationResult.FromSilvernode(new ConditionalExpressionSilvernode(
                                                        a,
                                                        b,
                                                        c, this.OriginalNode
                                                        ),
                                                    errors).AndPrepend(cres.PrependTheseSilvernodes.Concat(trueres.PrependTheseSilvernodes).Concat(falseres.PrependTheseSilvernodes)));
        }
Ejemplo n.º 20
0
        public override TranslationResult Translate(TranslationContext context)
        {
            // Translate parts
            var conditionResult = this.Condition.Translate(context.ChangePurityContext(PurityContext.Purifiable));
            var statementResult = this.Statement.Translate(context);
            var statementBlock  = ((StatementSilvernode)statementResult.Silvernode).EncloseInBlockIfNotAlready();

            // Put them together
            var errors = new List <Error>();

            errors.AddRange(conditionResult.Errors);
            foreach (var incrementor in this.Incrementors)
            {
                var incrementorResult = incrementor.Translate(context);
                statementBlock.Add(incrementorResult.Silvernode as StatementSilvernode);
                errors.AddRange(incrementorResult.Errors);
            }
            errors.AddRange(statementResult.Errors);
            statementBlock.Statements.AddRange(conditionResult.PrependTheseSilvernodes);
            WhileSilvernode whileNode =
                new WhileSilvernode(
                    conditionResult.Silvernode,
                    statementResult.Contracts,
                    statementBlock, this.OriginalNode
                    );
            var sequence = new StatementsSequenceSilvernode(this.OriginalNode);

            foreach (var initializer in this.Initializers)
            {
                var initializerResult = initializer.Translate(context);
                errors.AddRange(initializerResult.Errors);
                sequence.List.Add(initializerResult.Silvernode as StatementSilvernode);
            }
            sequence.List.AddRange(conditionResult.PrependTheseSilvernodes);
            sequence.List.Add(whileNode);
            return(TranslationResult.FromSilvernode(sequence, errors));
        }
Ejemplo n.º 21
0
        public override TranslationResult Translate(TranslationContext context)
        {
            // Translate parts
            var conditionResult = this.Condition.Translate(context.ChangePurityContext(PurityContext.Purifiable));
            var thenResult      = this.Then.Translate(context);
            var elseResult      = this.Else?.Translate(context);

            // Put them together
            var errors = new List <Error>();

            errors.AddRange(conditionResult.Errors);
            errors.AddRange(thenResult.Errors);
            if (elseResult != null)
            {
                errors.AddRange(elseResult.Errors);
            }

            Silvernode output = new IfSilvernode(this.OriginalNode,
                                                 conditionResult.Silvernode,
                                                 thenResult.Silvernode as StatementSilvernode,
                                                 elseResult?.Silvernode as StatementSilvernode);

            return(TranslationResult.FromSilvernode(output, errors).AndPrepend(conditionResult.PrependTheseSilvernodes));
        }
 public override TranslationResult Translate(TranslationContext context)
 {
     return(TranslationResult.FromSilvernode(new TextStatementSilvernode("", this.OriginalNode)));
 }
        public override TranslationResult Translate(TranslationContext context)
        {
            // Get symbol from semantic analysis
            var method       = context.Semantics.GetSymbolInfo(this.MethodGroup);
            var methodSymbol = method.Symbol as IMethodSymbol;

            if (methodSymbol == null)
            {
                return(TranslationResult.Error(this.OriginalNode, Diagnostics.SSIL123_ThereIsThisCSharpError,
                                               "This name cannot be unambiguously mapped to a single method."));
            }
            var methodName = methodSymbol.GetQualifiedName();

            // There are many special cases where we don't want to translate a method call as a Viper method or function call
            // Each case is a subclass of InvocationTranslation. See InvocationTranslation for details.
            // These special cases all concern invocation targets within Soothsharp.Contracts and are translated into
            // keyworded Viper constructs
            InvocationTranslation translationStyle;

            switch (methodName)
            {
            case ContractsTranslator.ContractEnsures:
            case ContractsTranslator.ContractRequires:
            case ContractsTranslator.ContractInvariant:
                translationStyle = new InvocationContract(methodName);
                break;

            case ContractsTranslator.Implication:
                translationStyle = new InvocationImplicationEquivalence("==>", this.MethodGroup);
                break;

            case ContractsTranslator.Equivalence:
                translationStyle = new InvocationImplicationEquivalence("<==>", this.MethodGroup);
                break;

            case ContractsTranslator.ForAll:
                translationStyle = new InvocationQuantifier(QuantifierKind.ForAll);
                break;

            case ContractsTranslator.Exists:
                translationStyle = new InvocationQuantifier(QuantifierKind.Exists);
                break;

            case ContractsTranslator.ContractAssert:
                translationStyle = new InvocationPhpStatement("assert");
                break;

            case ContractsTranslator.ContractAssume:
                translationStyle = new InvocationPhpStatement("assume");
                break;

            case ContractsTranslator.ContractInhale:
                translationStyle = new InvocationPhpStatement("inhale");
                break;

            case ContractsTranslator.ContractExhale:
                translationStyle = new InvocationPhpStatement("exhale");
                break;

            case ContractsTranslator.ContractAcc:
                translationStyle = new InvocationViperBuiltInFunction("acc", false);
                break;

            case ContractsTranslator.ContractAccArray:
                translationStyle = new InvocationAccArray();
                break;

            case ContractsTranslator.Old:
                translationStyle = new InvocationViperBuiltInFunction("old", false);
                break;

            case ContractsTranslator.Fold:
                translationStyle = new InvocationPhpStatement("fold");
                break;

            case ContractsTranslator.Unfold:
                translationStyle = new InvocationPhpStatement("unfold");
                break;

            case ContractsTranslator.PermissionCreate:
                translationStyle = new InvocationPermissionCreate();
                break;

            case ContractsTranslator.PermissionFromLocation:
                translationStyle = new InvocationViperBuiltInFunction("perm", false);
                break;

            case SeqTranslator.Contains:
                translationStyle = new InvocationSeqContains(this.MethodGroup, this.methodGroupSharpnode);
                break;

            case SeqTranslator.Drop:
                translationStyle = new InvocationSeqTakeDrop(false, true, this.MethodGroup, this.methodGroupSharpnode);
                break;

            case SeqTranslator.Take:
                translationStyle = new InvocationSeqTakeDrop(true, false, this.MethodGroup, this.methodGroupSharpnode);
                break;

            case SeqTranslator.TakeDrop:
                translationStyle = new InvocationSeqTakeDrop(true, true, this.MethodGroup, this.methodGroupSharpnode);
                break;

            case ContractsTranslator.Result:
                translationStyle = new InvocationResult();
                break;

            case ContractsTranslator.Folding:
                translationStyle = new InvocationFoldingUnfolding(true);
                break;

            case ContractsTranslator.Unfolding:
                translationStyle = new InvocationFoldingUnfolding(false);
                break;

            default:
                // Standard case
                translationStyle = new InvocationStandardMethod(this.MethodGroup, this.methodGroupSharpnode, method);
                break;
            }

            // Perform the translation
            translationStyle.Run(this.Arguments, this.OriginalNode, context);

            // Get the result
            Silvernode silvernode = translationStyle.Silvernode;

            TranslationResult result = TranslationResult.FromSilvernode(silvernode,
                                                                        translationStyle.Errors).AndPrepend(translationStyle.Prependors.ToArray());

            // Maybe prepending is required.
            translationStyle.PostprocessPurity(result, context);
            return(result);
        }
Ejemplo n.º 24
0
 public override TranslationResult Translate(TranslationContext context)
 {
     // This is not translated.
     return(TranslationResult.FromSilvernode(new EmptySilvernode(this.fieldDeclarationSyntax)));
 }
Ejemplo n.º 25
0
 public override TranslationResult Translate(TranslationContext context)
 {
     return(TranslationResult.FromSilvernode(this.Code));
 }