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

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

Issue 1299413002: Move common identifiers, names and selectors to a separate library. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments. Created 5 years, 4 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) 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 part of js_backend; 5 part of js_backend;
6 6
7 /** 7 /**
8 * Assigns JavaScript identifiers to Dart variables, class-names and members. 8 * Assigns JavaScript identifiers to Dart variables, class-names and members.
9 * 9 *
10 * Names are generated through three stages: 10 * Names are generated through three stages:
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 _literalGetterPrefix = new StringBackedName(getterPrefix); 453 _literalGetterPrefix = new StringBackedName(getterPrefix);
454 _literalSetterPrefix = new StringBackedName(setterPrefix); 454 _literalSetterPrefix = new StringBackedName(setterPrefix);
455 _literalLazyGetterPrefix = new StringBackedName(lazyGetterPrefix); 455 _literalLazyGetterPrefix = new StringBackedName(lazyGetterPrefix);
456 } 456 }
457 457
458 JavaScriptBackend get backend => compiler.backend; 458 JavaScriptBackend get backend => compiler.backend;
459 459
460 String get deferredTypesName => 'deferredTypes'; 460 String get deferredTypesName => 'deferredTypes';
461 String get isolateName => 'Isolate'; 461 String get isolateName => 'Isolate';
462 String get isolatePropertiesName => r'$isolateProperties'; 462 String get isolatePropertiesName => r'$isolateProperties';
463 jsAst.Name get noSuchMethodName => publicInstanceMethodNameByArity( 463 jsAst.Name get noSuchMethodName => invocationName(Selectors.noSuchMethod_);
464 Compiler.NO_SUCH_METHOD, Compiler.NO_SUCH_METHOD_ARG_COUNT); 464
465 /** 465 /**
466 * Some closures must contain their name. The name is stored in 466 * Some closures must contain their name. The name is stored in
467 * [STATIC_CLOSURE_NAME_NAME]. 467 * [STATIC_CLOSURE_NAME_NAME].
468 */ 468 */
469 String get STATIC_CLOSURE_NAME_NAME => r'$name'; 469 String get STATIC_CLOSURE_NAME_NAME => r'$name';
470 String get closureInvocationSelectorName => Compiler.CALL_OPERATOR_NAME; 470 String get closureInvocationSelectorName => Identifiers.call;
471 bool get shouldMinify => false; 471 bool get shouldMinify => false;
472 472
473 /// Returns the string that is to be used as the result of a call to 473 /// Returns the string that is to be used as the result of a call to
474 /// [JS_GET_NAME] at [node] with argument [name]. 474 /// [JS_GET_NAME] at [node] with argument [name].
475 jsAst.Name getNameForJsGetName(Node node, JsGetName name) { 475 jsAst.Name getNameForJsGetName(Node node, JsGetName name) {
476 switch (name) { 476 switch (name) {
477 case JsGetName.GETTER_PREFIX: return asName(getterPrefix); 477 case JsGetName.GETTER_PREFIX: return asName(getterPrefix);
478 case JsGetName.SETTER_PREFIX: return asName(setterPrefix); 478 case JsGetName.SETTER_PREFIX: return asName(setterPrefix);
479 case JsGetName.CALL_PREFIX: return asName(callPrefix); 479 case JsGetName.CALL_PREFIX: return asName(callPrefix);
480 case JsGetName.CALL_PREFIX0: return asName('${callPrefix}\$0'); 480 case JsGetName.CALL_PREFIX0: return asName('${callPrefix}\$0');
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 } 626 }
627 627
628 /// Annotated name for [method] encoding arity and named parameters. 628 /// Annotated name for [method] encoding arity and named parameters.
629 jsAst.Name instanceMethodName(FunctionElement method) { 629 jsAst.Name instanceMethodName(FunctionElement method) {
630 if (method.isGenerativeConstructorBody) { 630 if (method.isGenerativeConstructorBody) {
631 return constructorBodyName(method); 631 return constructorBodyName(method);
632 } 632 }
633 return invocationName(new Selector.fromElement(method)); 633 return invocationName(new Selector.fromElement(method));
634 } 634 }
635 635
636 /// Annotated name for a public method with the given [originalName]
637 /// and [arity] and no named parameters.
638 jsAst.Name publicInstanceMethodNameByArity(String originalName,
639 int arity) {
640 return invocationName(new Selector.call(originalName, null, arity));
641 }
642
643 /// Returns the annotated name for a variant of `call`. 636 /// Returns the annotated name for a variant of `call`.
644 /// The result has the form: 637 /// The result has the form:
645 /// 638 ///
646 /// call$<N>$namedParam1...$namedParam<M> 639 /// call$<N>$namedParam1...$namedParam<M>
647 /// 640 ///
648 /// This name cannot be minified because it is generated by string 641 /// This name cannot be minified because it is generated by string
649 /// concatenation at runtime, by applyFunction in js_helper.dart. 642 /// concatenation at runtime, by applyFunction in js_helper.dart.
650 jsAst.Name deriveCallMethodName(List<String> suffix) { 643 jsAst.Name deriveCallMethodName(List<String> suffix) {
651 // TODO(asgerf): Avoid clashes when named parameters contain $ symbols. 644 // TODO(asgerf): Avoid clashes when named parameters contain $ symbols.
652 return new StringBackedName('$callPrefix\$${suffix.join(r'$')}'); 645 return new StringBackedName('$callPrefix\$${suffix.join(r'$')}');
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 688
696 case SelectorKind.OPERATOR: 689 case SelectorKind.OPERATOR:
697 case SelectorKind.INDEX: 690 case SelectorKind.INDEX:
698 String operatorIdentifier = operatorNameToIdentifier(selector.name); 691 String operatorIdentifier = operatorNameToIdentifier(selector.name);
699 jsAst.Name disambiguatedName = 692 jsAst.Name disambiguatedName =
700 _disambiguateOperator(operatorIdentifier); 693 _disambiguateOperator(operatorIdentifier);
701 return disambiguatedName; // Operators are not annotated. 694 return disambiguatedName; // Operators are not annotated.
702 695
703 case SelectorKind.CALL: 696 case SelectorKind.CALL:
704 List<String> suffix = callSuffixForStructure(selector.callStructure); 697 List<String> suffix = callSuffixForStructure(selector.callStructure);
705 if (selector.name == Compiler.CALL_OPERATOR_NAME) { 698 if (selector.name == Identifiers.call) {
706 // Derive the annotated name for this variant of 'call'. 699 // Derive the annotated name for this variant of 'call'.
707 return deriveCallMethodName(suffix); 700 return deriveCallMethodName(suffix);
708 } 701 }
709 jsAst.Name disambiguatedName = 702 jsAst.Name disambiguatedName =
710 _disambiguateMember(selector.memberName, suffix); 703 _disambiguateMember(selector.memberName, suffix);
711 return disambiguatedName; // Methods other than call are not annotated. 704 return disambiguatedName; // Methods other than call are not annotated.
712 705
713 default: 706 default:
714 compiler.internalError(compiler.currentElement, 707 compiler.internalError(compiler.currentElement,
715 'Unexpected selector kind: ${selector.kind}'); 708 'Unexpected selector kind: ${selector.kind}');
(...skipping 1273 matching lines...) Expand 10 before | Expand all | Expand 10 after
1989 } 1982 }
1990 } 1983 }
1991 } 1984 }
1992 } 1985 }
1993 1986
1994 enum NamingScope { 1987 enum NamingScope {
1995 global, 1988 global,
1996 instance, 1989 instance,
1997 constant 1990 constant
1998 } 1991 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/js_backend.dart ('k') | pkg/compiler/lib/src/js_backend/no_such_method_registry.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698