OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 library fasta.builder; |
| 6 |
| 7 import '../errors.dart' show |
| 8 internalError; |
| 9 |
| 10 export 'class_builder.dart' show |
| 11 ClassBuilder; |
| 12 |
| 13 export 'field_builder.dart' show |
| 14 FieldBuilder; |
| 15 |
| 16 export 'library_builder.dart' show |
| 17 LibraryBuilder; |
| 18 |
| 19 export 'procedure_builder.dart' show |
| 20 ProcedureBuilder; |
| 21 |
| 22 export 'type_builder.dart' show |
| 23 TypeBuilder; |
| 24 |
| 25 export 'formal_parameter_builder.dart' show |
| 26 FormalParameterBuilder; |
| 27 |
| 28 export 'metadata_builder.dart' show |
| 29 MetadataBuilder; |
| 30 |
| 31 export 'type_variable_builder.dart' show |
| 32 TypeVariableBuilder; |
| 33 |
| 34 export 'function_type_alias_builder.dart' show |
| 35 FunctionTypeAliasBuilder; |
| 36 |
| 37 export 'named_mixin_application_builder.dart' show |
| 38 NamedMixinApplicationBuilder; |
| 39 |
| 40 export 'mixin_application_builder.dart' show |
| 41 MixinApplicationBuilder; |
| 42 |
| 43 export 'enum_builder.dart' show |
| 44 EnumBuilder; |
| 45 |
| 46 export 'type_declaration_builder.dart' show |
| 47 TypeDeclarationBuilder; |
| 48 |
| 49 export 'interface_type_builder.dart' show |
| 50 InterfaceTypeBuilder; |
| 51 |
| 52 export 'constructor_reference_builder.dart' show |
| 53 ConstructorReferenceBuilder; |
| 54 |
| 55 export '../source/unhandled_listener.dart' show |
| 56 Unhandled; |
| 57 |
| 58 export 'member_builder.dart' show |
| 59 MemberBuilder; |
| 60 |
| 61 export 'modifier_builder.dart' show |
| 62 ModifierBuilder; |
| 63 |
| 64 export 'prefix_builder.dart' show |
| 65 PrefixBuilder; |
| 66 |
| 67 export 'invalid_type_builder.dart' show |
| 68 InvalidTypeBuilder; |
| 69 |
| 70 export 'mixed_accessor.dart' show |
| 71 MixedAccessor; |
| 72 |
| 73 export 'scope.dart' show |
| 74 AccessErrorBuilder; |
| 75 |
| 76 export 'dynamic_type_builder.dart' show |
| 77 DynamicTypeBuilder; |
| 78 |
| 79 import 'library_builder.dart' show |
| 80 LibraryBuilder; |
| 81 |
| 82 abstract class Builder { |
| 83 /// Used when multiple things with the same name are declared within the same |
| 84 /// parent. Only used for declarations, not for scopes. |
| 85 /// |
| 86 // TODO(ahe): Move to member builder or something. Then we can make |
| 87 // this a const class. |
| 88 Builder next; |
| 89 |
| 90 /// Resolve types (lookup names in scope) recorded in this builder and return |
| 91 /// the number of types resolved. |
| 92 int resolveTypes(Builder parent) => 0; |
| 93 |
| 94 /// Resolve constructors (lookup names in scope) recorded in this builder and |
| 95 /// return the number of constructors resolved. |
| 96 int resolveConstructors(Builder parent) => 0; |
| 97 |
| 98 /// Look for methods with the same name as their enclosing class and convert |
| 99 /// them to constructors. Return the number of methods converted to |
| 100 /// constructors. |
| 101 int convertConstructors(Builder parent) => 0; |
| 102 |
| 103 /// This builder and [other] has been imported into [library] using [name]. |
| 104 /// |
| 105 /// This method handles this case according to the Dart language |
| 106 /// specification. |
| 107 Builder combineAmbiguousImport(String name, Builder other, |
| 108 LibraryBuilder library) { |
| 109 if (other == this) return this; |
| 110 bool isLocal = false; |
| 111 Builder preferred; |
| 112 Builder hidden; |
| 113 if (library.members[name] == this) { |
| 114 isLocal = true; |
| 115 preferred = this; |
| 116 hidden = other; |
| 117 } else if (getUri(other)?.scheme == "dart" && |
| 118 getUri(this)?.scheme != "dart") { |
| 119 preferred = this; |
| 120 hidden = other; |
| 121 } else if (getUri(this)?.scheme == "dart" && |
| 122 getUri(other)?.scheme != "dart") { |
| 123 preferred = other; |
| 124 hidden = this; |
| 125 } else { |
| 126 print("${library.uri}: Note: '$name' is imported from both " |
| 127 "'${getUri(this)}' and '${getUri(other)}'."); |
| 128 return library.buildAmbiguousBuilder(name, this, other); |
| 129 } |
| 130 if (isLocal) { |
| 131 print("${library.uri}: Note: local definition of '$name' hides imported " |
| 132 "version from '${getUri(other)}'."); |
| 133 } else { |
| 134 print("${library.uri}: import of '$name' (from '${getUri(preferred)}') " |
| 135 "hides imported version from '${getUri(hidden)}'."); |
| 136 } |
| 137 return preferred; |
| 138 } |
| 139 |
| 140 Builder get parent => null; |
| 141 |
| 142 bool get isFinal => false; |
| 143 |
| 144 bool get isField => false; |
| 145 |
| 146 bool get isRegularMethod => false; |
| 147 |
| 148 bool get isGetter => false; |
| 149 |
| 150 bool get isSetter => false; |
| 151 |
| 152 bool get isInstanceMember => false; |
| 153 |
| 154 bool get isStatic => false; |
| 155 |
| 156 bool get isTopLevel => false; |
| 157 |
| 158 bool get isTypeDeclaration => false; |
| 159 |
| 160 bool get isConstructor => false; |
| 161 |
| 162 bool get isFactory => false; |
| 163 |
| 164 bool get isLocal => false; |
| 165 |
| 166 get target => internalError("Unsupported operation $runtimeType."); |
| 167 |
| 168 bool get hasProblem => false; |
| 169 |
| 170 static Uri getUri(Builder builder) { |
| 171 if (builder == null) return internalError("Builder is null."); |
| 172 while (builder != null) { |
| 173 if (builder is LibraryBuilder) return builder.uri; |
| 174 builder = builder.parent; |
| 175 } |
| 176 return internalError("No library parent."); |
| 177 } |
| 178 } |
OLD | NEW |