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

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

Issue 694353007: Move dart2js from sdk/lib/_internal/compiler to pkg/compiler (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
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.
4
5 part of js_backend;
6
7 class CheckedModeHelper {
8 final String name;
9
10 const CheckedModeHelper(String this.name);
11
12 Element getElement(Compiler compiler) {
13 JavaScriptBackend backend = compiler.backend;
14 return backend.findHelper(name);
15 }
16
17 jsAst.Expression generateCall(SsaCodeGenerator codegen,
18 HTypeConversion node) {
19 Element helperElement = getElement(codegen.compiler);
20 codegen.registry.registerStaticUse(helperElement);
21 List<jsAst.Expression> arguments = <jsAst.Expression>[];
22 codegen.use(node.checkedInput);
23 arguments.add(codegen.pop());
24 generateAdditionalArguments(codegen, node, arguments);
25 jsAst.Expression helper = codegen.backend.namer.elementAccess(helperElement) ;
26 return new jsAst.Call(helper, arguments);
27 }
28
29 void generateAdditionalArguments(SsaCodeGenerator codegen,
30 HTypeConversion node,
31 List<jsAst.Expression> arguments) {
32 // No additional arguments needed.
33 }
34
35 static const List<CheckedModeHelper> helpers = const <CheckedModeHelper> [
36 const MalformedCheckedModeHelper('checkMalformedType'),
37 const CheckedModeHelper('voidTypeCheck'),
38 const CheckedModeHelper('stringTypeCast'),
39 const CheckedModeHelper('stringTypeCheck'),
40 const CheckedModeHelper('doubleTypeCast'),
41 const CheckedModeHelper('doubleTypeCheck'),
42 const CheckedModeHelper('numTypeCast'),
43 const CheckedModeHelper('numTypeCheck'),
44 const CheckedModeHelper('boolTypeCast'),
45 const CheckedModeHelper('boolTypeCheck'),
46 const CheckedModeHelper('intTypeCast'),
47 const CheckedModeHelper('intTypeCheck'),
48 const PropertyCheckedModeHelper('numberOrStringSuperNativeTypeCast'),
49 const PropertyCheckedModeHelper('numberOrStringSuperNativeTypeCheck'),
50 const PropertyCheckedModeHelper('numberOrStringSuperTypeCast'),
51 const PropertyCheckedModeHelper('numberOrStringSuperTypeCheck'),
52 const PropertyCheckedModeHelper('stringSuperNativeTypeCast'),
53 const PropertyCheckedModeHelper('stringSuperNativeTypeCheck'),
54 const PropertyCheckedModeHelper('stringSuperTypeCast'),
55 const PropertyCheckedModeHelper('stringSuperTypeCheck'),
56 const CheckedModeHelper('listTypeCast'),
57 const CheckedModeHelper('listTypeCheck'),
58 const PropertyCheckedModeHelper('listSuperNativeTypeCast'),
59 const PropertyCheckedModeHelper('listSuperNativeTypeCheck'),
60 const PropertyCheckedModeHelper('listSuperTypeCast'),
61 const PropertyCheckedModeHelper('listSuperTypeCheck'),
62 const PropertyCheckedModeHelper('interceptedTypeCast'),
63 const PropertyCheckedModeHelper('interceptedTypeCheck'),
64 const SubtypeCheckedModeHelper('subtypeCast'),
65 const SubtypeCheckedModeHelper('assertSubtype'),
66 const TypeVariableCheckedModeHelper('subtypeOfRuntimeTypeCast'),
67 const TypeVariableCheckedModeHelper('assertSubtypeOfRuntimeType'),
68 const PropertyCheckedModeHelper('propertyTypeCast'),
69 const PropertyCheckedModeHelper('propertyTypeCheck')];
70 }
71
72 class MalformedCheckedModeHelper extends CheckedModeHelper {
73 const MalformedCheckedModeHelper(String name) : super(name);
74
75 void generateAdditionalArguments(SsaCodeGenerator codegen,
76 HTypeConversion node,
77 List<jsAst.Expression> arguments) {
78 ErroneousElement element = node.typeExpression.element;
79 arguments.add(js.escapedString(element.message));
80 }
81 }
82
83 class PropertyCheckedModeHelper extends CheckedModeHelper {
84 const PropertyCheckedModeHelper(String name) : super(name);
85
86 void generateAdditionalArguments(SsaCodeGenerator codegen,
87 HTypeConversion node,
88 List<jsAst.Expression> arguments) {
89 DartType type = node.typeExpression;
90 String additionalArgument = codegen.backend.namer.operatorIsType(type);
91 arguments.add(js.string(additionalArgument));
92 }
93 }
94
95 class TypeVariableCheckedModeHelper extends CheckedModeHelper {
96 const TypeVariableCheckedModeHelper(String name) : super(name);
97
98 void generateAdditionalArguments(SsaCodeGenerator codegen,
99 HTypeConversion node,
100 List<jsAst.Expression> arguments) {
101 assert(node.typeExpression.isTypeVariable);
102 codegen.use(node.typeRepresentation);
103 arguments.add(codegen.pop());
104 }
105 }
106
107 class SubtypeCheckedModeHelper extends CheckedModeHelper {
108 const SubtypeCheckedModeHelper(String name) : super(name);
109
110 void generateAdditionalArguments(SsaCodeGenerator codegen,
111 HTypeConversion node,
112 List<jsAst.Expression> arguments) {
113 DartType type = node.typeExpression;
114 Element element = type.element;
115 String isField = codegen.backend.namer.operatorIs(element);
116 arguments.add(js.string(isField));
117 codegen.use(node.typeRepresentation);
118 arguments.add(codegen.pop());
119 String asField = codegen.backend.namer.substitutionName(element);
120 arguments.add(js.string(asField));
121 }
122 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698