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

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

Issue 2968383002: Add ConstructorBodyEntity (Closed)
Patch Set: Skip non-live constructor bodies Created 3 years, 5 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 library js_backend.namer; 5 library js_backend.namer;
6 6
7 import 'dart:collection' show HashMap; 7 import 'dart:collection' show HashMap;
8 8
9 import 'package:js_runtime/shared/embedded_names.dart' show JsGetName; 9 import 'package:js_runtime/shared/embedded_names.dart' show JsGetName;
10 10
11 import '../closure.dart'; 11 import '../closure.dart';
12 import '../common.dart'; 12 import '../common.dart';
13 import '../common/names.dart' show Identifiers, Selectors; 13 import '../common/names.dart' show Identifiers, Selectors;
14 import '../constants/values.dart'; 14 import '../constants/values.dart';
15 import '../common_elements.dart' show CommonElements; 15 import '../common_elements.dart' show CommonElements;
16 import '../diagnostics/invariant.dart' show DEBUG_MODE; 16 import '../diagnostics/invariant.dart' show DEBUG_MODE;
17 import '../elements/elements.dart' 17 import '../elements/elements.dart'
18 show 18 show
19 ClassElement, 19 ClassElement,
20 ConstructorBodyElement,
21 Element, 20 Element,
22 Elements, 21 Elements,
23 FieldElement, 22 FieldElement,
24 FormalElement,
25 FunctionElement,
26 FunctionSignature,
27 MemberElement, 23 MemberElement,
28 TypeDeclarationElement, 24 TypeDeclarationElement,
29 MixinApplicationElement, 25 MixinApplicationElement,
30 TypedefElement; 26 TypedefElement;
31 import '../elements/entities.dart'; 27 import '../elements/entities.dart';
32 import '../elements/entity_utils.dart' as utils; 28 import '../elements/entity_utils.dart' as utils;
33 import '../elements/jumps.dart'; 29 import '../elements/jumps.dart';
34 import '../elements/names.dart'; 30 import '../elements/names.dart';
35 import '../elements/resolution_types.dart'; 31 import '../elements/resolution_types.dart';
36 import '../elements/types.dart'; 32 import '../elements/types.dart';
(...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 // Make sure to return a private name that starts with _ so it 758 // Make sure to return a private name that starts with _ so it
763 // cannot clash with any public names. 759 // cannot clash with any public names.
764 // The name is still not guaranteed to be unique, since both the library 760 // The name is still not guaranteed to be unique, since both the library
765 // name and originalName could contain $ symbols and as the library 761 // name and originalName could contain $ symbols and as the library
766 // name itself might clash. 762 // name itself might clash.
767 String libraryName = _proposeNameForLibrary(library); 763 String libraryName = _proposeNameForLibrary(library);
768 return "_$libraryName\$$text"; 764 return "_$libraryName\$$text";
769 } 765 }
770 } 766 }
771 767
772 String _proposeNameForConstructorBody(ConstructorBodyElement method) { 768 String _proposeNameForConstructorBody(ConstructorBodyEntity method) {
773 String name = Elements.reconstructConstructorNameSourceString(method); 769 String name = Elements.reconstructConstructorNameSourceString(method);
774 // We include the method suffix on constructor bodies. It has no purpose, 770 // We include the method suffix on constructor bodies. It has no purpose,
775 // but this way it produces the same names as previous versions of the 771 // but this way it produces the same names as previous versions of the
776 // Namer class did. 772 // Namer class did.
777 List<String> suffix = callSuffixForSignature(method.functionSignature); 773 List<String> suffix = callSuffixForSignature(method.parameterStructure);
778 return '$name\$${suffix.join(r'$')}'; 774 return '$name\$${suffix.join(r'$')}';
779 } 775 }
780 776
781 /// Name for a constructor body. 777 /// Name for a constructor body.
782 jsAst.Name constructorBodyName(ConstructorBodyElement ctor) { 778 jsAst.Name constructorBodyName(ConstructorBodyEntity ctor) {
783 return _disambiguateInternalMember( 779 return _disambiguateInternalMember(
784 ctor, () => _proposeNameForConstructorBody(ctor)); 780 ctor, () => _proposeNameForConstructorBody(ctor));
785 } 781 }
786 782
787 /// Annotated name for [method] encoding arity and named parameters. 783 /// Annotated name for [method] encoding arity and named parameters.
788 jsAst.Name instanceMethodName(FunctionEntity method) { 784 jsAst.Name instanceMethodName(FunctionEntity method) {
789 // TODO(redemption): Avoid the use of [ConstructorBodyElement]. The 785 // TODO(johnniwinther): Avoid the use of [ConstructorBodyEntity]. The
790 // codegen model should be explicit about its constructor body elements. 786 // codegen model should be explicit about its constructor body elements.
791 if (method is ConstructorBodyElement) { 787 if (method is ConstructorBodyEntity) {
792 return constructorBodyName(method); 788 return constructorBodyName(method);
793 } 789 }
794 return invocationName(new Selector.fromElement(method)); 790 return invocationName(new Selector.fromElement(method));
795 } 791 }
796 792
797 /// Returns the annotated name for a variant of `call`. 793 /// Returns the annotated name for a variant of `call`.
798 /// The result has the form: 794 /// The result has the form:
799 /// 795 ///
800 /// call$<N>$namedParam1...$namedParam<M> 796 /// call$<N>$namedParam1...$namedParam<M>
801 /// 797 ///
(...skipping 15 matching lines...) Expand all
817 suffixes.addAll(callStructure.getOrderedNamedArguments()); 813 suffixes.addAll(callStructure.getOrderedNamedArguments());
818 return suffixes; 814 return suffixes;
819 } 815 }
820 816
821 /// The suffix list for the pattern: 817 /// The suffix list for the pattern:
822 /// 818 ///
823 /// $<N>$namedParam1...$namedParam<M> 819 /// $<N>$namedParam1...$namedParam<M>
824 /// 820 ///
825 /// This is used for the annotated names of `call`, and for the proposed name 821 /// This is used for the annotated names of `call`, and for the proposed name
826 /// for other instance methods. 822 /// for other instance methods.
827 List<String> callSuffixForSignature(FunctionSignature sig) { 823 List<String> callSuffixForSignature(ParameterStructure parameterStructure) {
828 List<String> suffixes = ['${sig.parameterCount}']; 824 List<String> suffixes = ['${parameterStructure.totalParameters}'];
829 if (sig.optionalParametersAreNamed) { 825 suffixes.addAll(parameterStructure.namedParameters);
830 for (FormalElement param in sig.orderedOptionalParameters) {
831 suffixes.add(param.name);
832 }
833 }
834 return suffixes; 826 return suffixes;
835 } 827 }
836 828
837 /// Annotated name for the member being invoked by [selector]. 829 /// Annotated name for the member being invoked by [selector].
838 jsAst.Name invocationName(Selector selector) { 830 jsAst.Name invocationName(Selector selector) {
839 switch (selector.kind) { 831 switch (selector.kind) {
840 case SelectorKind.GETTER: 832 case SelectorKind.GETTER:
841 jsAst.Name disambiguatedName = _disambiguateMember(selector.memberName); 833 jsAst.Name disambiguatedName = _disambiguateMember(selector.memberName);
842 return deriveGetterName(disambiguatedName); 834 return deriveGetterName(disambiguatedName);
843 835
(...skipping 1404 matching lines...) Expand 10 before | Expand all | Expand 10 after
2248 void addSuggestion(String original, String suggestion) { 2240 void addSuggestion(String original, String suggestion) {
2249 assert(!_suggestedNames.containsKey(original)); 2241 assert(!_suggestedNames.containsKey(original));
2250 _suggestedNames[original] = suggestion; 2242 _suggestedNames[original] = suggestion;
2251 } 2243 }
2252 2244
2253 bool hasSuggestion(String original) => _suggestedNames.containsKey(original); 2245 bool hasSuggestion(String original) => _suggestedNames.containsKey(original);
2254 bool isSuggestion(String candidate) { 2246 bool isSuggestion(String candidate) {
2255 return _suggestedNames.containsValue(candidate); 2247 return _suggestedNames.containsValue(candidate);
2256 } 2248 }
2257 } 2249 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/minify_namer.dart ('k') | pkg/compiler/lib/src/js_emitter/full_emitter/emitter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698