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

Side by Side Diff: pkg/compiler/lib/src/native/behavior.dart

Issue 954253002: dart2js: add compiler builtins to the core-runtime. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 native; 5 part of native;
6 6
7 /// This class is a temporary work-around until we get a more powerful DartType. 7 /// This class is a temporary work-around until we get a more powerful DartType.
8 class SpecialType { 8 class SpecialType {
9 final String name; 9 final String name;
10 const SpecialType._(this.name); 10 const SpecialType._(this.name);
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 specString, 207 specString,
208 resolveType: resolveType, 208 resolveType: resolveType,
209 typesReturned: behavior.typesReturned, 209 typesReturned: behavior.typesReturned,
210 typesInstantiated: behavior.typesInstantiated, 210 typesInstantiated: behavior.typesInstantiated,
211 objectType: compiler.objectClass.computeType(compiler), 211 objectType: compiler.objectClass.computeType(compiler),
212 nullType: compiler.nullClass.computeType(compiler)); 212 nullType: compiler.nullClass.computeType(compiler));
213 213
214 return behavior; 214 return behavior;
215 } 215 }
216 216
217 static NativeBehavior ofJsEmbeddedGlobalCall(Send jsGlobalCall, 217 static NativeBehavior _ofMacroOrEmbeddedGlobal(Send jsMacroOrGlobalCall,
218 Compiler compiler, 218 Compiler compiler,
219 resolver) { 219 ResolverVisitor resolver,
220 {bool isMacro}) {
220 // The first argument of a JS-embedded global call is a string encoding 221 // The first argument of a JS-embedded global call is a string encoding
221 // the type of the code. 222 // the type of the code.
222 // 223 //
223 // 'Type1|Type2'. A union type. 224 // 'Type1|Type2'. A union type.
224 // '=Object'. A JavaScript Object, no subtype. 225 // '=Object'. A JavaScript Object, no subtype.
225 226
226 Link<Node> argNodes = jsGlobalCall.arguments; 227 String macroOrGlobal = isMacro ? "macro" : "embedded global";
228
229 Link<Node> argNodes = jsMacroOrGlobalCall.arguments;
227 if (argNodes.isEmpty) { 230 if (argNodes.isEmpty) {
228 compiler.internalError(jsGlobalCall, 231 compiler.internalError(jsMacroOrGlobalCall,
229 "JS embedded global expression has no type."); 232 "JS $macroOrGlobal expression has no type.");
230 } 233 }
231 234
232 // We don't check the given name. That needs to be done at a later point. 235 // We don't check the given name. That needs to be done at a later point.
herhut 2015/02/26 08:50:28 For macros, the name has to be a literal. Otherwis
floitsch 2015/03/18 17:43:01 We are switching to enums and shared string-litera
233 // This is, because we want to allow non-literals as names. 236 // This is, because we want to allow non-literals as names.
234 if (argNodes.tail.isEmpty) { 237 if (argNodes.tail.isEmpty) {
235 compiler.internalError(jsGlobalCall, 'Embedded Global is missing name'); 238 compiler.internalError(jsMacroOrGlobalCall,
239 'JS $macroOrGlobal is missing name');
236 } 240 }
237 241
238 if (!argNodes.tail.tail.isEmpty) { 242 if (!isMacro) {
239 compiler.internalError(argNodes.tail.tail.head, 243 if (!argNodes.tail.tail.isEmpty) {
240 'Embedded Global has more than 2 arguments'); 244 compiler.internalError(argNodes.tail.tail.head,
245 'JS embedded global has more than 2 arguments');
246 }
241 } 247 }
242 248
243 LiteralString specLiteral = argNodes.head.asLiteralString(); 249 LiteralString specLiteral = argNodes.head.asLiteralString();
244 if (specLiteral == null) { 250 if (specLiteral == null) {
245 // TODO(sra): We could accept a type identifier? e.g. JS(bool, '1<2'). It 251 // TODO(sra): We could accept a type identifier? e.g. JS(bool, '1<2'). It
246 // is not very satisfactory because it does not work for void, dynamic. 252 // is not very satisfactory because it does not work for void, dynamic.
247 compiler.internalError(argNodes.head, "Unexpected first argument."); 253 compiler.internalError(argNodes.head, "Unexpected first argument.");
248 } 254 }
249 255
250 NativeBehavior behavior = new NativeBehavior(); 256 NativeBehavior behavior = new NativeBehavior();
251 257
252 String specString = specLiteral.dartString.slowToString(); 258 String specString = specLiteral.dartString.slowToString();
253 259
254 resolveType(String typeString) { 260 resolveType(String typeString) {
255 return _parseType( 261 return _parseType(
256 typeString, 262 typeString,
257 compiler, 263 compiler,
258 (name) => resolver.resolveTypeFromString(specLiteral, name), 264 (name) => resolver.resolveTypeFromString(specLiteral, name),
259 jsGlobalCall); 265 jsMacroOrGlobalCall);
260 } 266 }
261 267
262 processSpecString(compiler, jsGlobalCall, 268 processSpecString(compiler, jsMacroOrGlobalCall,
263 specString, 269 specString,
264 resolveType: resolveType, 270 resolveType: resolveType,
265 typesReturned: behavior.typesReturned, 271 typesReturned: behavior.typesReturned,
266 typesInstantiated: behavior.typesInstantiated, 272 typesInstantiated: behavior.typesInstantiated,
267 objectType: compiler.objectClass.computeType(compiler), 273 objectType: compiler.objectClass.computeType(compiler),
268 nullType: compiler.nullClass.computeType(compiler)); 274 nullType: compiler.nullClass.computeType(compiler));
269 275
270 return behavior; 276 return behavior;
271 } 277 }
272 278
279 static NativeBehavior ofJsCompilerMacroCall(Send jsMacroCall,
280 Compiler compiler,
281 ResolverVisitor resolver) {
282 return _ofMacroOrEmbeddedGlobal(
283 jsMacroCall, compiler, resolver, isMacro: true);
284 }
285
286 static NativeBehavior ofJsEmbeddedGlobalCall(Send jsGlobalCall,
287 Compiler compiler,
288 ResolverVisitor resolver) {
289 return _ofMacroOrEmbeddedGlobal(
290 jsGlobalCall, compiler, resolver, isMacro: false);
291 }
292
273 static NativeBehavior ofMethod(FunctionElement method, Compiler compiler) { 293 static NativeBehavior ofMethod(FunctionElement method, Compiler compiler) {
274 FunctionType type = method.computeType(compiler); 294 FunctionType type = method.computeType(compiler);
275 var behavior = new NativeBehavior(); 295 var behavior = new NativeBehavior();
276 behavior.typesReturned.add(type.returnType); 296 behavior.typesReturned.add(type.returnType);
277 if (!type.returnType.isVoid) { 297 if (!type.returnType.isVoid) {
278 // Declared types are nullable. 298 // Declared types are nullable.
279 behavior.typesReturned.add(compiler.nullClass.computeType(compiler)); 299 behavior.typesReturned.add(compiler.nullClass.computeType(compiler));
280 } 300 }
281 behavior._capture(type, compiler); 301 behavior._capture(type, compiler);
282 302
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 compiler.internalError( 447 compiler.internalError(
428 _errorNode(locationNodeOrElement, compiler), 448 _errorNode(locationNodeOrElement, compiler),
429 "Type '$typeString' not found."); 449 "Type '$typeString' not found.");
430 } 450 }
431 451
432 static _errorNode(locationNodeOrElement, compiler) { 452 static _errorNode(locationNodeOrElement, compiler) {
433 if (locationNodeOrElement is Node) return locationNodeOrElement; 453 if (locationNodeOrElement is Node) return locationNodeOrElement;
434 return locationNodeOrElement.parseNode(compiler); 454 return locationNodeOrElement.parseNode(compiler);
435 } 455 }
436 } 456 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698