Beispiel #1
0
 public BoundForStatement(VariableSymble variable, BoundExpression lowerBound, BoundExpression upperBound, BoundStatement body)
 {
     Variable   = variable;
     LowerBound = lowerBound;
     UpperBound = upperBound;
     Body       = body;
 }
Beispiel #2
0
 public BoundForStatement(VariableSymble variable, BoundExpression lowerBound, BoundExpression upperBound, BoundExpression itterator, BoundStatement body, BoundLabel bodyLabel, BoundLabel breakLabel, BoundLabel continueLabel)
     : base(body, bodyLabel, breakLabel, continueLabel)
 {
     Variable   = variable;
     LowerBound = lowerBound;
     UpperBound = upperBound;
     Itterator  = itterator;
 }
Beispiel #3
0
        public bool TryDeclare(VariableSymble variable)
        {
            if (_variables.ContainsKey(variable.Name))
            {
                return(false);
            }

            _variables.Add(variable.Name, variable);
            return(true);
        }
Beispiel #4
0
        private BoundStatement BindVeriableDeclaration(VeriableDeclarationSyntax syntax)
        {
            var name        = syntax.Identifier.Text;
            var initializer = BindExpression(syntax.Initializer);
            var variable    = new VariableSymble(name, false, initializer.Type);

            if (!_scope.TryDeclare(variable))
            {
                _diagnostics.ReportVariableAlreadyDecleard(syntax.Identifier.Span, name);
            }

            return(new BoundVeriableDeclaration(variable, initializer));
        }
Beispiel #5
0
        public bool TryLookup(string name, out VariableSymble variable)
        {
            if (_variables.TryGetValue(name, out variable))
            {
                return(true);
            }

            if (Parent == null)
            {
                return(false);
            }

            return(Parent.TryLookup(name, out variable));
        }
Beispiel #6
0
        protected override BoundStatement RewriteForStatement(BoundForStatement node)
        {
            // for <var> = <lower> to <upper>
            //      <body>
            //
            // ---->
            //
            // {
            //      var <var> = <lower>
            //      while (<var> <= <upper>)
            //      {
            //          <body>
            //          <var> = <var> + 1
            //      }
            // }

            var variableDeclaration   = new BoundVeriableDeclaration(node.Variable, node.LowerBound);
            var variableExpression    = new BoundVariableExpression(node.Variable);
            var upperBoundSybmle      = new VariableSymble("upperBound", true, typeof(int));
            var upperBoundDeclaration = new BoundVeriableDeclaration(upperBoundSybmle, node.UpperBound);
            var condition             = new BoundBinaryExpression(
                variableExpression,
                BoundBinaryOperator.Bind(SyntaxKind.LessOrEqualToken, typeof(int), typeof(int)),
                new BoundVariableExpression(upperBoundSybmle)
                );
            var increment = new BoundExpressionStatemnet(
                new BoundAssignmentExpression(
                    node.Variable,
                    new BoundBinaryExpression(
                        variableExpression,
                        BoundBinaryOperator.Bind(SyntaxKind.PlusToken, typeof(int), typeof(int)),
                        new BoundLiteralExpression(1)
                        )
                    )
                );
            var whileBody      = new BoundBlockStatemnet(ImmutableArray.Create <BoundStatement>(node.Body, increment));
            var whileStatement = new BoundWhileStatement(condition, whileBody);
            var result         = new BoundBlockStatemnet(ImmutableArray.Create <BoundStatement>(
                                                             variableDeclaration, upperBoundDeclaration, whileStatement));

            return(RewriteStatement(result));
        }
Beispiel #7
0
        private BoundStatement BindForStatement(ForStatementSyntax syntax)
        {
            var lowerBound = BindExpression(syntax.LowerBound, typeof(int));
            var upperBound = BindExpression(syntax.UpperBoud, typeof(int));


            _scope = new BoundScope(_scope);

            var name     = syntax.Identifier.Text;
            var variable = new VariableSymble(name, true, typeof(int));

            if (!_scope.TryDeclare(variable))
            {
                _diagnostics.ReportVariableAlreadyDecleard(syntax.Identifier.Span, name);
            }

            var body = BindStatement(syntax.Body);

            _scope = _scope.Parent;

            return(new BoundForStatement(variable, lowerBound, upperBound, body));
        }
Beispiel #8
0
 public bool TryDeclareVariable(VariableSymble variable)
 => TryDeclareSymbol(variable);
 public BoundAssignmentExpression(VariableSymble variable, BoundExpression expression)
 {
     Variable   = variable;
     Expression = expression;
 }
 public BoundVeriableDeclaration(VariableSymble variable, BoundExpression initializer)
 {
     Variable    = variable;
     Initializer = initializer;
 }
Beispiel #11
0
 public BoundVariableExpression(VariableSymble variable)
 {
     Variable = variable;
 }