Index: pkg/compiler/lib/src/resolution/enum_creator.dart |
diff --git a/pkg/compiler/lib/src/resolution/enum_creator.dart b/pkg/compiler/lib/src/resolution/enum_creator.dart |
index 953225b188fcfcbb69746202c253045a29c1794d..9b106ad304a2ebbde76160a88e6f8aa9c7bfbf0a 100644 |
--- a/pkg/compiler/lib/src/resolution/enum_creator.dart |
+++ b/pkg/compiler/lib/src/resolution/enum_creator.dart |
@@ -5,13 +5,11 @@ |
library dart2js.resolution.enum_creator; |
import '../common.dart'; |
-import '../core_types.dart' show |
- CoreTypes; |
+import '../core_types.dart' show CoreTypes; |
import '../dart_types.dart'; |
import '../elements/elements.dart'; |
import '../elements/modelx.dart'; |
-import '../tokens/keyword.dart' show |
- Keyword; |
+import '../tokens/keyword.dart' show Keyword; |
import '../tokens/precedence.dart'; |
import '../tokens/precedence_constants.dart' as Precedence; |
import '../tokens/token.dart'; |
@@ -24,9 +22,8 @@ class AstBuilder { |
AstBuilder(this.charOffset); |
- Modifiers modifiers({bool isConst: false, |
- bool isFinal: false, |
- bool isStatic: false}) { |
+ Modifiers modifiers( |
+ {bool isConst: false, bool isFinal: false, bool isStatic: false}) { |
List identifiers = []; |
int flags = 0; |
if (isConst) { |
@@ -42,8 +39,7 @@ class AstBuilder { |
flags |= Modifiers.FLAG_STATIC; |
} |
return new Modifiers.withFlags( |
- new NodeList(null, linkedList(identifiers), null, ''), |
- flags); |
+ new NodeList(null, linkedList(identifiers), null, ''), flags); |
} |
Token keywordToken(String text) { |
@@ -78,23 +74,17 @@ class AstBuilder { |
NodeList argumentList(List<Node> nodes) { |
return new NodeList(symbolToken(Precedence.OPEN_PAREN_INFO), |
- linkedList(nodes), |
- symbolToken(Precedence.CLOSE_PAREN_INFO), |
- ','); |
+ linkedList(nodes), symbolToken(Precedence.CLOSE_PAREN_INFO), ','); |
} |
Return returnStatement(Expression expression) { |
- return new Return( |
- keywordToken('return'), |
- symbolToken(Precedence.SEMICOLON_INFO), |
- expression); |
+ return new Return(keywordToken('return'), |
+ symbolToken(Precedence.SEMICOLON_INFO), expression); |
} |
- FunctionExpression functionExpression(Modifiers modifiers, |
- String name, |
- NodeList argumentList, |
- Statement body, |
- [TypeAnnotation returnType]) { |
+ FunctionExpression functionExpression( |
+ Modifiers modifiers, String name, NodeList argumentList, Statement body, |
+ [TypeAnnotation returnType]) { |
return new FunctionExpression( |
identifier(name), |
argumentList, |
@@ -103,7 +93,7 @@ class AstBuilder { |
modifiers, |
null, // Initializer. |
null, // get/set. |
- null // Async modifier. |
+ null // Async modifier. |
); |
} |
@@ -116,27 +106,29 @@ class AstBuilder { |
} |
LiteralString literalString(String text, |
- {String prefix: '"', |
- String suffix: '"'}) { |
- return new LiteralString(stringToken('$prefix$text$suffix'), |
- new DartString.literal(text)); |
+ {String prefix: '"', String suffix: '"'}) { |
+ return new LiteralString( |
+ stringToken('$prefix$text$suffix'), new DartString.literal(text)); |
} |
LiteralList listLiteral(List<Node> elements, {bool isConst: false}) { |
return new LiteralList( |
null, |
- new NodeList(symbolToken(Precedence.OPEN_SQUARE_BRACKET_INFO), |
- linkedList(elements), |
- symbolToken(Precedence.CLOSE_SQUARE_BRACKET_INFO), |
- ','), |
+ new NodeList( |
+ symbolToken(Precedence.OPEN_SQUARE_BRACKET_INFO), |
+ linkedList(elements), |
+ symbolToken(Precedence.CLOSE_SQUARE_BRACKET_INFO), |
+ ','), |
isConst ? keywordToken('const') : null); |
} |
Node createDefinition(Identifier name, Expression initializer) { |
if (initializer == null) return name; |
- return new SendSet(null, name, |
+ return new SendSet( |
+ null, |
+ name, |
new Operator(symbolToken(Precedence.EQ_INFO)), |
- new NodeList.singleton(initializer)); |
+ new NodeList.singleton(initializer)); |
} |
VariableDefinitions initializingFormal(String fieldName) { |
@@ -148,9 +140,8 @@ class AstBuilder { |
new Send(identifier('this'), identifier(fieldName)))); |
} |
- NewExpression newExpression(String typeName, |
- NodeList arguments, |
- {bool isConst: false}) { |
+ NewExpression newExpression(String typeName, NodeList arguments, |
+ {bool isConst: false}) { |
return new NewExpression(keywordToken(isConst ? 'const' : 'new'), |
new Send(null, identifier(typeName), arguments)); |
} |
@@ -160,9 +151,8 @@ class AstBuilder { |
} |
Send indexGet(Expression receiver, Expression index) { |
- return new Send(receiver, |
- new Operator(symbolToken(Precedence.INDEX_INFO)), |
- new NodeList.singleton(index)); |
+ return new Send(receiver, new Operator(symbolToken(Precedence.INDEX_INFO)), |
+ new NodeList.singleton(index)); |
} |
LiteralMapEntry mapLiteralEntry(Expression key, Expression value) { |
@@ -172,10 +162,11 @@ class AstBuilder { |
LiteralMap mapLiteral(List<LiteralMapEntry> entries, {bool isConst: false}) { |
return new LiteralMap( |
null, // Type arguments. |
- new NodeList(symbolToken(Precedence.OPEN_CURLY_BRACKET_INFO), |
- linkedList(entries), |
- symbolToken(Precedence.CLOSE_CURLY_BRACKET_INFO), |
- ','), |
+ new NodeList( |
+ symbolToken(Precedence.OPEN_CURLY_BRACKET_INFO), |
+ linkedList(entries), |
+ symbolToken(Precedence.CLOSE_CURLY_BRACKET_INFO), |
+ ','), |
isConst ? keywordToken('const') : null); |
} |
} |
@@ -219,21 +210,16 @@ class EnumCreator { |
builder.emptyStatement()); |
EnumConstructorElementX constructor = new EnumConstructorElementX( |
- enumClass, |
- builder.modifiers(isConst: true), |
- constructorNode); |
+ enumClass, builder.modifiers(isConst: true), constructorNode); |
- EnumFormalElementX indexFormal = new EnumFormalElementX( |
- constructor, |
- indexDefinition, |
- builder.identifier('index'), |
- indexVariable); |
+ EnumFormalElementX indexFormal = new EnumFormalElementX(constructor, |
+ indexDefinition, builder.identifier('index'), indexVariable); |
FunctionSignatureX constructorSignature = new FunctionSignatureX( |
requiredParameters: [indexFormal], |
requiredParameterCount: 1, |
- type: new FunctionType(constructor, const VoidType(), |
- <DartType>[intType])); |
+ type: new FunctionType( |
+ constructor, const VoidType(), <DartType>[intType])); |
constructor.functionSignature = constructorSignature; |
enumClass.addMember(constructor, reporter); |
@@ -244,9 +230,7 @@ class EnumCreator { |
int index = 0; |
List<Node> valueReferences = <Node>[]; |
List<LiteralMapEntry> mapEntries = <LiteralMapEntry>[]; |
- for (Link<Node> link = node.names.nodes; |
- !link.isEmpty; |
- link = link.tail) { |
+ for (Link<Node> link = node.names.nodes; !link.isEmpty; link = link.tail) { |
Identifier name = link.head; |
AstBuilder valueBuilder = new AstBuilder(name.token.charOffset); |
@@ -255,11 +239,10 @@ class EnumCreator { |
// Add map entry for `toString` implementation. |
mapEntries.add(valueBuilder.mapLiteralEntry( |
- valueBuilder.literalInt(index), |
- valueBuilder.literalString('${enumClass.name}.${name.source}'))); |
+ valueBuilder.literalInt(index), |
+ valueBuilder.literalString('${enumClass.name}.${name.source}'))); |
- Expression initializer = valueBuilder.newExpression( |
- enumClass.name, |
+ Expression initializer = valueBuilder.newExpression(enumClass.name, |
valueBuilder.argumentList([valueBuilder.literalInt(index)]), |
isConst: true); |
SendSet definition = valueBuilder.createDefinition(name, initializer); |
@@ -277,14 +260,13 @@ class EnumCreator { |
Identifier valuesIdentifier = builder.identifier('values'); |
// TODO(johnniwinther): Add type argument. |
- Expression initializer = builder.listLiteral( |
- valueReferences, isConst: true); |
+ Expression initializer = |
+ builder.listLiteral(valueReferences, isConst: true); |
Node definition = builder.createDefinition(valuesIdentifier, initializer); |
- EnumFieldElementX valuesVariable = new EnumFieldElementX( |
- valuesIdentifier, enumClass, valuesVariableList, |
- definition, initializer); |
+ EnumFieldElementX valuesVariable = new EnumFieldElementX(valuesIdentifier, |
+ enumClass, valuesVariableList, definition, initializer); |
enumClass.addMember(valuesVariable, reporter); |
@@ -294,20 +276,17 @@ class EnumCreator { |
Modifiers.EMPTY, |
'toString', |
builder.argumentList([]), |
- builder.returnStatement( |
- builder.indexGet( |
- builder.mapLiteral(mapEntries, isConst: true), |
- builder.reference(builder.identifier('index'))) |
- ) |
- ); |
- |
- EnumMethodElementX toString = new EnumMethodElementX('toString', |
- enumClass, Modifiers.EMPTY, toStringNode); |
- FunctionSignatureX toStringSignature = new FunctionSignatureX( |
- type: new FunctionType(toString, stringType)); |
+ builder.returnStatement(builder.indexGet( |
+ builder.mapLiteral(mapEntries, isConst: true), |
+ builder.reference(builder.identifier('index'))))); |
+ |
+ EnumMethodElementX toString = new EnumMethodElementX( |
+ 'toString', enumClass, Modifiers.EMPTY, toStringNode); |
+ FunctionSignatureX toStringSignature = |
+ new FunctionSignatureX(type: new FunctionType(toString, stringType)); |
toString.functionSignature = toStringSignature; |
enumClass.addMember(toString, reporter); |
enumClass.enumValues = enumValues; |
} |
-} |
+} |