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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/compile_time_constants.dart

Issue 304153014: Remove element from DynamicType. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix infinite loop. Created 6 years, 6 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) 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 part of dart2js; 5 part of dart2js;
6 6
7 /// A [ConstantEnvironment] provides access for constants compiled for variable 7 /// A [ConstantEnvironment] provides access for constants compiled for variable
8 /// initializers. 8 /// initializers.
9 abstract class ConstantEnvironment { 9 abstract class ConstantEnvironment {
10 /// Returns the constant for the initializer of [element]. 10 /// Returns the constant for the initializer of [element].
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 if (initializer == null) { 144 if (initializer == null) {
145 // No initial value. 145 // No initial value.
146 value = new NullConstant(); 146 value = new NullConstant();
147 } else { 147 } else {
148 value = compileNodeWithDefinitions( 148 value = compileNodeWithDefinitions(
149 initializer, definitions, isConst: isConst); 149 initializer, definitions, isConst: isConst);
150 if (compiler.enableTypeAssertions && 150 if (compiler.enableTypeAssertions &&
151 value != null && 151 value != null &&
152 element.isField) { 152 element.isField) {
153 DartType elementType = element.type; 153 DartType elementType = element.type;
154 if (elementType.kind == TypeKind.MALFORMED_TYPE && !value.isNull) { 154 if (elementType.isMalformed && !value.isNull) {
155 if (isConst) { 155 if (isConst) {
156 ErroneousElement element = elementType.element; 156 ErroneousElement element = elementType.element;
157 compiler.reportFatalError( 157 compiler.reportFatalError(
158 node, element.messageKind, element.messageArguments); 158 node, element.messageKind, element.messageArguments);
159 } else { 159 } else {
160 // We need to throw an exception at runtime. 160 // We need to throw an exception at runtime.
161 value = null; 161 value = null;
162 } 162 }
163 } else { 163 } else {
164 DartType constantType = value.computeType(compiler); 164 DartType constantType = value.computeType(compiler);
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 Constant visitLiteralSymbol(LiteralSymbol node) { 400 Constant visitLiteralSymbol(LiteralSymbol node) {
401 InterfaceType type = compiler.symbolClass.rawType; 401 InterfaceType type = compiler.symbolClass.rawType;
402 List<Constant> createArguments(_) { 402 List<Constant> createArguments(_) {
403 return [constantSystem.createString( 403 return [constantSystem.createString(
404 new DartString.literal(node.slowNameString))]; 404 new DartString.literal(node.slowNameString))];
405 } 405 }
406 return makeConstructedConstant( 406 return makeConstructedConstant(
407 node, type, compiler.symbolConstructor, createArguments); 407 node, type, compiler.symbolConstructor, createArguments);
408 } 408 }
409 409
410 Constant makeTypeConstant(TypeDeclarationElement element) { 410 Constant makeTypeConstant(DartType elementType) {
411 DartType elementType = element.rawType;
412 DartType constantType = 411 DartType constantType =
413 compiler.backend.typeImplementation.computeType(compiler); 412 compiler.backend.typeImplementation.computeType(compiler);
414 return new TypeConstant(elementType, constantType); 413 return new TypeConstant(elementType, constantType);
415 } 414 }
416 415
417 /// Returns true if the prefix of the send resolves to a deferred import 416 /// Returns true if the prefix of the send resolves to a deferred import
418 /// prefix. 417 /// prefix.
419 bool isDeferredUse(Send send) { 418 bool isDeferredUse(Send send) {
420 if (send == null) return false; 419 if (send == null) return false;
421 return compiler.deferredLoadTask 420 return compiler.deferredLoadTask
422 .deferredPrefixElement(send, elements) != null; 421 .deferredPrefixElement(send, elements) != null;
423 } 422 }
424 423
425 Constant visitIdentifier(Identifier node) { 424 Constant visitIdentifier(Identifier node) {
426 Element element = elements[node]; 425 Element element = elements[node];
427 if (Elements.isClass(element) || Elements.isTypedef(element)) { 426 if (Elements.isClass(element) || Elements.isTypedef(element)) {
428 return makeTypeConstant(element); 427 TypeDeclarationElement typeDeclarationElement = element;
428 return makeTypeConstant(typeDeclarationElement.rawType);
429 } 429 }
430 return signalNotCompileTimeConstant(node); 430 return signalNotCompileTimeConstant(node);
431 } 431 }
432 432
433 // TODO(floitsch): provide better error-messages. 433 // TODO(floitsch): provide better error-messages.
434 Constant visitSend(Send send) { 434 Constant visitSend(Send send) {
435 Element element = elements[send]; 435 Element element = elements[send];
436 if (send.isPropertyAccess) { 436 if (send.isPropertyAccess) {
437 if (isDeferredUse(send)) { 437 if (isDeferredUse(send)) {
438 return signalNotCompileTimeConstant(send, 438 return signalNotCompileTimeConstant(send,
439 message: MessageKind.DEFERRED_COMPILE_TIME_CONSTANT); 439 message: MessageKind.DEFERRED_COMPILE_TIME_CONSTANT);
440 } 440 }
441 if (Elements.isStaticOrTopLevelFunction(element)) { 441 if (Elements.isStaticOrTopLevelFunction(element)) {
442 return new FunctionConstant(element); 442 return new FunctionConstant(element);
443 } else if (Elements.isStaticOrTopLevelField(element)) { 443 } else if (Elements.isStaticOrTopLevelField(element)) {
444 Constant result; 444 Constant result;
445 if (element.isConst) { 445 if (element.isConst) {
446 result = handler.compileConstant(element); 446 result = handler.compileConstant(element);
447 } else if (element.isFinal && !isEvaluatingConstant) { 447 } else if (element.isFinal && !isEvaluatingConstant) {
448 result = handler.compileVariable(element); 448 result = handler.compileVariable(element);
449 } 449 }
450 if (result != null) return result; 450 if (result != null) return result;
451 } else if (Elements.isClass(element) || Elements.isTypedef(element)) { 451 } else if (Elements.isClass(element) || Elements.isTypedef(element)) {
452 assert(elements.isTypeLiteral(send)); 452 assert(elements.isTypeLiteral(send));
453 return makeTypeConstant(element); 453 return makeTypeConstant(elements.getTypeLiteralType(send));
454 } else if (send.receiver != null) { 454 } else if (send.receiver != null) {
455 // Fall through to error handling. 455 // Fall through to error handling.
456 } else if (!Elements.isUnresolved(element) 456 } else if (!Elements.isUnresolved(element)
457 && element.isVariable 457 && element.isVariable
458 && element.isConst) { 458 && element.isConst) {
459 Constant result = handler.compileConstant(element); 459 Constant result = handler.compileConstant(element);
460 if (result != null) return result; 460 if (result != null) return result;
461 } 461 }
462 return signalNotCompileTimeConstant(send); 462 return signalNotCompileTimeConstant(send);
463 } else if (send.isCall) { 463 } else if (send.isCall) {
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 if (fieldValue == null) { 968 if (fieldValue == null) {
969 // Use the default value. 969 // Use the default value.
970 fieldValue = handler.compileConstant(field); 970 fieldValue = handler.compileConstant(field);
971 } 971 }
972 jsNewArguments.add(fieldValue); 972 jsNewArguments.add(fieldValue);
973 }, 973 },
974 includeSuperAndInjectedMembers: true); 974 includeSuperAndInjectedMembers: true);
975 return jsNewArguments; 975 return jsNewArguments;
976 } 976 }
977 } 977 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/closure.dart ('k') | sdk/lib/_internal/compiler/implementation/compiler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698