Ejemplo n.º 1
0
        protected BoundStatement(SourceLocation location)
        {
            if (location == null)
                throw new ArgumentNullException("location");

            Location = location;
        }
Ejemplo n.º 2
0
        public SwitchCase(ExpressionSyntax expression, BlockSyntax body, SourceLocation location)
        {
            if (body == null)
                throw new ArgumentNullException("body");
            if (location == null)
                throw new ArgumentNullException("location");

            Expression = expression;
            Body = body;
            Location = location;
        }
Ejemplo n.º 3
0
        public BoundFunction Update(string name, ReadOnlyArray<string> parameters, BoundBody body, SourceLocation location)
        {
            if (
                name == Name &&
                parameters == Parameters &&
                body == Body &&
                location == Location
            )
                return this;

            return new BoundFunction(name, parameters, body, location);
        }
Ejemplo n.º 4
0
        public BoundFunction(string name, ReadOnlyArray<string> parameters, BoundBody body, SourceLocation location)
        {
            if (parameters == null)
                throw new ArgumentNullException("parameters");
            if (body == null)
                throw new ArgumentNullException("body");
            if (location == null)
                throw new ArgumentNullException("location");

            Name = name;
            Parameters = parameters;
            Body = body;
            Location = location;
        }
Ejemplo n.º 5
0
        public FunctionSyntax BuildFunction(string name, ReadOnlyArray<string> parameters, BodySyntax body, SourceLocation location)
        {
            IIdentifier identifier = null;

            if (name != null)
            {
                identifier = _scope.CreateIdentifier(name);
                _scope.DeclareIdentifier(name);
            }

            return new FunctionSyntax(
                identifier,
                parameters,
                body,
                location
            );
        }
Ejemplo n.º 6
0
        public SyntaxNode BuildFor(EcmaScriptParser parser, SourceLocation location)
        {
            if (Expression != null)
            {
                IIdentifier identifier;

                if (Initialization is IdentifierSyntax)
                {
                    identifier = ((IdentifierSyntax)Initialization).Identifier;
                }
                else
                {
                    var variableDeclaration = (VariableDeclarationSyntax)Initialization;

                    Debug.Assert(variableDeclaration.Declarations.Count == 1);

                    var declaration = variableDeclaration.Declarations[0];

                    identifier = declaration.Identifier;

                    Debug.Assert(declaration.Expression == null);
                }

                return _builder.BuildForEachIn(
                    identifier,
                    Expression,
                    Body,
                    location
                );
            }

            return _builder.BuildFor(
                Initialization,
                Test,
                Increment,
                Body,
                location
            );
        }
Ejemplo n.º 7
0
        private BoundBlock BuildBlock(SyntaxNode syntax, SourceLocation location)
        {
            IEnumerable<SyntaxNode> items;
            var block = syntax as BlockSyntax;
            if (block != null)
                items = block.Statements;
            else
                items = new[] { syntax };

            var builder = new BlockBuilder(this);

            foreach (var item in items)
            {
                var node = item.Accept(this);

                var statement =
                    node as BoundStatement ??
                    new BoundExpressionStatement((BoundExpression)node, GetLocation(item));

                builder.Add(statement);
            }

            return builder.BuildBlock(location ?? SourceLocation.Missing);
        }
Ejemplo n.º 8
0
 public DoWhileSyntax BuildDoWhile(ExpressionSyntax condition, SyntaxNode statement, SourceLocation location)
 {
     return new DoWhileSyntax(condition, statement, location);
 }
Ejemplo n.º 9
0
 public ContinueSyntax BuildContinue(string target, SourceLocation location)
 {
     return new ContinueSyntax(target, location);
 }
Ejemplo n.º 10
0
 public BreakSyntax BuildBreak(string target, SourceLocation location)
 {
     return new BreakSyntax(target, location);
 }
Ejemplo n.º 11
0
 public WhileSyntax BuildWhile(ExpressionSyntax test, SyntaxNode body, SourceLocation location)
 {
     return new WhileSyntax(test, body, location);
 }
Ejemplo n.º 12
0
 public VariableDeclarationSyntax BuildVariableDeclaration(ReadOnlyArray<VariableDeclaration> declarations, SourceLocation location)
 {
     return new VariableDeclarationSyntax(declarations, location);
 }
