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

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

Issue 574683002: Use ConstExp for storing constants. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixes and further implementation. Created 6 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 | 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 library native; 5 library native;
6 6
7 import 'dart:collection' show Queue; 7 import 'dart:collection' show Queue;
8 import 'dart2jslib.dart'; 8 import 'dart2jslib.dart';
9 import 'dart_types.dart'; 9 import 'dart_types.dart';
10 import 'elements/elements.dart'; 10 import 'elements/elements.dart';
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 325
326 /// Returns the JSName annotation string or `null` if no JSName annotation is 326 /// Returns the JSName annotation string or `null` if no JSName annotation is
327 /// present. 327 /// present.
328 String findJsNameFromAnnotation(Element element) { 328 String findJsNameFromAnnotation(Element element) {
329 String name = null; 329 String name = null;
330 ClassElement annotationClass = annotationJsNameClass; 330 ClassElement annotationClass = annotationJsNameClass;
331 for (Link<MetadataAnnotation> link = element.metadata; 331 for (Link<MetadataAnnotation> link = element.metadata;
332 !link.isEmpty; 332 !link.isEmpty;
333 link = link.tail) { 333 link = link.tail) {
334 MetadataAnnotation annotation = link.head.ensureResolved(compiler); 334 MetadataAnnotation annotation = link.head.ensureResolved(compiler);
335 var value = annotation.value; 335 var value = annotation.constant;
336 if (value is! ConstructedConstant) continue; 336 if (value is! ConstructedConstant) continue;
337 if (value.type is! InterfaceType) continue; 337 if (value.type is! InterfaceType) continue;
338 if (!identical(value.type.element, annotationClass)) continue; 338 if (!identical(value.type.element, annotationClass)) continue;
339 339
340 var fields = value.fields; 340 var fields = value.fields;
341 // TODO(sra): Better validation of the constant. 341 // TODO(sra): Better validation of the constant.
342 if (fields.length != 1 || fields[0] is! StringConstant) { 342 if (fields.length != 1 || fields[0] is! StringConstant) {
343 PartialMetadataAnnotation partial = annotation; 343 PartialMetadataAnnotation partial = annotation;
344 compiler.internalError(annotation, 344 compiler.internalError(annotation,
345 'Annotations needs one string: ${partial.parseNode(compiler)}'); 345 'Annotations needs one string: ${partial.parseNode(compiler)}');
(...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after
1092 * [annotationClass]. 1092 * [annotationClass].
1093 * Returns `null` if no constraints. 1093 * Returns `null` if no constraints.
1094 */ 1094 */
1095 static _collect(Element element, Compiler compiler, Element annotationClass, 1095 static _collect(Element element, Compiler compiler, Element annotationClass,
1096 lookup(str)) { 1096 lookup(str)) {
1097 var types = null; 1097 var types = null;
1098 for (Link<MetadataAnnotation> link = element.metadata; 1098 for (Link<MetadataAnnotation> link = element.metadata;
1099 !link.isEmpty; 1099 !link.isEmpty;
1100 link = link.tail) { 1100 link = link.tail) {
1101 MetadataAnnotation annotation = link.head.ensureResolved(compiler); 1101 MetadataAnnotation annotation = link.head.ensureResolved(compiler);
1102 var value = annotation.value; 1102 Constant value = annotation.constant.value;
1103 if (value is! ConstructedConstant) continue; 1103 if (!value.isConstructedObject) continue;
1104 if (value.type is! InterfaceType) continue; 1104 ConstructedConstant constructedObject = value;
1105 if (!identical(value.type.element, annotationClass)) continue; 1105 if (constructedObject.type.element != annotationClass) continue;
1106 1106
1107 var fields = value.fields; 1107 List<Constant> fields = constructedObject.fields;
1108 // TODO(sra): Better validation of the constant. 1108 // TODO(sra): Better validation of the constant.
1109 if (fields.length != 1 || fields[0] is! StringConstant) { 1109 if (fields.length != 1 || !fields[0].isString) {
1110 PartialMetadataAnnotation partial = annotation; 1110 PartialMetadataAnnotation partial = annotation;
1111 compiler.internalError(annotation, 1111 compiler.internalError(annotation,
1112 'Annotations needs one string: ${partial.parseNode(compiler)}'); 1112 'Annotations needs one string: ${partial.parseNode(compiler)}');
1113 } 1113 }
1114 String specString = fields[0].toDartString().slowToString(); 1114 StringConstant specStringConstant = fields[0];
1115 String specString = specStringConstant.toDartString().slowToString();
1115 for (final typeString in specString.split('|')) { 1116 for (final typeString in specString.split('|')) {
1116 var type = _parseType(typeString, compiler, lookup, annotation); 1117 var type = _parseType(typeString, compiler, lookup, annotation);
1117 if (types == null) types = []; 1118 if (types == null) types = [];
1118 types.add(type); 1119 types.add(type);
1119 } 1120 }
1120 } 1121 }
1121 return types; 1122 return types;
1122 } 1123 }
1123 1124
1124 /// Models the behavior of having intances of [type] escape from Dart code 1125 /// Models the behavior of having intances of [type] escape from Dart code
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
1335 LiteralString jsCode = nativeBody.asLiteralString(); 1336 LiteralString jsCode = nativeBody.asLiteralString();
1336 builder.push(new HForeign.statement( 1337 builder.push(new HForeign.statement(
1337 js.js.statementTemplateYielding( 1338 js.js.statementTemplateYielding(
1338 new js.LiteralStatement(jsCode.dartString.slowToString())), 1339 new js.LiteralStatement(jsCode.dartString.slowToString())),
1339 <HInstruction>[], 1340 <HInstruction>[],
1340 new SideEffects(), 1341 new SideEffects(),
1341 null, 1342 null,
1342 backend.dynamicType)); 1343 backend.dynamicType));
1343 } 1344 }
1344 } 1345 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698