Exemplo n.º 1
0
        public override void Run(List <ExpressionSharpnode> arguments, SyntaxNode originalNode, TranslationContext context)
        {
            if (this.MethodGroup is MemberAccessExpressionSyntax)
            {
                MemberAccessExpressionSyntax memberAccess = (MemberAccessExpressionSyntax)this.MethodGroup;
                var leftExpression = RoslynToSharpnode.MapExpression(memberAccess.Expression);
                // There are some Viper purity requirements here, but they are checked by the verifier,
                // so we don't need to check them.
                var        leftExpressionResult  = leftExpression.Translate(context);
                var        rightExpressionResult = arguments[0].Translate(context);
                Silvernode implies = new BinaryExpressionSilvernode(
                    leftExpressionResult.Silvernode, this._operator,
                    rightExpressionResult.Silvernode,
                    originalNode
                    );

                this.Errors.AddRange(leftExpressionResult.Errors);
                this.Errors.AddRange(rightExpressionResult.Errors);
                this.Prependors.AddRange(leftExpressionResult.PrependTheseSilvernodes);
                this.Prependors.AddRange(rightExpressionResult.PrependTheseSilvernodes);
                this.Silvernode = implies;
            }
            else
            {
                this.Errors.Add(new Error(Diagnostics.SSIL110_InvalidSyntax, originalNode,
                                          "member access expression expected"));
                this.Silvernode = new TextSilvernode(Constants.SilverErrorString, originalNode);
            }
        }
Exemplo n.º 2
0
 public ElementAccessSharpnode(ElementAccessExpressionSyntax syntax) : base(syntax)
 {
     this.eaes      = syntax;
     this.Container = RoslynToSharpnode.MapExpression(syntax.Expression);
     // Only single-dimensional arrays are supported.
     this.Index = RoslynToSharpnode.MapExpression(syntax.ArgumentList.Arguments[0].Expression);
 }
Exemplo n.º 3
0
 public CompoundAssignmentExpressionSharpnode(AssignmentExpressionSyntax syntax, string operation)
     : base(syntax)
 {
     this.operation = operation;
     this.Left      = RoslynToSharpnode.MapExpression(syntax.Left);
     this.Right     = RoslynToSharpnode.MapExpression(syntax.Right);
 }
Exemplo n.º 4
0
 public ReturnStatementSharpnode(ReturnStatementSyntax stmt) : base(stmt)
 {
     if (stmt.Expression != null)
     {
         this.Expression = RoslynToSharpnode.MapExpression(stmt.Expression);
     }
 }
Exemplo n.º 5
0
 public ObjectCreationExpressionSharpnode(ObjectCreationExpressionSyntax syntax) : base(syntax)
 {
     foreach (var argument in syntax.ArgumentList.Arguments)
     {
         this.Arguments.Add(RoslynToSharpnode.MapExpression(argument.Expression));
     }
 }
 public BinaryExpressionSharpnode(BinaryExpressionSyntax syntax, string @operator) : base(syntax)
 {
     this._syntax  = syntax;
     this.Operator = @operator;
     this.Left     = RoslynToSharpnode.MapExpression(syntax.Left);
     this.Right    = RoslynToSharpnode.MapExpression(syntax.Right);
 }
 public InvocationExpressionSharpnode(InvocationExpressionSyntax syntax) : base(syntax)
 {
     this.MethodGroup          = syntax.Expression;
     this.methodGroupSharpnode = RoslynToSharpnode.MapExpression(syntax.Expression);
     foreach (var argument in syntax.ArgumentList.Arguments)
     {
         this.Arguments.Add(RoslynToSharpnode.MapExpression(argument.Expression));
     }
 }
Exemplo n.º 8
0
 private void LoadFrom(InitializerExpressionSyntax syntax)
 {
     if (syntax == null)
     {
         error = new Error(Diagnostics.SSIL108_FeatureNotSupported, this.OriginalNode,
                           "rank-initialized arrays");
         return;
     }
     foreach (var s in syntax.Expressions)
     {
         Arguments.Add(RoslynToSharpnode.MapExpression(s));
     }
 }
Exemplo n.º 9
0
 public LambdaSharpnode(SimpleLambdaExpressionSyntax syntax) : base(syntax)
 {
     this.parameter = new ParameterSharpnode(syntax.Parameter);
     if (syntax.Body is ExpressionSyntax)
     {
         this.body = RoslynToSharpnode.MapExpression((ExpressionSyntax)syntax.Body);
     }
     else
     {
         this.errorneousResult = new Error(
             Diagnostics.SSIL126_LambdasMustBeExpressions, syntax.Body);
     }
 }
