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

Side by Side Diff: pkg/compiler/lib/src/compile_time_constants.dart

Issue 1383503002: Add Resolution and Parsing interfaces for computeType, ensureResolved and parseNode. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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.compile_time_constant_evaluator; 5 library dart2js.compile_time_constant_evaluator;
6 6
7 import 'common/resolution.dart' show
8 Resolution;
7 import 'common/tasks.dart' show 9 import 'common/tasks.dart' show
8 CompilerTask; 10 CompilerTask;
9 import 'compiler.dart' show 11 import 'compiler.dart' show
10 Compiler; 12 Compiler;
11 import 'constant_system_dart.dart'; 13 import 'constant_system_dart.dart';
12 import 'constants/constant_system.dart'; 14 import 'constants/constant_system.dart';
13 import 'constants/evaluation.dart'; 15 import 'constants/evaluation.dart';
14 import 'constants/expressions.dart'; 16 import 'constants/expressions.dart';
15 import 'constants/values.dart'; 17 import 'constants/values.dart';
16 import 'dart_types.dart'; 18 import 'dart_types.dart';
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 final TreeElements elements; 361 final TreeElements elements;
360 final Compiler compiler; 362 final Compiler compiler;
361 363
362 Element get context => elements.analyzedElement; 364 Element get context => elements.analyzedElement;
363 365
364 CompileTimeConstantEvaluator(this.handler, this.elements, this.compiler, 366 CompileTimeConstantEvaluator(this.handler, this.elements, this.compiler,
365 {bool isConst: false}) 367 {bool isConst: false})
366 : this.isEvaluatingConstant = isConst; 368 : this.isEvaluatingConstant = isConst;
367 369
368 ConstantSystem get constantSystem => handler.constantSystem; 370 ConstantSystem get constantSystem => handler.constantSystem;
371 Resolution get resolution => compiler.resolution;
369 372
370 AstConstant evaluate(Node node) { 373 AstConstant evaluate(Node node) {
371 // TODO(johnniwinther): should there be a visitErrorNode? 374 // TODO(johnniwinther): should there be a visitErrorNode?
372 if (node is ErrorNode) return new ErroneousAstConstant(context, node); 375 if (node is ErrorNode) return new ErroneousAstConstant(context, node);
373 return node.accept(this); 376 return node.accept(this);
374 } 377 }
375 378
376 AstConstant evaluateConstant(Node node) { 379 AstConstant evaluateConstant(Node node) {
377 bool oldIsEvaluatingConstant = isEvaluatingConstant; 380 bool oldIsEvaluatingConstant = isEvaluatingConstant;
378 isEvaluatingConstant = true; 381 isEvaluatingConstant = true;
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 return signalNotCompileTimeConstant(node); 569 return signalNotCompileTimeConstant(node);
567 } 570 }
568 571
569 // TODO(floitsch): provide better error-messages. 572 // TODO(floitsch): provide better error-messages.
570 AstConstant visitSend(Send send) { 573 AstConstant visitSend(Send send) {
571 Element element = elements[send]; 574 Element element = elements[send];
572 if (send.isPropertyAccess) { 575 if (send.isPropertyAccess) {
573 AstConstant result; 576 AstConstant result;
574 if (Elements.isStaticOrTopLevelFunction(element)) { 577 if (Elements.isStaticOrTopLevelFunction(element)) {
575 FunctionElementX function = element; 578 FunctionElementX function = element;
576 function.computeType(compiler); 579 function.computeType(resolution);
577 result = new AstConstant(context, send, 580 result = new AstConstant(context, send,
578 new FunctionConstantExpression(function), 581 new FunctionConstantExpression(function),
579 new FunctionConstantValue(function)); 582 new FunctionConstantValue(function));
580 } else if (Elements.isStaticOrTopLevelField(element)) { 583 } else if (Elements.isStaticOrTopLevelField(element)) {
581 ConstantExpression elementExpression; 584 ConstantExpression elementExpression;
582 if (element.isConst) { 585 if (element.isConst) {
583 elementExpression = handler.compileConstant(element); 586 elementExpression = handler.compileConstant(element);
584 } else if (element.isFinal && !isEvaluatingConstant) { 587 } else if (element.isFinal && !isEvaluatingConstant) {
585 elementExpression = handler.compileVariable(element); 588 elementExpression = handler.compileVariable(element);
586 } 589 }
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 List<AstConstant> evaluateArgumentsToConstructor(Node node, 762 List<AstConstant> evaluateArgumentsToConstructor(Node node,
760 CallStructure callStructure, Link<Node> arguments, 763 CallStructure callStructure, Link<Node> arguments,
761 ConstructorElement target, {AstConstant compileArgument(Node node)}) { 764 ConstructorElement target, {AstConstant compileArgument(Node node)}) {
762 assert(invariant(node, target.isImplementation)); 765 assert(invariant(node, target.isImplementation));
763 766
764 AstConstant compileDefaultValue(VariableElement element) { 767 AstConstant compileDefaultValue(VariableElement element) {
765 ConstantExpression constant = handler.compileConstant(element); 768 ConstantExpression constant = handler.compileConstant(element);
766 return new AstConstant.fromDefaultValue( 769 return new AstConstant.fromDefaultValue(
767 element, constant, handler.getConstantValue(constant)); 770 element, constant, handler.getConstantValue(constant));
768 } 771 }
769 target.computeType(compiler); 772 target.computeType(resolution);
770 773
771 FunctionSignature signature = target.functionSignature; 774 FunctionSignature signature = target.functionSignature;
772 if (!callStructure.signatureApplies(signature)) { 775 if (!callStructure.signatureApplies(signature)) {
773 String name = Elements.constructorNameForDiagnostics( 776 String name = Elements.constructorNameForDiagnostics(
774 target.enclosingClass.name, target.name); 777 target.enclosingClass.name, target.name);
775 compiler.reportErrorMessage( 778 compiler.reportErrorMessage(
776 node, MessageKind.INVALID_CONSTRUCTOR_ARGUMENTS, 779 node, MessageKind.INVALID_CONSTRUCTOR_ARGUMENTS,
777 {'constructorName': name}); 780 {'constructorName': name});
778 781
779 return new List<AstConstant>.filled( 782 return new List<AstConstant>.filled(
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
1266 class _CompilerEnvironment implements Environment { 1269 class _CompilerEnvironment implements Environment {
1267 final Compiler compiler; 1270 final Compiler compiler;
1268 1271
1269 _CompilerEnvironment(this.compiler); 1272 _CompilerEnvironment(this.compiler);
1270 1273
1271 @override 1274 @override
1272 String readFromEnvironment(String name) { 1275 String readFromEnvironment(String name) {
1273 return compiler.fromEnvironment(name); 1276 return compiler.fromEnvironment(name);
1274 } 1277 }
1275 } 1278 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698