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

Side by Side Diff: frog/leg/elements/elements.dart

Issue 9284022: Operators. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 11 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
« no previous file with comments | « frog/leg/compiler.dart ('k') | frog/leg/emitter.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 #library('elements'); 5 #library('elements');
6 6
7 #import('../tree/tree.dart'); 7 #import('../tree/tree.dart');
8 #import('../scanner/scannerlib.dart'); 8 #import('../scanner/scannerlib.dart');
9 #import('../leg.dart'); // TODO(karlklose): we only need type. 9 #import('../leg.dart'); // TODO(karlklose): we only need type.
10 #import('../util/util.dart'); 10 #import('../util/util.dart');
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 } 404 }
405 405
406 Element lookupConstructor(SourceString className, 406 Element lookupConstructor(SourceString className,
407 [SourceString constructorName = 407 [SourceString constructorName =
408 const SourceString(''), 408 const SourceString(''),
409 Element noMatch(Element)]) { 409 Element noMatch(Element)]) {
410 // TODO(karlklose): have a map from class names to a map of constructors 410 // TODO(karlklose): have a map from class names to a map of constructors
411 // instead of creating the name here? 411 // instead of creating the name here?
412 SourceString name; 412 SourceString name;
413 if (constructorName !== const SourceString('')) { 413 if (constructorName !== const SourceString('')) {
414 name = new SourceString('$className.$constructorName'); 414 name = Elements.constructConstructorName(className, constructorName);
415 } else { 415 } else {
416 name = className; 416 name = className;
417 } 417 }
418 Element result = constructors[name]; 418 Element result = constructors[name];
419 if (result === null && noMatch !== null) { 419 if (result === null && noMatch !== null) {
420 result = noMatch(lookupLocalMember(constructorName)); 420 result = noMatch(lookupLocalMember(constructorName));
421 } 421 }
422 return result; 422 return result;
423 } 423 }
424 424
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 static bool isClosureSend(Send send, TreeElements elements) { 464 static bool isClosureSend(Send send, TreeElements elements) {
465 if (send.isPropertyAccess) return false; 465 if (send.isPropertyAccess) return false;
466 if (send.receiver !== null) return false; 466 if (send.receiver !== null) return false;
467 Element element = elements[send]; 467 Element element = elements[send];
468 // (o)() or foo()(). 468 // (o)() or foo()().
469 if (element === null && send.selector.asIdentifier() === null) return true; 469 if (element === null && send.selector.asIdentifier() === null) return true;
470 if (element === null) return false; 470 if (element === null) return false;
471 // foo() with foo a local or a parameter. 471 // foo() with foo a local or a parameter.
472 return element.isVariable() || element.isParameter(); 472 return element.isVariable() || element.isParameter();
473 } 473 }
474
475 static SourceString constructConstructorName(SourceString receiver,
476 SourceString selector) {
477 return new SourceString('$receiver\$$selector');
478 }
479
480 static SourceString constructOperatorName(SourceString receiver,
481 SourceString selector,
482 [bool isPrefix = false]) {
483 String str = selector.stringValue;
484 if (str === '==' || str === '!=') return Namer.OPERATOR_EQUALS;
485
486 if (str === '~') str = 'not';
487 else if (str === 'negate' || (str === '-' && isPrefix)) str = 'negate';
488 else if (str === '[]') str = 'index';
489 else if (str === '[]=') str = 'indexSet';
490 else if (str === '*' || str === '*=') str = 'mul';
491 else if (str === '/' || str === '/=') str = 'div';
492 else if (str === '%' || str === '%=') str = 'mod';
493 else if (str === '~/' || str === '~/=') str = 'tdiv';
494 else if (str === '+' || str === '+=') str = 'add';
495 else if (str === '-' || str === '-=') str = 'sub';
496 else if (str === '<<' || str === '<<=') str = 'shl';
497 else if (str === '>>' || str === '>>=') str = 'shr';
498 else if (str === '>=') str = 'ge';
499 else if (str === '>') str = 'gt';
500 else if (str === '<=') str = 'le';
501 else if (str === '<') str = 'lt';
502 else if (str === '&' || str === '&=') str = 'and';
503 else if (str === '^' || str === '^=') str = 'xor';
504 else if (str === '|' || str === '|=') str = 'or';
505 return new SourceString('$receiver\$$str');
506 }
474 } 507 }
OLDNEW
« no previous file with comments | « frog/leg/compiler.dart ('k') | frog/leg/emitter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698