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

Side by Side Diff: pkg/compiler/lib/src/js_backend/checked_mode_helpers.dart

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

Powered by Google App Engine
This is Rietveld 408576698