| Index: pkg/compiler/lib/src/dart_backend/backend_ast_nodes.dart
|
| diff --git a/pkg/compiler/lib/src/dart_backend/backend_ast_nodes.dart b/pkg/compiler/lib/src/dart_backend/backend_ast_nodes.dart
|
| index d4e86e623ebe62aacca7652e88277d910159e167..81c17c3894787a82bb3296344334662d0b7388f4 100644
|
| --- a/pkg/compiler/lib/src/dart_backend/backend_ast_nodes.dart
|
| +++ b/pkg/compiler/lib/src/dart_backend/backend_ast_nodes.dart
|
| @@ -68,7 +68,6 @@ class TypeAnnotation extends Node {
|
|
|
| // STATEMENTS
|
|
|
| -
|
| class Block extends Statement {
|
| final List<Statement> statements;
|
|
|
| @@ -108,9 +107,9 @@ class For extends Statement {
|
|
|
| /// Initializer must be [VariableDeclarations] or [Expression] or null.
|
| For(this.initializer, this.condition, this.updates, this.body) {
|
| - assert(initializer == null
|
| - || initializer is VariableDeclarations
|
| - || initializer is Expression);
|
| + assert(initializer == null ||
|
| + initializer is VariableDeclarations ||
|
| + initializer is Expression);
|
| }
|
| }
|
|
|
| @@ -124,10 +123,10 @@ class ForIn extends Statement {
|
| /// initializer.
|
| ForIn(Node leftHandValue, this.expression, this.body)
|
| : this.leftHandValue = leftHandValue {
|
| - assert(leftHandValue is Identifier
|
| - || (leftHandValue is VariableDeclarations
|
| - && leftHandValue.declarations.length == 1
|
| - && leftHandValue.declarations[0].initializer == null));
|
| + assert(leftHandValue is Identifier ||
|
| + (leftHandValue is VariableDeclarations &&
|
| + leftHandValue.declarations.length == 1 &&
|
| + leftHandValue.declarations[0].initializer == null));
|
| }
|
| }
|
|
|
| @@ -160,8 +159,7 @@ class LabeledStatement extends Statement {
|
| LabeledStatement(this.label, this.statement);
|
| }
|
|
|
| -class Rethrow extends Statement {
|
| -}
|
| +class Rethrow extends Statement {}
|
|
|
| class Return extends Statement {
|
| final Expression expression;
|
| @@ -229,9 +227,7 @@ class VariableDeclarations extends Statement {
|
| final List<VariableDeclaration> declarations;
|
|
|
| VariableDeclarations(this.declarations,
|
| - { this.type,
|
| - this.isFinal: false,
|
| - this.isConst: false }) {
|
| + {this.type, this.isFinal: false, this.isConst: false}) {
|
| // Cannot be both final and const.
|
| assert(!isFinal || !isConst);
|
| }
|
| @@ -246,7 +242,6 @@ class VariableDeclaration extends Node {
|
| VariableDeclaration(this.name, [this.initializer]);
|
| }
|
|
|
| -
|
| class FunctionDeclaration extends Statement {
|
| final FunctionExpression function;
|
|
|
| @@ -264,14 +259,13 @@ class Parameters extends Node {
|
| final bool hasNamedParameters;
|
|
|
| Parameters(this.requiredParameters,
|
| - [ this.optionalParameters,
|
| - this.hasNamedParameters = false ]);
|
| + [this.optionalParameters, this.hasNamedParameters = false]);
|
|
|
| Parameters.named(this.requiredParameters, this.optionalParameters)
|
| : hasNamedParameters = true;
|
|
|
| Parameters.positional(this.requiredParameters, this.optionalParameters)
|
| - : hasNamedParameters = false;
|
| + : hasNamedParameters = false;
|
|
|
| bool get hasOptionalParameters =>
|
| optionalParameters != null && optionalParameters.length > 0;
|
| @@ -290,13 +284,11 @@ class Parameter extends Node {
|
|
|
| elements.FormalElement element;
|
|
|
| - Parameter(this.name, {this.type, this.defaultValue})
|
| - : parameters = null;
|
| + Parameter(this.name, {this.type, this.defaultValue}) : parameters = null;
|
|
|
| - Parameter.function(this.name,
|
| - TypeAnnotation returnType,
|
| - this.parameters,
|
| - [ this.defaultValue ]) : type = returnType {
|
| + Parameter.function(this.name, TypeAnnotation returnType, this.parameters,
|
| + [this.defaultValue])
|
| + : type = returnType {
|
| assert(parameters != null);
|
| }
|
|
|
| @@ -332,12 +324,11 @@ class FunctionExpression extends Expression implements RootNode {
|
|
|
| elements.FunctionElement element;
|
|
|
| - FunctionExpression(this.parameters,
|
| - this.body,
|
| - { this.name,
|
| - this.returnType,
|
| - this.isGetter: false,
|
| - this.isSetter: false }) {
|
| + FunctionExpression(this.parameters, this.body,
|
| + {this.name,
|
| + this.returnType,
|
| + this.isGetter: false,
|
| + this.isSetter: false}) {
|
| // Function must have a name if it has a return type
|
| assert(returnType == null || name != null);
|
| }
|
| @@ -348,7 +339,7 @@ class ConstructorDefinition extends FunctionExpression {
|
| final bool isConst;
|
|
|
| ConstructorDefinition(Parameters parameters, Statement body,
|
| - this.initializers, String name, this.isConst)
|
| + this.initializers, String name, this.isConst)
|
| : super(parameters, body, name: name);
|
| }
|
|
|
| @@ -389,7 +380,7 @@ class LiteralList extends Expression {
|
| final TypeAnnotation typeArgument;
|
| final List<Expression> values;
|
|
|
| - LiteralList(this.values, { this.typeArgument, this.isConst: false });
|
| + LiteralList(this.values, {this.typeArgument, this.isConst: false});
|
| }
|
|
|
| class LiteralMap extends Expression {
|
| @@ -397,10 +388,10 @@ class LiteralMap extends Expression {
|
| final List<TypeAnnotation> typeArguments;
|
| final List<LiteralMapEntry> entries;
|
|
|
| - LiteralMap(this.entries, { this.typeArguments, this.isConst: false }) {
|
| - assert(this.typeArguments == null
|
| - || this.typeArguments.length == 0
|
| - || this.typeArguments.length == 2);
|
| + LiteralMap(this.entries, {this.typeArguments, this.isConst: false}) {
|
| + assert(this.typeArguments == null ||
|
| + this.typeArguments.length == 0 ||
|
| + this.typeArguments.length == 2);
|
| }
|
| }
|
|
|
| @@ -504,10 +495,8 @@ class CallNew extends Expression {
|
| elements.FunctionElement constructor;
|
| types.DartType dartType;
|
|
|
| - CallNew(this.type,
|
| - this.arguments,
|
| - { this.constructorName,
|
| - this.isConst: false });
|
| + CallNew(this.type, this.arguments,
|
| + {this.constructorName, this.isConst: false});
|
| }
|
|
|
| /// Expression of form `T.f(..)`.
|
| @@ -550,9 +539,7 @@ class TypeOperator extends Expression {
|
| final TypeAnnotation type;
|
|
|
| TypeOperator(this.expression, this.operator, this.type) {
|
| - assert(operator == 'is'
|
| - || operator == 'as'
|
| - || operator == 'is!');
|
| + assert(operator == 'is' || operator == 'as' || operator == 'is!');
|
| }
|
| }
|
|
|
| @@ -574,9 +561,20 @@ class Increment extends Expression {
|
| }
|
|
|
| class Assignment extends Expression {
|
| - static final _operators =
|
| - new Set.from(['=', '|=', '^=', '&=', '<<=', '>>=',
|
| - '+=', '-=', '*=', '/=', '%=', '~/=']);
|
| + static final _operators = new Set.from([
|
| + '=',
|
| + '|=',
|
| + '^=',
|
| + '&=',
|
| + '<<=',
|
| + '>>=',
|
| + '+=',
|
| + '-=',
|
| + '*=',
|
| + '/=',
|
| + '%=',
|
| + '~/='
|
| + ]);
|
|
|
| final Expression left;
|
| final String operator;
|
| @@ -606,9 +604,11 @@ class This extends Expression {
|
| bool isUnaryOperator(String op) {
|
| return op == '!' || op == '-' || op == '~';
|
| }
|
| +
|
| bool isBinaryOperator(String op) {
|
| return BINARY_PRECEDENCE.containsKey(op);
|
| }
|
| +
|
| /// True if the given operator can be converted to a compound assignment.
|
| bool isCompoundableOperator(String op) {
|
| switch (BINARY_PRECEDENCE[op]) {
|
| @@ -624,7 +624,6 @@ bool isCompoundableOperator(String op) {
|
| }
|
| }
|
|
|
| -
|
| // Precedence levels
|
| const int EXPRESSION = 1;
|
| const int CONDITIONAL = 2;
|
| @@ -646,28 +645,22 @@ const int PRIMARY = 20;
|
| /// Precedence level required for the callee in a [FunctionCall].
|
| const int CALLEE = 21;
|
|
|
| -const Map<String,int> BINARY_PRECEDENCE = const {
|
| +const Map<String, int> BINARY_PRECEDENCE = const {
|
| '&&': LOGICAL_AND,
|
| '||': LOGICAL_OR,
|
| -
|
| '==': EQUALITY,
|
| '!=': EQUALITY,
|
| -
|
| '>': RELATIONAL,
|
| '>=': RELATIONAL,
|
| '<': RELATIONAL,
|
| '<=': RELATIONAL,
|
| -
|
| '|': BITWISE_OR,
|
| '^': BITWISE_XOR,
|
| '&': BITWISE_AND,
|
| -
|
| '>>': SHIFT,
|
| '<<': SHIFT,
|
| -
|
| '+': ADDITIVE,
|
| '-': ADDITIVE,
|
| -
|
| '*': MULTIPLICATIVE,
|
| '%': MULTIPLICATIVE,
|
| '/': MULTIPLICATIVE,
|
| @@ -687,9 +680,9 @@ bool isIdentifierPartNoDollar(dynamic x) {
|
| return false;
|
| }
|
| return (characters.$0 <= x && x <= characters.$9) ||
|
| - (characters.$A <= x && x <= characters.$Z) ||
|
| - (characters.$a <= x && x <= characters.$z) ||
|
| - (x == characters.$_);
|
| + (characters.$A <= x && x <= characters.$Z) ||
|
| + (characters.$a <= x && x <= characters.$z) ||
|
| + (x == characters.$_);
|
| }
|
|
|
| /// The unparser will apply the following syntactic rewritings:
|
| @@ -727,7 +720,6 @@ class Unparser {
|
|
|
| Unparser(this.output);
|
|
|
| -
|
| void write(String s) {
|
| output.write(s);
|
| }
|
| @@ -786,7 +778,7 @@ class Unparser {
|
| /// using parentheses if necessary to raise the precedence level.
|
| /// Abusing terminology slightly, the function accepts a [Receiver] which
|
| /// may also be the [SuperReceiver] object.
|
| - void writeExp(Receiver e, int minPrecedence, {beginStmt:false}) {
|
| + void writeExp(Receiver e, int minPrecedence, {beginStmt: false}) {
|
| void withPrecedence(int actual, void action()) {
|
| if (actual < minPrecedence) {
|
| write("(");
|
| @@ -842,8 +834,7 @@ class Unparser {
|
| } else if (e is Literal) {
|
| if (e.value.isString) {
|
| writeStringLiteral(e);
|
| - }
|
| - else if (e.value.isDouble) {
|
| + } else if (e.value.isDouble) {
|
| double v = e.value.primitiveValue;
|
| if (v == double.INFINITY) {
|
| withPrecedence(MULTIPLICATIVE, () {
|
| @@ -875,8 +866,7 @@ class Unparser {
|
| write('[');
|
| writeEach(',', e.values, writeExpression);
|
| write(']');
|
| - }
|
| - else if (e is LiteralMap) {
|
| + } else if (e is LiteralMap) {
|
| // The curly brace can be mistaken for a block statement if we
|
| // are at the beginning of a statement.
|
| bool needParen = beginStmt;
|
| @@ -920,7 +910,8 @@ class Unparser {
|
| Receiver operand = e.operand;
|
| // !(x == y) ==> x != y.
|
| if (e.operatorName == '!' &&
|
| - operand is BinaryOperator && operand.operator == '==') {
|
| + operand is BinaryOperator &&
|
| + operand.operator == '==') {
|
| withPrecedence(EQUALITY, () {
|
| writeExp(operand.left, RELATIONAL);
|
| writeOperator('!=');
|
| @@ -929,14 +920,14 @@ class Unparser {
|
| }
|
| // !(x is T) ==> x is!T
|
| else if (e.operatorName == '!' &&
|
| - operand is TypeOperator && operand.operator == 'is') {
|
| + operand is TypeOperator &&
|
| + operand.operator == 'is') {
|
| withPrecedence(RELATIONAL, () {
|
| writeExp(operand.expression, BITWISE_OR, beginStmt: beginStmt);
|
| write(' is!');
|
| writeType(operand.type);
|
| });
|
| - }
|
| - else {
|
| + } else {
|
| withPrecedence(UNARY, () {
|
| writeOperator(e.operatorName);
|
| writeExp(e.operand, UNARY);
|
| @@ -1100,7 +1091,7 @@ class Unparser {
|
| } else if (stmt is EmptyStatement) {
|
| write(';');
|
| } else if (stmt is ExpressionStatement) {
|
| - writeExp(stmt.expression, EXPRESSION, beginStmt:true);
|
| + writeExp(stmt.expression, EXPRESSION, beginStmt: true);
|
| write(';');
|
| } else if (stmt is For) {
|
| write('for(');
|
| @@ -1246,8 +1237,7 @@ class Unparser {
|
| void writeVariableDefinitions(VariableDeclarations vds) {
|
| if (vds.isConst)
|
| write('const ');
|
| - else if (vds.isFinal)
|
| - write('final ');
|
| + else if (vds.isFinal) write('final ');
|
| if (vds.type != null) {
|
| writeType(vds.type);
|
| write(' ');
|
| @@ -1307,10 +1297,10 @@ class Unparser {
|
| // Ignore multiline quotings for now. Would need to make sure that no
|
| // newline (potentially prefixed by whitespace) follows the quoting.
|
| static const _QUOTINGS = const <tree.StringQuoting>[
|
| - const tree.StringQuoting(characters.$DQ, raw: false, leftQuoteLength: 1),
|
| - const tree.StringQuoting(characters.$DQ, raw: true, leftQuoteLength: 1),
|
| - const tree.StringQuoting(characters.$SQ, raw: false, leftQuoteLength: 1),
|
| - const tree.StringQuoting(characters.$SQ, raw: true, leftQuoteLength: 1),
|
| + const tree.StringQuoting(characters.$DQ, raw: false, leftQuoteLength: 1),
|
| + const tree.StringQuoting(characters.$DQ, raw: true, leftQuoteLength: 1),
|
| + const tree.StringQuoting(characters.$SQ, raw: false, leftQuoteLength: 1),
|
| + const tree.StringQuoting(characters.$SQ, raw: true, leftQuoteLength: 1),
|
| ];
|
|
|
| static StringLiteralOutput analyzeStringLiteral(Expression node) {
|
| @@ -1371,24 +1361,20 @@ class Unparser {
|
| }
|
| }
|
|
|
| -
|
| /// Applies additional cost to each track in [penalized], and considers
|
| /// switching from each [penalized] to a [nonPenalized] track.
|
| - void penalize(List<int> penalized,
|
| - List<int> nonPenalized,
|
| - int endIndex,
|
| - num cost(tree.StringQuoting q)) {
|
| + void penalize(List<int> penalized, List<int> nonPenalized, int endIndex,
|
| + num cost(tree.StringQuoting q)) {
|
| for (int j in penalized) {
|
| // Check if another track can benefit from switching from this track.
|
| for (int k in nonPenalized) {
|
| - num newCost = best[j].cost
|
| - + 1 // Whitespace in string juxtaposition
|
| - + getQuoteCost(best[k].quoting);
|
| + num newCost = best[j].cost +
|
| + 1 // Whitespace in string juxtaposition
|
| + +
|
| + getQuoteCost(best[k].quoting);
|
| if (newCost < best[k].cost) {
|
| best[k] = new OpenStringChunk(
|
| - best[j].end(endIndex),
|
| - best[k].quoting,
|
| - newCost);
|
| + best[j].end(endIndex), best[k].quoting, newCost);
|
| }
|
| }
|
| best[j].cost += cost(best[j].quoting);
|
| @@ -1433,18 +1419,18 @@ class Unparser {
|
| if (part is Identifier &&
|
| !part.name.contains(r'$') &&
|
| i + 1 < parts.length &&
|
| - isIdentifierPartNoDollar(parts[i+1])) {
|
| + isIdentifierPartNoDollar(parts[i + 1])) {
|
| for (int j in nonRaws) {
|
| for (int k = 0; k < best.length; k++) {
|
| - num newCost = best[j].cost
|
| - + 1 // Whitespace in string juxtaposition
|
| - - 2 // Save two curly braces
|
| - + getQuoteCost(best[k].quoting);
|
| + num newCost = best[j].cost +
|
| + 1 // Whitespace in string juxtaposition
|
| + -
|
| + 2 // Save two curly braces
|
| + +
|
| + getQuoteCost(best[k].quoting);
|
| if (newCost < best[k].cost) {
|
| best[k] = new OpenStringChunk(
|
| - best[j].end(i+1),
|
| - best[k].quoting,
|
| - newCost);
|
| + best[j].end(i + 1), best[k].quoting, newCost);
|
| }
|
| }
|
| }
|
| @@ -1481,15 +1467,15 @@ class Unparser {
|
| write(chunk.quoting.quoteChar);
|
| bool raw = chunk.quoting.raw;
|
| int quoteCode = chunk.quoting.quote;
|
| - for (int i=startIndex; i<chunk.endIndex; i++) {
|
| + for (int i = startIndex; i < chunk.endIndex; i++) {
|
| var part = parts[i];
|
| if (part is int) {
|
| int char = part;
|
| write(getEscapedCharacter(char, quoteCode, raw));
|
| } else if (part is Identifier &&
|
| - !part.name.contains(r'$') &&
|
| - (i == chunk.endIndex - 1 ||
|
| - !isIdentifierPartNoDollar(parts[i+1]))) {
|
| + !part.name.contains(r'$') &&
|
| + (i == chunk.endIndex - 1 ||
|
| + !isIdentifierPartNoDollar(parts[i + 1]))) {
|
| write(r'$');
|
| write(part.name);
|
| } else {
|
| @@ -1531,7 +1517,6 @@ class Unparser {
|
| return new String.fromCharCode(char);
|
| }
|
| }
|
| -
|
| }
|
|
|
| /// The contents of a string literal together with a strategy for printing it.
|
| @@ -1544,7 +1529,6 @@ class StringLiteralOutput {
|
| StringLiteralOutput(this.parts, this.chunk);
|
| }
|
|
|
| -
|
| /// Strategy for printing a prefix of a string literal.
|
| /// A chunk represents the substring going from [:previous.endIndex:] to
|
| /// [endIndex] (or from 0 to [endIndex] if [previous] is null).
|
|
|