Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(392)

Side by Side Diff: pkg/compiler/lib/src/constants/expressions.dart

Issue 1062913003: Extract CallStructure from Selector. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library dart2js.constants.expressions; 5 library dart2js.constants.expressions;
6 6
7 import '../dart2jslib.dart' show assertDebugMode; 7 import '../dart2jslib.dart' show assertDebugMode;
8 import '../dart_types.dart'; 8 import '../dart_types.dart';
9 import '../elements/elements.dart' show 9 import '../elements/elements.dart' show
10 Element, 10 Element,
11 FunctionElement, 11 FunctionElement,
12 VariableElement; 12 VariableElement;
13 import '../universe/universe.dart' show Selector; 13 import '../universe/universe.dart' show CallStructure;
14 import 'values.dart'; 14 import 'values.dart';
15 15
16 /// An expression that is a compile-time constant. 16 /// An expression that is a compile-time constant.
17 /// 17 ///
18 /// Whereas [ConstantValue] represent a compile-time value, a 18 /// Whereas [ConstantValue] represent a compile-time value, a
19 /// [ConstantExpression] represents an expression for creating a constant. 19 /// [ConstantExpression] represents an expression for creating a constant.
20 /// 20 ///
21 /// There is no one-to-one mapping between [ConstantExpression] and 21 /// There is no one-to-one mapping between [ConstantExpression] and
22 /// [ConstantValue], because different expressions can denote the same constant. 22 /// [ConstantValue], because different expressions can denote the same constant.
23 /// For instance, multiple `const` constructors may be used to create the same 23 /// For instance, multiple `const` constructors may be used to create the same
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 accept(ConstantExpressionVisitor visitor, [context]) { 94 accept(ConstantExpressionVisitor visitor, [context]) {
95 return visitor.visitMap(this, context); 95 return visitor.visitMap(this, context);
96 } 96 }
97 } 97 }
98 98
99 /// Invocation of a const constructor. 99 /// Invocation of a const constructor.
100 class ConstructedConstantExpression extends ConstantExpression { 100 class ConstructedConstantExpression extends ConstantExpression {
101 final ConstantValue value; 101 final ConstantValue value;
102 final InterfaceType type; 102 final InterfaceType type;
103 final FunctionElement target; 103 final FunctionElement target;
104 final Selector selector; 104 final CallStructure callStructure;
105 final List<ConstantExpression> arguments; 105 final List<ConstantExpression> arguments;
106 106
107 ConstructedConstantExpression(this.value, 107 ConstructedConstantExpression(
108 this.type, 108 this.value,
109 this.target, 109 this.type,
110 this.selector, 110 this.target,
111 this.arguments) { 111 this.callStructure,
112 this.arguments) {
112 assert(type.element == target.enclosingClass); 113 assert(type.element == target.enclosingClass);
113 } 114 }
114 115
115 accept(ConstantExpressionVisitor visitor, [context]) { 116 accept(ConstantExpressionVisitor visitor, [context]) {
116 return visitor.visitConstructed(this, context); 117 return visitor.visitConstructed(this, context);
117 } 118 }
118 } 119 }
119 120
120 /// String literal with juxtaposition and/or interpolations. 121 /// String literal with juxtaposition and/or interpolations.
121 // TODO(johnniwinther): Do we need this? 122 // TODO(johnniwinther): Do we need this?
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 sb.write('const '); 372 sb.write('const ');
372 sb.write(exp.target.enclosingClass.name); 373 sb.write(exp.target.enclosingClass.name);
373 if (exp.target.name != '') { 374 if (exp.target.name != '') {
374 sb.write('.'); 375 sb.write('.');
375 sb.write(exp.target.name); 376 sb.write(exp.target.name);
376 } 377 }
377 writeTypeArguments(exp.type); 378 writeTypeArguments(exp.type);
378 sb.write('('); 379 sb.write('(');
379 bool needsComma = false; 380 bool needsComma = false;
380 381
381 int namedOffset = exp.selector.positionalArgumentCount; 382 int namedOffset = exp.callStructure.positionalArgumentCount;
382 for (int index = 0; index < namedOffset; index++) { 383 for (int index = 0; index < namedOffset; index++) {
383 if (needsComma) { 384 if (needsComma) {
384 sb.write(', '); 385 sb.write(', ');
385 } 386 }
386 visit(exp.arguments[index]); 387 visit(exp.arguments[index]);
387 needsComma = true; 388 needsComma = true;
388 } 389 }
389 for (int index = 0; index < exp.selector.namedArgumentCount; index++) { 390 for (int index = 0; index < exp.callStructure.namedArgumentCount; index++) {
390 if (needsComma) { 391 if (needsComma) {
391 sb.write(', '); 392 sb.write(', ');
392 } 393 }
393 sb.write(exp.selector.namedArguments[index]); 394 sb.write(exp.callStructure.namedArguments[index]);
394 sb.write(': '); 395 sb.write(': ');
395 visit(exp.arguments[namedOffset + index]); 396 visit(exp.arguments[namedOffset + index]);
396 needsComma = true; 397 needsComma = true;
397 } 398 }
398 sb.write(')'); 399 sb.write(')');
399 } 400 }
400 401
401 @override 402 @override
402 void visitConcatenate(ConcatenateConstantExpression exp, [_]) { 403 void visitConcatenate(ConcatenateConstantExpression exp, [_]) {
403 sb.write(exp.value.unparse()); 404 sb.write(exp.value.unparse());
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 void visitConditional(ConditionalConstantExpression exp, [_]) { 460 void visitConditional(ConditionalConstantExpression exp, [_]) {
460 write(exp, exp.condition, leftAssociative: false); 461 write(exp, exp.condition, leftAssociative: false);
461 sb.write(' ? '); 462 sb.write(' ? ');
462 write(exp, exp.trueExp); 463 write(exp, exp.trueExp);
463 sb.write(' : '); 464 sb.write(' : ');
464 write(exp, exp.falseExp); 465 write(exp, exp.falseExp);
465 } 466 }
466 467
467 String toString() => sb.toString(); 468 String toString() => sb.toString();
468 } 469 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698