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

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: Created 7 years, 5 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 MalformedCheckedModeHelper extends CheckedModeHelper {
karlklose 2013/07/19 11:45:40 This should be AmbiguousTypeCheckedModeHelper.
Johnni Winther 2013/07/29 09:59:48 Done.
111 const MalformedCheckedModeHelper(SourceString name) : super(name); 109 const MalformedCheckedModeHelper(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 arguments.add(js.string('$type')); 117 arguments.add(js.string('$type'));
120 // TODO(johnniwinther): Handle escaping correctly. 118 // TODO(johnniwinther): Handle escaping correctly.
121 arguments.add(js.string(reasons)); 119 arguments.add(js.string(reasons));
122 } 120 }
123 } 121 }
124 122
125 123
126 class JavaScriptBackend extends Backend { 124 class JavaScriptBackend extends Backend {
127 SsaBuilderTask builder; 125 SsaBuilderTask builder;
128 SsaOptimizerTask optimizer; 126 SsaOptimizerTask optimizer;
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 world.registerInstantiatedClass(compiler.boolClass, elements); 798 world.registerInstantiatedClass(compiler.boolClass, elements);
801 bool inCheckedMode = compiler.enableTypeAssertions; 799 bool inCheckedMode = compiler.enableTypeAssertions;
802 // [registerIsCheck] is also called for checked mode checks, so we 800 // [registerIsCheck] is also called for checked mode checks, so we
803 // need to register checked mode helpers. 801 // need to register checked mode helpers.
804 if (inCheckedMode) { 802 if (inCheckedMode) {
805 CheckedModeHelper helper = getCheckedModeHelper(type, typeCast: false); 803 CheckedModeHelper helper = getCheckedModeHelper(type, typeCast: false);
806 if (helper != null) world.addToWorkList(helper.getElement(compiler)); 804 if (helper != null) world.addToWorkList(helper.getElement(compiler));
807 // We also need the native variant of the check (for DOM types). 805 // We also need the native variant of the check (for DOM types).
808 helper = getNativeCheckedModeHelper(type, typeCast: false); 806 helper = getNativeCheckedModeHelper(type, typeCast: false);
809 if (helper != null) world.addToWorkList(helper.getElement(compiler)); 807 if (helper != null) world.addToWorkList(helper.getElement(compiler));
810 if (type.isMalformed) { 808 if (type.containsAmbiguousTypes) {
811 enqueueInResolution(getThrowMalformedSubtypeError(), elements); 809 enqueueInResolution(getThrowMalformedSubtypeError(), elements);
812 return; 810 return;
813 } 811 }
814 } else if (type.isMalformed) { 812 } else if (type.containsAmbiguousTypes) {
815 registerThrowRuntimeError(elements); 813 registerThrowRuntimeError(elements);
816 return; 814 return;
817 } 815 }
818 bool isTypeVariable = type.kind == TypeKind.TYPE_VARIABLE; 816 bool isTypeVariable = type.kind == TypeKind.TYPE_VARIABLE;
819 if (!type.isRaw || type.containsTypeVariables) { 817 if (!type.isRaw || type.containsTypeVariables) {
820 enqueueInResolution(getSetRuntimeTypeInfo(), elements); 818 enqueueInResolution(getSetRuntimeTypeInfo(), elements);
821 enqueueInResolution(getGetRuntimeTypeInfo(), elements); 819 enqueueInResolution(getGetRuntimeTypeInfo(), elements);
822 enqueueInResolution(getGetRuntimeTypeArgument(), elements); 820 enqueueInResolution(getGetRuntimeTypeArgument(), elements);
823 if (inCheckedMode) { 821 if (inCheckedMode) {
824 enqueueInResolution(getAssertSubtype(), elements); 822 enqueueInResolution(getAssertSubtype(), elements);
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
1067 * Returns the checked mode helper for the type check/type cast for [type]. If 1065 * Returns the checked mode helper for the type check/type cast for [type]. If
1068 * [nativeCheckOnly] is [:true:], only names for native helpers are returned. 1066 * [nativeCheckOnly] is [:true:], only names for native helpers are returned.
1069 */ 1067 */
1070 CheckedModeHelper getCheckedModeHelperInternal(DartType type, 1068 CheckedModeHelper getCheckedModeHelperInternal(DartType type,
1071 {bool typeCast, 1069 {bool typeCast,
1072 bool nativeCheckOnly}) { 1070 bool nativeCheckOnly}) {
1073 assert(type.kind != TypeKind.TYPEDEF); 1071 assert(type.kind != TypeKind.TYPEDEF);
1074 Element element = type.element; 1072 Element element = type.element;
1075 bool nativeCheck = nativeCheckOnly || 1073 bool nativeCheck = nativeCheckOnly ||
1076 emitter.nativeEmitter.requiresNativeIsCheck(element); 1074 emitter.nativeEmitter.requiresNativeIsCheck(element);
1077 if (type.isMalformed) { 1075 if (type.containsAmbiguousTypes) {
1078 // Check for malformed types first, because the type may be a list type 1076 // Check for malformed types first, because the type may be a list type
1079 // with a malformed argument type. 1077 // with a malformed argument type.
1080 if (nativeCheckOnly) return null; 1078 if (nativeCheckOnly) return null;
1081 return typeCast 1079 return typeCast
1082 ? const MalformedCheckedModeHelper( 1080 ? const MalformedCheckedModeHelper(
1083 const SourceString('malformedTypeCast')) 1081 const SourceString('malformedTypeCast'))
1084 : const MalformedCheckedModeHelper( 1082 : const MalformedCheckedModeHelper(
1085 const SourceString('malformedTypeCheck')); 1083 const SourceString('malformedTypeCheck'));
1086 } else if (type == compiler.types.voidType) { 1084 } else if (type == compiler.types.voidType) {
1087 assert(!typeCast); // Cannot cast to void. 1085 assert(!typeCast); // Cannot cast to void.
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
1442 } 1440 }
1443 } 1441 }
1444 1442
1445 /// Records that [type] is used by [user.element]. 1443 /// Records that [type] is used by [user.element].
1446 class Dependency { 1444 class Dependency {
1447 final DartType type; 1445 final DartType type;
1448 final TreeElements user; 1446 final TreeElements user;
1449 1447
1450 const Dependency(this.type, this.user); 1448 const Dependency(this.type, this.user);
1451 } 1449 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698