Ejemplo n.º 13
0
 public WithSyntax ExitWith(ExpressionSyntax expression, SyntaxNode body, SourceLocation location)
 {
     return _scope.ExitWith(expression, body, location);
 }
Ejemplo n.º 14
0
 public SyntaxNode BuildForEachIn(IIdentifier identifier, ExpressionSyntax expression, SyntaxNode body, SourceLocation location)
 {
     return new ForEachInSyntax(identifier, expression, body, location);
 }
Ejemplo n.º 15
0
 public ReturnSyntax BuildReturn(ExpressionSyntax expression, SourceLocation location)
 {
     return new ReturnSyntax(expression, location);
 }
Ejemplo n.º 16
0
 public IfSyntax BuildIf(ExpressionSyntax test, SyntaxNode then, SyntaxNode @else, SourceLocation location)
 {
     return new IfSyntax(test, then, @else, location);
 }
Ejemplo n.º 17
0
            public WithSyntax ExitWith(ExpressionSyntax expression, SyntaxNode body, SourceLocation location)
            {
                var result = new WithSyntax(expression, _withScope.WithScope.Identifier, body, location);

                _withScope = _withScope.Parent;

                return result;
            }
Ejemplo n.º 18
0
            public BoundBlock BuildBlock(SourceLocation location)
            {
                if (_nodes == null)
                {
                    Debug.Assert(_temporaries == null);

                    return new BoundBlock(
                        ReadOnlyArray<BoundTemporary>.Empty,
                        ReadOnlyArray<BoundStatement>.Empty,
                        location
                    );
                }

                var nodes = new ReadOnlyArray<BoundStatement>.Builder();

                foreach (var node in _nodes.ToReadOnly())
                {
                    // Flatten blocks. Nested blocks have no use, so we flatten
                    // them into this block. First we try to see whether the node
                    // is a block. If not, we try to see whether the node is an
                    // expression statement that has an expression block
                    // as its expression. In that case, we're taking the value of
                    // an expression block without doing anything with it.

                    var block = node as BoundBlock;
                    if (block != null)
                    {
                        if (_temporaries == null)
                            _temporaries = new ReadOnlyArray<BoundTemporary>.Builder();

                        _temporaries.AddRange(block.Temporaries);
                        if (block.Location != SourceLocation.Missing)
                            nodes.Add(new BoundEmpty(block.Location));
                        nodes.AddRange(block.Nodes);
                        continue;
                    }

                    // Otherwise, we keep the node unchanged.
                    nodes.Add(node);
                }

                return new BoundBlock(
                    _temporaries == null ? ReadOnlyArray<BoundTemporary>.Empty : _temporaries.ToReadOnly(),
                    nodes.ToReadOnly(),
                    location
                );
            }
Ejemplo n.º 19
0
 public BoundExpression BuildExpression(BoundTemporary result, SourceLocation location)
 {
     return new BoundExpressionBlock(
         result,
         new BoundBlock(
             _temporaries == null ? ReadOnlyArray<BoundTemporary>.Empty : _temporaries.ToReadOnly(),
             _nodes == null ? ReadOnlyArray<BoundStatement>.Empty : _nodes.ToReadOnly(),
             location
         )
     );
 }
Ejemplo n.º 20
0
 public ExpressionStatementSyntax BuildExpressionStatement(ExpressionSyntax expression, SourceLocation location)
 {
     return new ExpressionStatementSyntax(expression, location);
 }
Ejemplo n.º 21
0
 public SyntaxNode BuildFor(SyntaxNode initialization, SyntaxNode test, SyntaxNode increment, SyntaxNode body, SourceLocation location)
 {
     return new ForSyntax(initialization, test, increment, body, location);
 }
Ejemplo n.º 22
0
 public SwitchCase BuildSwitchCase(ExpressionSyntax expression, BlockSyntax body, SourceLocation location)
 {
     return new SwitchCase(expression, body, location);
 }
Ejemplo n.º 23
0
 public SwitchSyntax BuildSwitch(SyntaxNode expression, ReadOnlyArray<SwitchCase> cases, SourceLocation location)
 {
     return new SwitchSyntax(expression, cases, location);
 }
Ejemplo n.º 24
0
 public ThrowSyntax BuildThrow(ExpressionSyntax expression, SourceLocation location)
 {
     return new ThrowSyntax(expression, location);
 }