Exemplo n.º 10
0
 public LambdaSharpnode(ParenthesizedLambdaExpressionSyntax syntax) : base(syntax)
 {
     // We only allow for a single kind of lambda expressions: those that fit ForAll and Exists.
     if (syntax.ParameterList.Parameters.Count != 1)
     {
         this.errorneousResult = new Error(
             Diagnostics.SSIL125_LambdasMustHaveSingleParameter, syntax.ParameterList);
         return;
     }
     this.parameter = new ParameterSharpnode(syntax.ParameterList.Parameters[0]);
     if (syntax.Body is ExpressionSyntax)
     {
         this.body = RoslynToSharpnode.MapExpression((ExpressionSyntax)syntax.Body);
     }
     else
     {
         this.errorneousResult = new Error(
             Diagnostics.SSIL126_LambdasMustBeExpressions, syntax.Body);
     }
 }
Exemplo n.º 11
0
        private void Init(VariableDeclarationSyntax syntax)
        {
            var typeSyntax = syntax.Type;

            foreach (var variable in syntax.Variables)
            {
                ExpressionSharpnode initialValue = null;
                if (variable.Initializer != null)
                {
                    initialValue = RoslynToSharpnode.MapExpression(variable.Initializer.Value);
                }
                SimpleLocalDeclarationSharpnode declaration =
                    new SimpleLocalDeclarationSharpnode(
                        typeSyntax,
                        initialValue,
                        variable)
                ;
                this.Declarations.Add(declaration);
            }
        }
Exemplo n.º 12
0
        public ForStatementSharpnode(ForStatementSyntax stmt) : base(stmt)
        {
            this.Condition = RoslynToSharpnode.MapExpression(stmt.Condition);
            this.Statement = RoslynToSharpnode.MapStatement(stmt.Statement);
            // Add declarations
            if (stmt.Declaration != null)
            {
                this.Initializers.Add(new LocalDeclarationSharpnode(stmt.Declaration));
            }
            // Add initializers

            if (stmt.Initializers != null)
            {
                foreach (var initializer in stmt.Initializers)
                {
                    Initializers.Add(new ExpressionStatementSharpnode(initializer));
                }
            }
            foreach (var incrementor in stmt.Incrementors)
            {
                this.Incrementors.Add(RoslynToSharpnode.MapExpression(incrementor));
            }
        }
Exemplo n.º 13
0
 public IfStatementSharpnode(IfStatementSyntax stmt) : base(stmt)
 {
     this.Condition = RoslynToSharpnode.MapExpression(stmt.Condition);
     this.Then      = RoslynToSharpnode.MapStatement(stmt.Statement);
     this.Else      = stmt.Else != null?RoslynToSharpnode.MapStatement(stmt.Else.Statement) : null;
 }
 public GotoStatementSharpnode(GotoStatementSyntax stmt) : base(stmt)
 {
     this.Identifier = RoslynToSharpnode.MapExpression(stmt.Expression);
 }
 public ConditionalExpressionSharpnode(ConditionalExpressionSyntax syntax) : base(syntax)
 {
     this.Condition = RoslynToSharpnode.MapExpression(syntax.Condition);
     this.WhenTrue  = RoslynToSharpnode.MapExpression(syntax.WhenTrue);
     this.WhenFalse = RoslynToSharpnode.MapExpression(syntax.WhenFalse);
 }
 public LabeledStatementSharpnode(LabeledStatementSyntax stmt) : base(stmt)
 {
     this.Self      = stmt;
     this.Statement = RoslynToSharpnode.MapStatement(stmt.Statement);
 }
 public SimpleAssignmentExpressionSharpnode(AssignmentExpressionSyntax syntax) : base(syntax)
 {
     this.Left  = RoslynToSharpnode.MapExpression(syntax.Left);
     this.Right = RoslynToSharpnode.MapExpression(syntax.Right);
 }
Exemplo n.º 18
0
 public IncrementExpressionSharpnode(PostfixUnaryExpressionSyntax syntax, IncrementExpressionDirection direction) : base(syntax)
 {
     this.direction  = direction;
     this.order      = IncrementExpressionOrder.Post;
     this.expression = RoslynToSharpnode.MapExpression(syntax.Operand);
 }
Exemplo n.º 19
0
 public PrefixUnaryExpressionSharpnode(PrefixUnaryExpressionSyntax syntax, string @operator) : base(syntax)
 {
     this.Operator   = @operator;
     this.Expression = RoslynToSharpnode.MapExpression(syntax.Operand);
 }
Exemplo n.º 20
0
 public ParenthesizedExpressionSharpnode(ParenthesizedExpressionSyntax syntax) : base(syntax)
 {
     this.InnerExpression = RoslynToSharpnode.MapExpression(syntax.Expression);
 }
 public ExpressionStatementSharpnode(ExpressionStatementSyntax originalNode) : base(originalNode)
 {
     this.Expression = RoslynToSharpnode.MapExpression(originalNode.Expression);
 }