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

Side by Side Diff: frog/member.dart

Issue 9487012: Avoid mangling the name of native methods. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase. Created 8 years, 9 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/gen.dart ('k') | frog/minfrog » ('j') | frog/world.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 /** A formal parameter to a [Method]. */ 5 /** A formal parameter to a [Method]. */
6 class Parameter { 6 class Parameter {
7 FormalNode definition; 7 FormalNode definition;
8 Member method; 8 Member method;
9 9
10 String name; 10 String name;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 } 82 }
83 83
84 84
85 class Member extends Element { 85 class Member extends Element {
86 final Type declaringType; 86 final Type declaringType;
87 87
88 Member genericMember; 88 Member genericMember;
89 89
90 Member(String name, Type declaringType) 90 Member(String name, Type declaringType)
91 : this.declaringType = declaringType, 91 : this.declaringType = declaringType,
92 super(name, declaringType) { 92 super(name, declaringType);
93 if (_jsname != null && declaringType != null && declaringType.isTop) { 93
94 _jsname = JsNames.getValid(_jsname); 94 String mangleJsName() {
95 var mangled = super.mangleJsName();
96 if (mangled == 'split') {
97 // Hack: We don't want Dart's String.split to overwrite the
98 // existing JS String.prototype.split method. By mangling it we
99 // ensure that frog will not use the 'split' name, thus leaving
100 // the original JS String.prototype.split untouched.
101 return 'split_';
102 } else if (declaringType != null && declaringType.isTop) {
103 return JsNames.getValid(mangled);
104 } else {
105 // We don't need to mangle native member names unless
106 // they contain illegal characters.
107 return (isNative && !name.contains(':')) ? name : mangled;
95 } 108 }
96 } 109 }
97 110
98 abstract bool get isStatic(); 111 abstract bool get isStatic();
99 abstract Type get returnType(); 112 abstract Type get returnType();
100 113
101 abstract bool get canGet(); 114 abstract bool get canGet();
102 abstract bool get canSet(); 115 abstract bool get canSet();
103 116
104 Library get library() => declaringType.library; 117 Library get library() => declaringType.library;
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 /** Represents a Dart field from source code. */ 374 /** Represents a Dart field from source code. */
362 class FieldMember extends Member { 375 class FieldMember extends Member {
363 final VariableDefinition definition; 376 final VariableDefinition definition;
364 final Expression value; 377 final Expression value;
365 378
366 Type type; 379 Type type;
367 Value _computedValue; 380 Value _computedValue;
368 381
369 bool isStatic; 382 bool isStatic;
370 bool isFinal; 383 bool isFinal;
371 bool isNative; 384 final bool isNative;
372 385
373 // TODO(jimhug): Better notion of fields that need special handling... 386 // TODO(jimhug): Better notion of fields that need special handling...
374 bool get overridesProperty() { 387 bool get overridesProperty() {
375 if (isStatic) return false; 388 if (isStatic) return false;
376 389
377 if (declaringType.parent != null) { 390 if (declaringType.parent != null) {
378 var p = declaringType.parent.getProperty(name); 391 var p = declaringType.parent.getProperty(name);
379 if (p != null && p.isProperty) return true; 392 if (p != null && p.isProperty) return true;
380 if (p is FieldMember && p != this) return p.overridesProperty; 393 if (p is FieldMember && p != this) return p.overridesProperty;
381 } 394 }
(...skipping 24 matching lines...) Expand all
406 } 419 }
407 } 420 }
408 421
409 void provideSetter() { 422 void provideSetter() {
410 _provideSetter = true; 423 _provideSetter = true;
411 if (genericMember !== null) { 424 if (genericMember !== null) {
412 genericMember.provideSetter(); 425 genericMember.provideSetter();
413 } 426 }
414 } 427 }
415 428
416 FieldMember(String name, Type declaringType, this.definition, this.value) 429 FieldMember(String name, Type declaringType, this.definition, this.value,
417 : super(name, declaringType), isNative = false; 430 [bool this.isNative = false])
431 : super(name, declaringType);
418 432
419 Member makeConcrete(Type concreteType) { 433 Member makeConcrete(Type concreteType) {
420 var ret = new FieldMember(name, concreteType, definition, value); 434 var ret = new FieldMember(name, concreteType, definition, value);
421 ret.genericMember = this; 435 ret.genericMember = this;
422 ret._jsname = _jsname; 436 ret._jsname = _jsname;
423 return ret; 437 return ret;
424 } 438 }
425 439
426
427 SourceSpan get span() => definition == null ? null : definition.span; 440 SourceSpan get span() => definition == null ? null : definition.span;
428 441
429 Type get returnType() => type; 442 Type get returnType() => type;
430 443
431 bool get canGet() => true; 444 bool get canGet() => true;
432 bool get canSet() => !isFinal; 445 bool get canSet() => !isFinal;
433 446
434 bool get isField() => true; 447 bool get isField() => true;
435 448
436 resolve() { 449 resolve() {
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 707
695 Type _functionType; 708 Type _functionType;
696 bool isStatic = false; 709 bool isStatic = false;
697 bool isAbstract = false; 710 bool isAbstract = false;
698 711
699 // Note: these two modifiers are only legal on constructors 712 // Note: these two modifiers are only legal on constructors
700 bool isConst = false; 713 bool isConst = false;
701 bool isFactory = false; 714 bool isFactory = false;
702 715
703 /** True if this is a function defined inside another method. */ 716 /** True if this is a function defined inside another method. */
704 bool isLambda = false; 717 final bool isLambda;
705 718
706 /** 719 /**
707 * True if we should provide info on optional parameters for use by runtime 720 * True if we should provide info on optional parameters for use by runtime
708 * dispatch. 721 * dispatch.
709 */ 722 */
710 bool _provideOptionalParamInfo = false; 723 bool _provideOptionalParamInfo = false;
711 724
712 /* 725 /*
713 * When this is a constructor, contains any other constructor called during 726 * When this is a constructor, contains any other constructor called during
714 * initialization (if any). 727 * initialization (if any).
715 */ 728 */
716 Member initDelegate; 729 Member initDelegate;
717 730
718 MethodMember(String name, Type declaringType, this.definition) 731 MethodMember(String name, Type declaringType, this.definition)
719 : super(name, declaringType); 732 : isLambda = false, super(name, declaringType);
733
734 MethodMember.lambda(String name, Type declaringType, this.definition)
735 : isLambda = true, super(name, declaringType);
720 736
721 Member makeConcrete(Type concreteType) { 737 Member makeConcrete(Type concreteType) {
722 var _name = isConstructor ? concreteType.name : name; 738 var _name = isConstructor ? concreteType.name : name;
723 var ret = new MethodMember(_name, concreteType, definition); 739 var ret = new MethodMember(_name, concreteType, definition);
724 ret.genericMember = this; 740 ret.genericMember = this;
725 ret._jsname = _jsname; 741 ret._jsname = _jsname;
726 return ret; 742 return ret;
727 } 743 }
728 744
729 MethodData get methodData() { 745 MethodData get methodData() {
730 if (genericMember !== null) return genericMember.dynamic.methodData; 746 if (genericMember !== null) return genericMember.dynamic.methodData;
731 747
732 if (_methodData === null) { 748 if (_methodData === null) {
733 _methodData = new MethodData(this); 749 _methodData = new MethodData(this);
734 } 750 }
735 return _methodData; 751 return _methodData;
736 } 752 }
737 753
738 bool get isConstructor() => name == declaringType.name; 754 bool get isConstructor() => name == declaringType.name;
739 bool get isMethod() => !isConstructor; 755 bool get isMethod() => !isConstructor;
740 756
741 bool get isNative() => definition.nativeBody != null; 757 bool get isNative() {
758 if (definition == null) return false;
759 return definition.nativeBody != null;
760 }
742 761
743 bool get canGet() => true; 762 bool get canGet() => true;
744 bool get canSet() => false; 763 bool get canSet() => false;
745 764
746 bool get requiresPropertySyntax() => true; 765 bool get requiresPropertySyntax() => true;
747 766
748 SourceSpan get span() => definition == null ? null : definition.span; 767 SourceSpan get span() => definition == null ? null : definition.span;
749 768
750 String get constructorName() { 769 String get constructorName() {
751 var returnType = definition.returnType; 770 var returnType = definition.returnType;
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after
1391 f(member); 1410 f(member);
1392 }); 1411 });
1393 }); 1412 });
1394 } 1413 }
1395 1414
1396 bool isEmpty() { 1415 bool isEmpty() {
1397 return factories.getValues() 1416 return factories.getValues()
1398 .every((Map constructors) => constructors.isEmpty()); 1417 .every((Map constructors) => constructors.isEmpty());
1399 } 1418 }
1400 } 1419 }
OLDNEW
« no previous file with comments | « frog/gen.dart ('k') | frog/minfrog » ('j') | frog/world.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698