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

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

Issue 19097003: Support new malformed types semantics. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix unittests. Created 7 years, 4 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 js_backend; 5 part of js_backend;
6 6
7 class JavaScriptItemCompilationContext extends ItemCompilationContext { 7 class JavaScriptItemCompilationContext extends ItemCompilationContext {
8 final Set<HInstruction> boundsChecked; 8 final Set<HInstruction> boundsChecked;
9 9
10 JavaScriptItemCompilationContext() 10 JavaScriptItemCompilationContext()
(...skipping 15 matching lines...) Expand all
26 codegen.use(node.checkedInput); 26 codegen.use(node.checkedInput);
27 arguments.add(codegen.pop()); 27 arguments.add(codegen.pop());
28 generateAdditionalArguments(codegen, node, arguments); 28 generateAdditionalArguments(codegen, node, arguments);
29 String helperName = codegen.backend.namer.isolateAccess(helperElement); 29 String helperName = codegen.backend.namer.isolateAccess(helperElement);
30 return new jsAst.Call(new jsAst.VariableUse(helperName), arguments); 30 return new jsAst.Call(new jsAst.VariableUse(helperName), arguments);
31 } 31 }
32 32
33 void generateAdditionalArguments(SsaCodeGenerator codegen, 33 void generateAdditionalArguments(SsaCodeGenerator codegen,
34 HTypeConversion node, 34 HTypeConversion node,
35 List<jsAst.Expression> arguments) { 35 List<jsAst.Expression> arguments) {
36 assert(!node.typeExpression.isMalformed);
37 // No additional arguments needed. 36 // No additional arguments needed.
38 } 37 }
39 } 38 }
40 39
41 class PropertyCheckedModeHelper extends CheckedModeHelper { 40 class PropertyCheckedModeHelper extends CheckedModeHelper {
42 const PropertyCheckedModeHelper(SourceString name) : super(name); 41 const PropertyCheckedModeHelper(SourceString name) : super(name);
43 42
44 void generateAdditionalArguments(SsaCodeGenerator codegen, 43 void generateAdditionalArguments(SsaCodeGenerator codegen,
45 HTypeConversion node, 44 HTypeConversion node,
46 List<jsAst.Expression> arguments) { 45 List<jsAst.Expression> arguments) {
47 DartType type = node.typeExpression; 46 DartType type = node.typeExpression;
48 assert(!type.isMalformed);
49 String additionalArgument = codegen.backend.namer.operatorIsType(type); 47 String additionalArgument = codegen.backend.namer.operatorIsType(type);
50 arguments.add(js.string(additionalArgument)); 48 arguments.add(js.string(additionalArgument));
51 } 49 }
52 } 50 }
53 51
54 class TypeVariableCheckedModeHelper extends CheckedModeHelper { 52 class TypeVariableCheckedModeHelper extends CheckedModeHelper {
55 const TypeVariableCheckedModeHelper(SourceString name) : super(name); 53 const TypeVariableCheckedModeHelper(SourceString name) : super(name);
56 54
57 void generateAdditionalArguments(SsaCodeGenerator codegen, 55 void generateAdditionalArguments(SsaCodeGenerator codegen,
58 HTypeConversion node, 56 HTypeConversion node,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 codegen.use(node.context); 98 codegen.use(node.context);
101 arguments.add(codegen.pop()); 99 arguments.add(codegen.pop());
102 } else { 100 } else {
103 codegen.use(node.context); 101 codegen.use(node.context);
104 arguments.add(codegen.pop()); 102 arguments.add(codegen.pop());
105 } 103 }
106 } 104 }
107 } 105 }
108 } 106 }
109 107
110 class MalformedCheckedModeHelper extends CheckedModeHelper { 108 class AmbiguousTypeCheckedModeHelper extends CheckedModeHelper {
111 const MalformedCheckedModeHelper(SourceString name) : super(name); 109 const AmbiguousTypeCheckedModeHelper(SourceString name) : super(name);
112 110
113 void generateAdditionalArguments(SsaCodeGenerator codegen, 111 void generateAdditionalArguments(SsaCodeGenerator codegen,
114 HTypeConversion node, 112 HTypeConversion node,
115 List<jsAst.Expression> arguments) { 113 List<jsAst.Expression> arguments) {
116 DartType type = node.typeExpression; 114 DartType type = node.typeExpression;
117 assert(type.isMalformed); 115 assert(type.containsAmbiguousTypes);
118 String reasons = Types.fetchReasonsFromMalformedType(type); 116 String reasons = Types.fetchReasonsFromAmbiguousType(type);
119 117
120 arguments.add(js.string(quote('$type'))); 118 arguments.add(js.string(quote('$type')));
121 arguments.add(js.string(quote(reasons))); 119 arguments.add(js.string(quote(reasons)));
122 } 120 }
123 121
124 String quote(String string) => string.replaceAll('"', r'\"'); 122 String quote(String string) => string.replaceAll('"', r'\"');
125 } 123 }
126 124
127 /* 125 /*
128 * Invariants: 126 * Invariants:
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 world.registerInstantiatedClass(compiler.boolClass, elements); 846 world.registerInstantiatedClass(compiler.boolClass, elements);
849 bool inCheckedMode = compiler.enableTypeAssertions; 847 bool inCheckedMode = compiler.enableTypeAssertions;
850 // [registerIsCheck] is also called for checked mode checks, so we 848 // [registerIsCheck] is also called for checked mode checks, so we
851 // need to register checked mode helpers. 849 // need to register checked mode helpers.
852 if (inCheckedMode) { 850 if (inCheckedMode) {
853 CheckedModeHelper helper = getCheckedModeHelper(type, typeCast: false); 851 CheckedModeHelper helper = getCheckedModeHelper(type, typeCast: false);
854 if (helper != null) world.addToWorkList(helper.getElement(compiler)); 852 if (helper != null) world.addToWorkList(helper.getElement(compiler));
855 // We also need the native variant of the check (for DOM types). 853 // We also need the native variant of the check (for DOM types).
856 helper = getNativeCheckedModeHelper(type, typeCast: false); 854 helper = getNativeCheckedModeHelper(type, typeCast: false);
857 if (helper != null) world.addToWorkList(helper.getElement(compiler)); 855 if (helper != null) world.addToWorkList(helper.getElement(compiler));
858 if (type.isMalformed) { 856 if (type.containsAmbiguousTypes) {
859 enqueueInResolution(getThrowMalformedSubtypeError(), elements); 857 enqueueInResolution(getThrowMalformedSubtypeError(), elements);
860 return; 858 return;
861 } 859 }
862 } else if (type.isMalformed) { 860 } else if (type.containsAmbiguousTypes) {
863 registerThrowRuntimeError(elements); 861 registerThrowRuntimeError(elements);
864 return; 862 return;
865 } 863 }
866 bool isTypeVariable = type.kind == TypeKind.TYPE_VARIABLE; 864 bool isTypeVariable = type.kind == TypeKind.TYPE_VARIABLE;
867 if (!type.isRaw || type.containsTypeVariables) { 865 if (!type.isRaw || type.containsTypeVariables) {
868 enqueueInResolution(getSetRuntimeTypeInfo(), elements); 866 enqueueInResolution(getSetRuntimeTypeInfo(), elements);
869 enqueueInResolution(getGetRuntimeTypeInfo(), elements); 867 enqueueInResolution(getGetRuntimeTypeInfo(), elements);
870 enqueueInResolution(getGetRuntimeTypeArgument(), elements); 868 enqueueInResolution(getGetRuntimeTypeArgument(), elements);
871 if (inCheckedMode) { 869 if (inCheckedMode) {
872 enqueueInResolution(getAssertSubtype(), elements); 870 enqueueInResolution(getAssertSubtype(), elements);
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
1115 * Returns the checked mode helper for the type check/type cast for [type]. If 1113 * Returns the checked mode helper for the type check/type cast for [type]. If
1116 * [nativeCheckOnly] is [:true:], only names for native helpers are returned. 1114 * [nativeCheckOnly] is [:true:], only names for native helpers are returned.
1117 */ 1115 */
1118 CheckedModeHelper getCheckedModeHelperInternal(DartType type, 1116 CheckedModeHelper getCheckedModeHelperInternal(DartType type,
1119 {bool typeCast, 1117 {bool typeCast,
1120 bool nativeCheckOnly}) { 1118 bool nativeCheckOnly}) {
1121 assert(type.kind != TypeKind.TYPEDEF); 1119 assert(type.kind != TypeKind.TYPEDEF);
1122 Element element = type.element; 1120 Element element = type.element;
1123 bool nativeCheck = nativeCheckOnly || 1121 bool nativeCheck = nativeCheckOnly ||
1124 emitter.nativeEmitter.requiresNativeIsCheck(element); 1122 emitter.nativeEmitter.requiresNativeIsCheck(element);
1125 if (type.isMalformed) { 1123 if (type.containsAmbiguousTypes) {
1126 // Check for malformed types first, because the type may be a list type 1124 // Check for malformed types first, because the type may be a list type
1127 // with a malformed argument type. 1125 // with a malformed argument type.
1128 if (nativeCheckOnly) return null; 1126 if (nativeCheckOnly) return null;
1129 return typeCast 1127 return typeCast
1130 ? const MalformedCheckedModeHelper( 1128 ? const AmbiguousTypeCheckedModeHelper(
1131 const SourceString('malformedTypeCast')) 1129 const SourceString('malformedTypeCast'))
1132 : const MalformedCheckedModeHelper( 1130 : const AmbiguousTypeCheckedModeHelper(
1133 const SourceString('malformedTypeCheck')); 1131 const SourceString('malformedTypeCheck'));
1134 } else if (type == compiler.types.voidType) { 1132 } else if (type == compiler.types.voidType) {
1135 assert(!typeCast); // Cannot cast to void. 1133 assert(!typeCast); // Cannot cast to void.
1136 if (nativeCheckOnly) return null; 1134 if (nativeCheckOnly) return null;
1137 return const CheckedModeHelper(const SourceString('voidTypeCheck')); 1135 return const CheckedModeHelper(const SourceString('voidTypeCheck'));
1138 } else if (element == jsStringClass || element == compiler.stringClass) { 1136 } else if (element == jsStringClass || element == compiler.stringClass) {
1139 if (nativeCheckOnly) return null; 1137 if (nativeCheckOnly) return null;
1140 return typeCast 1138 return typeCast
1141 ? const CheckedModeHelper(const SourceString("stringTypeCast")) 1139 ? const CheckedModeHelper(const SourceString("stringTypeCast"))
1142 : const CheckedModeHelper(const SourceString('stringTypeCheck')); 1140 : const CheckedModeHelper(const SourceString('stringTypeCheck'));
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
1488 } 1486 }
1489 } 1487 }
1490 1488
1491 /// Records that [type] is used by [user.element]. 1489 /// Records that [type] is used by [user.element].
1492 class Dependency { 1490 class Dependency {
1493 final DartType type; 1491 final DartType type;
1494 final TreeElements user; 1492 final TreeElements user;
1495 1493
1496 const Dependency(this.type, this.user); 1494 const Dependency(this.type, this.user);
1497 } 1495 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698