Chromium Code Reviews| Index: sdk/lib/_internal/compiler/implementation/js/nodes.dart |
| diff --git a/sdk/lib/_internal/compiler/implementation/js/nodes.dart b/sdk/lib/_internal/compiler/implementation/js/nodes.dart |
| index 93d1f5ecb735a5b3e47353ce0c14eb03b132bb11..36c18f5bceb613f92e63d453e92b3d1ab3d135aa 100644 |
| --- a/sdk/lib/_internal/compiler/implementation/js/nodes.dart |
| +++ b/sdk/lib/_internal/compiler/implementation/js/nodes.dart |
| @@ -170,11 +170,30 @@ class BaseVisitor<T> implements NodeVisitor<T> { |
| } |
| abstract class Node { |
| - var sourcePosition; |
| - var endSourcePosition; |
| + get sourcePosition => _sourcePosition; |
| + get endSourcePosition => _endSourcePosition; |
| + |
| + var _sourcePosition; |
| + var _endSourcePosition; |
| accept(NodeVisitor visitor); |
| void visitChildren(NodeVisitor visitor); |
| + Node _clone(); // Single node clone |
|
floitsch
2014/04/28 12:28:11
Comment.
Does it need to clone positions?...
sra1
2014/04/28 18:24:09
No, because it is used only by code that sets the
floitsch
2014/04/30 15:36:01
I got it (reading the source). Just wanted you to
|
| + |
| + Node withPosition(var sourcePosition, var endSourcePosition) { |
|
floitsch
2014/04/28 12:28:11
comments.
sra1
2014/04/28 18:24:09
Done.
|
| + if (sourcePosition == _sourcePosition && |
| + endSourcePosition == _endSourcePosition) { |
| + return this; |
| + } |
| + Node clone = _clone(); |
| + // TODO(sra): Should existing data be 'sticky' if we overwrite with `null`? |
| + clone._sourcePosition = sourcePosition; |
| + clone._endSourcePosition = endSourcePosition; |
| + return clone; |
| + } |
| + |
| + Node withLocation(var sourcePosition) => |
|
floitsch
2014/04/28 12:28:11
comments.
In particular differentiating Position/L
sra1
2014/04/28 18:24:09
Done.
|
| + withPosition(sourcePosition, this.endSourcePosition); |
| VariableUse asVariableUse() => null; |
| @@ -191,10 +210,14 @@ class Program extends Node { |
| void visitChildren(NodeVisitor visitor) { |
| for (Statement statement in body) statement.accept(visitor); |
| } |
| + Program _clone() => new Program(body); |
| } |
| abstract class Statement extends Node { |
| Statement toStatement() => this; |
| + |
| + Statement withPosition(var sourcePosition, var endSourcePosition) => |
| + super.withPosition(sourcePosition, endSourcePosition); |
| } |
| class Block extends Statement { |
| @@ -206,6 +229,7 @@ class Block extends Statement { |
| void visitChildren(NodeVisitor visitor) { |
| for (Statement statement in statements) statement.accept(visitor); |
| } |
| + Block _clone() => new Block(statements); |
| } |
| class ExpressionStatement extends Statement { |
| @@ -214,6 +238,7 @@ class ExpressionStatement extends Statement { |
| accept(NodeVisitor visitor) => visitor.visitExpressionStatement(this); |
| void visitChildren(NodeVisitor visitor) { expression.accept(visitor); } |
| + ExpressionStatement _clone() => new ExpressionStatement(expression); |
| } |
| class EmptyStatement extends Statement { |
| @@ -221,6 +246,7 @@ class EmptyStatement extends Statement { |
| accept(NodeVisitor visitor) => visitor.visitEmptyStatement(this); |
| void visitChildren(NodeVisitor visitor) {} |
| + EmptyStatement _clone() => new EmptyStatement(); |
| } |
| class If extends Statement { |
| @@ -240,6 +266,8 @@ class If extends Statement { |
| then.accept(visitor); |
| otherwise.accept(visitor); |
| } |
| + |
| + If _clone() => new If(condition, then, otherwise); |
| } |
| abstract class Loop extends Statement { |
| @@ -262,6 +290,8 @@ class For extends Loop { |
| if (update != null) update.accept(visitor); |
| body.accept(visitor); |
| } |
| + |
| + For _clone() => new For(init, condition, update, body); |
| } |
| class ForIn extends Loop { |
| @@ -279,6 +309,8 @@ class ForIn extends Loop { |
| object.accept(visitor); |
| body.accept(visitor); |
| } |
| + |
| + ForIn _clone() => new ForIn(leftHandSide, object, body); |
| } |
| class While extends Loop { |
| @@ -292,6 +324,8 @@ class While extends Loop { |
| condition.accept(visitor); |
| body.accept(visitor); |
| } |
| + |
| + While _clone() => new While(condition, body); |
| } |
| class Do extends Loop { |
| @@ -305,6 +339,8 @@ class Do extends Loop { |
| body.accept(visitor); |
| condition.accept(visitor); |
| } |
| + |
| + Do _clone() => new Do(body, condition); |
| } |
| class Continue extends Statement { |
| @@ -314,6 +350,8 @@ class Continue extends Statement { |
| accept(NodeVisitor visitor) => visitor.visitContinue(this); |
| void visitChildren(NodeVisitor visitor) {} |
| + |
| + Continue _clone() => new Continue(targetLabel); |
| } |
| class Break extends Statement { |
| @@ -323,6 +361,8 @@ class Break extends Statement { |
| accept(NodeVisitor visitor) => visitor.visitBreak(this); |
| void visitChildren(NodeVisitor visitor) {} |
| + |
| + Break _clone() => new Break(targetLabel); |
| } |
| class Return extends Statement { |
| @@ -335,6 +375,8 @@ class Return extends Statement { |
| void visitChildren(NodeVisitor visitor) { |
| if (value != null) value.accept(visitor); |
| } |
| + |
| + Return _clone() => new Return(value); |
| } |
| class Throw extends Statement { |
| @@ -347,6 +389,8 @@ class Throw extends Statement { |
| void visitChildren(NodeVisitor visitor) { |
| expression.accept(visitor); |
| } |
| + |
| + Throw _clone() => new Throw(expression); |
| } |
| class Try extends Statement { |
| @@ -365,6 +409,8 @@ class Try extends Statement { |
| if (catchPart != null) catchPart.accept(visitor); |
| if (finallyPart != null) finallyPart.accept(visitor); |
| } |
| + |
| + Try _clone() => new Try(body, catchPart, finallyPart); |
| } |
| class Catch extends Node { |
| @@ -379,6 +425,8 @@ class Catch extends Node { |
| declaration.accept(visitor); |
| body.accept(visitor); |
| } |
| + |
| + Catch _clone() => new Catch(declaration, body); |
| } |
| class Switch extends Statement { |
| @@ -393,12 +441,16 @@ class Switch extends Statement { |
| key.accept(visitor); |
| for (SwitchClause clause in cases) clause.accept(visitor); |
| } |
| + |
| + Switch _clone() => new Switch(key, cases); |
| } |
| abstract class SwitchClause extends Node { |
| final Block body; |
| SwitchClause(this.body); |
| + |
| + SwitchClause _clone() => new SwitchClause(body); |
| } |
| class Case extends SwitchClause { |
| @@ -412,6 +464,8 @@ class Case extends SwitchClause { |
| expression.accept(visitor); |
| body.accept(visitor); |
| } |
| + |
| + Case _clone() => new Case(expression, body); |
| } |
| class Default extends SwitchClause { |
| @@ -422,6 +476,8 @@ class Default extends SwitchClause { |
| void visitChildren(NodeVisitor visitor) { |
| body.accept(visitor); |
| } |
| + |
| + Default _clone() => new Default(body); |
| } |
| class FunctionDeclaration extends Statement { |
| @@ -436,6 +492,8 @@ class FunctionDeclaration extends Statement { |
| name.accept(visitor); |
| function.accept(visitor); |
| } |
| + |
| + FunctionDeclaration _clone() => new FunctionDeclaration(name, function); |
| } |
| class LabeledStatement extends Statement { |
| @@ -449,6 +507,8 @@ class LabeledStatement extends Statement { |
| void visitChildren(NodeVisitor visitor) { |
| body.accept(visitor); |
| } |
| + |
| + LabeledStatement _clone() => new LabeledStatement(label, body); |
| } |
| class LiteralStatement extends Statement { |
| @@ -458,12 +518,17 @@ class LiteralStatement extends Statement { |
| accept(NodeVisitor visitor) => visitor.visitLiteralStatement(this); |
| void visitChildren(NodeVisitor visitor) { } |
| + |
| + LiteralStatement _clone() => new LiteralStatement(code); |
| } |
| abstract class Expression extends Node { |
| int get precedenceLevel; |
| Statement toStatement() => new ExpressionStatement(this); |
| + |
| + Expression withPosition(var sourcePosition, var endSourcePosition) => |
| + super.withPosition(sourcePosition, endSourcePosition); |
| } |
| /// Wrap a CodeBuffer as an expression. |
| @@ -479,7 +544,10 @@ class Blob extends Expression { |
| void visitChildren(NodeVisitor visitor) {} |
| + Blob _clone() => new Blob(buffer); |
| + |
| int get precedenceLevel => PRIMARY; |
| + |
| } |
| class LiteralExpression extends Expression { |
| @@ -497,6 +565,8 @@ class LiteralExpression extends Expression { |
| } |
| } |
| + LiteralExpression _clone() => new LiteralExpression(template, inputs); |
| + |
| // Code that uses JS must take care of operator precedences, and |
| // put parenthesis if needed. |
| int get precedenceLevel => PRIMARY; |
| @@ -519,6 +589,8 @@ class VariableDeclarationList extends Expression { |
| } |
| } |
| + VariableDeclarationList _clone() => new VariableDeclarationList(declarations); |
| + |
| int get precedenceLevel => EXPRESSION; |
| } |
| @@ -533,6 +605,8 @@ class Sequence extends Expression { |
| for (Expression expr in expressions) expr.accept(visitor); |
| } |
| + Sequence _clone() => new Sequence(expressions); |
| + |
| int get precedenceLevel => EXPRESSION; |
| } |
| @@ -560,6 +634,9 @@ class Assignment extends Expression { |
| if (compoundTarget != null) compoundTarget.accept(visitor); |
| if (value != null) value.accept(visitor); |
| } |
| + |
| + Assignment _clone() => |
| + new Assignment._internal(leftHandSide, compoundTarget, value); |
| } |
| class VariableInitialization extends Assignment { |
| @@ -570,6 +647,9 @@ class VariableInitialization extends Assignment { |
| VariableDeclaration get declaration => leftHandSide; |
| accept(NodeVisitor visitor) => visitor.visitVariableInitialization(this); |
| + |
| + VariableInitialization _clone() => |
| + new VariableInitialization(declaration, value); |
| } |
| class Conditional extends Expression { |
| @@ -587,6 +667,8 @@ class Conditional extends Expression { |
| otherwise.accept(visitor); |
| } |
| + Conditional _clone() => new Conditional(condition, then, otherwise); |
| + |
| int get precedenceLevel => ASSIGNMENT; |
| } |
| @@ -603,6 +685,8 @@ class Call extends Expression { |
| for (Expression arg in arguments) arg.accept(visitor); |
| } |
| + Call _clone() => new Call(target, arguments); |
| + |
| int get precedenceLevel => CALL; |
| } |
| @@ -610,11 +694,16 @@ class New extends Call { |
| New(Expression cls, List<Expression> arguments) : super(cls, arguments); |
| accept(NodeVisitor visitor) => visitor.visitNew(this); |
| + |
| + New _clone() => new New(cls, arguments); |
| } |
| class Binary extends Call { |
| Binary(String op, Expression left, Expression right) |
| - : super(new VariableUse(op), <Expression>[left, right]); |
| + : this._internal(new VariableUse(op), <Expression>[left, right]); |
| + |
| + Binary._internal(Expression target, List<Expression> arguments) |
| + : super(target, arguments); |
| String get op { |
| VariableUse use = target; |
| @@ -626,6 +715,8 @@ class Binary extends Call { |
| accept(NodeVisitor visitor) => visitor.visitBinary(this); |
| + Binary _clone() => new Binary._internal(target, arguments); |
| + |
| int get precedenceLevel { |
| // TODO(floitsch): switch to constant map. |
| switch (op) { |
| @@ -673,25 +764,35 @@ class Binary extends Call { |
| class Prefix extends Call { |
| Prefix(String op, Expression arg) |
| - : super(new VariableUse(op), <Expression>[arg]); |
| + : this._internal(new VariableUse(op), <Expression>[arg]); |
| + |
| + Prefix._internal(Expression target, List<xpression> arguments) |
|
floitsch
2014/04/28 12:28:11
Expression.
sra1
2014/04/28 18:24:09
Done.
|
| + : super(target, arguments); |
| String get op => (target as VariableUse).name; |
| Expression get argument => arguments[0]; |
| accept(NodeVisitor visitor) => visitor.visitPrefix(this); |
| + Prefix _clone() => new Prefix._internal(target, arguments); |
| + |
| int get precedenceLevel => UNARY; |
| } |
| class Postfix extends Call { |
| Postfix(String op, Expression arg) |
| - : super(new VariableUse(op), <Expression>[arg]); |
| + : this._internal(new VariableUse(op), <Expression>[arg]); |
| + |
| + Postfix._internal(Expression target, List<xpression> arguments) |
|
floitsch
2014/04/28 12:28:11
Expression
sra1
2014/04/28 18:24:09
Done.
|
| + : super(target, arguments); |
| String get op => (target as VariableUse).name; |
| Expression get argument => arguments[0]; |
| accept(NodeVisitor visitor) => visitor.visitPostfix(this); |
| + Prefix _clone() => new Postfix._internal(target, arguments); |
| + |
| int get precedenceLevel => UNARY; |
| } |
| @@ -711,26 +812,32 @@ class VariableUse extends VariableReference { |
| VariableUse(String name) : super(name); |
| accept(NodeVisitor visitor) => visitor.visitVariableUse(this); |
| + VariableUse _clone() => new VariableUse(name); |
| VariableUse asVariableUse() => this; |
| + |
| + toString() => 'VariableUse($name)'; |
| } |
| class VariableDeclaration extends VariableReference { |
| VariableDeclaration(String name) : super(name); |
| accept(NodeVisitor visitor) => visitor.visitVariableDeclaration(this); |
| + VariableDeclaration _clone() => new VariableDeclaration(name); |
| } |
| class Parameter extends VariableDeclaration { |
| Parameter(String id) : super(id); |
| accept(NodeVisitor visitor) => visitor.visitParameter(this); |
| + Parameter _clone() => new Parameter(name); |
| } |
| class This extends Parameter { |
| This() : super("this"); |
| accept(NodeVisitor visitor) => visitor.visitThis(this); |
| + This _clone() => new This(); |
| } |
| class NamedFunction extends Expression { |
| @@ -745,6 +852,7 @@ class NamedFunction extends Expression { |
| name.accept(visitor); |
| function.accept(visitor); |
| } |
| + NamedFunction _clone() => new NamedFunction(name, function); |
| int get precedenceLevel => CALL; |
| } |
| @@ -762,6 +870,8 @@ class Fun extends Expression { |
| body.accept(visitor); |
| } |
| + Fun _clone() => new Fun(params, body); |
| + |
| int get precedenceLevel => CALL; |
| } |
| @@ -782,6 +892,8 @@ class PropertyAccess extends Expression { |
| selector.accept(visitor); |
| } |
| + PropertyAccess _clone() => new PropertyAccess(receiver, selector); |
| + |
| int get precedenceLevel => CALL; |
| } |
| @@ -798,12 +910,14 @@ class LiteralBool extends Literal { |
| accept(NodeVisitor visitor) => visitor.visitLiteralBool(this); |
| // [visitChildren] inherited from [Literal]. |
| + LiteralBool _clone() => new LiteralBool(value); |
| } |
| class LiteralNull extends Literal { |
| LiteralNull(); |
| accept(NodeVisitor visitor) => visitor.visitLiteralNull(this); |
| + LiteralNull _clone() => new LiteralNull(); |
| } |
| class LiteralString extends Literal { |
| @@ -819,6 +933,7 @@ class LiteralString extends Literal { |
| LiteralString(this.value); |
| accept(NodeVisitor visitor) => visitor.visitLiteralString(this); |
| + LiteralString _clone() => new LiteralString(value); |
| } |
| class LiteralNumber extends Literal { |
| @@ -827,6 +942,7 @@ class LiteralNumber extends Literal { |
| LiteralNumber(this.value); |
| accept(NodeVisitor visitor) => visitor.visitLiteralNumber(this); |
| + LiteralNumber _clone() => new LiteralNumber(value); |
| } |
| class ArrayInitializer extends Expression { |
| @@ -846,6 +962,8 @@ class ArrayInitializer extends Expression { |
| for (ArrayElement element in elements) element.accept(visitor); |
| } |
| + ArrayInitializer _clone() => new ArrayInitializer(length, elements); |
| + |
| int get precedenceLevel => PRIMARY; |
| static List<ArrayElement> _convert(Iterable<Expression> expressions) { |
| @@ -861,8 +979,8 @@ class ArrayInitializer extends Expression { |
| * its position in the containing [ArrayInitializer]. |
| */ |
| class ArrayElement extends Node { |
| - int index; |
| - Expression value; |
| + final int index; |
| + final Expression value; |
| ArrayElement(this.index, this.value); |
| @@ -871,11 +989,13 @@ class ArrayElement extends Node { |
| void visitChildren(NodeVisitor visitor) { |
| value.accept(visitor); |
| } |
| + |
| + ArrayElement _clone() => new ArrayElement(index, value); |
| } |
| class ObjectInitializer extends Expression { |
| - List<Property> properties; |
| - bool isOneLiner; |
| + final List<Property> properties; |
| + final bool isOneLiner; |
| /** |
| * Constructs a new object-initializer containing the given [properties]. |
| @@ -892,12 +1012,15 @@ class ObjectInitializer extends Expression { |
| for (Property init in properties) init.accept(visitor); |
| } |
| + ObjectInitializer _clone() => |
| + new ObjectInitializer(properties, isOneLiner: isOneLiner); |
| + |
| int get precedenceLevel => PRIMARY; |
| } |
| class Property extends Node { |
| - Literal name; |
| - Expression value; |
| + final Literal name; |
| + final Expression value; |
| Property(this.name, this.value); |
| @@ -907,6 +1030,8 @@ class Property extends Node { |
| name.accept(visitor); |
| value.accept(visitor); |
| } |
| + |
| + Property _clone() => new Property(name, value); |
| } |
| /// Tag class for all interpolated positions. |
| @@ -921,6 +1046,7 @@ class InterpolatedExpression extends Expression implements InterpolatedNode { |
| accept(NodeVisitor visitor) => visitor.visitInterpolatedExpression(this); |
| void visitChildren(NodeVisitor visitor) {} |
| + InterpolatedExpression _clone() => new InterpolatedExpression(name); |
| int get precedenceLevel => PRIMARY; |
| } |
| @@ -932,6 +1058,7 @@ class InterpolatedLiteral extends Literal implements InterpolatedNode { |
| accept(NodeVisitor visitor) => visitor.visitInterpolatedLiteral(this); |
| void visitChildren(NodeVisitor visitor) {} |
| + InterpolatedLiteral _clone() => new InterpolatedLiteral(name); |
| } |
| class InterpolatedParameter extends Expression |
| @@ -942,6 +1069,7 @@ class InterpolatedParameter extends Expression |
| accept(NodeVisitor visitor) => visitor.visitInterpolatedParameter(this); |
| void visitChildren(NodeVisitor visitor) {} |
| + InterpolatedParameter _clone() => new InterpolatedParameter(name); |
| int get precedenceLevel => PRIMARY; |
| } |
| @@ -953,6 +1081,7 @@ class InterpolatedSelector extends Expression implements InterpolatedNode { |
| accept(NodeVisitor visitor) => visitor.visitInterpolatedSelector(this); |
| void visitChildren(NodeVisitor visitor) {} |
| + InterpolatedSelector _clone() => new InterpolatedSelector(name); |
| int get precedenceLevel => PRIMARY; |
| } |
| @@ -964,6 +1093,7 @@ class InterpolatedStatement extends Statement implements InterpolatedNode { |
| accept(NodeVisitor visitor) => visitor.visitInterpolatedStatement(this); |
| void visitChildren(NodeVisitor visitor) {} |
| + InterpolatedStatement _clone() => new InterpolatedStatement(name); |
| } |
| /** |
| @@ -973,12 +1103,13 @@ class InterpolatedStatement extends Statement implements InterpolatedNode { |
| */ |
| class RegExpLiteral extends Expression { |
| /** Contains the pattern and the flags.*/ |
| - String pattern; |
| + final String pattern; |
| RegExpLiteral(this.pattern); |
| accept(NodeVisitor visitor) => visitor.visitRegExpLiteral(this); |
| void visitChildren(NodeVisitor visitor) {} |
| + RegExpLiteral _clone() => new RegExpLiteral(pattern); |
| int get precedenceLevel => PRIMARY; |
| } |
| @@ -995,6 +1126,7 @@ class Comment extends Statement { |
| Comment(this.comment); |
| accept(NodeVisitor visitor) => visitor.visitComment(this); |
| + Comment _clone() => new Comment(comment); |
| void visitChildren(NodeVisitor visitor) {} |
| } |