| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 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 | 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 fasta.kernel_library_builder; | 5 library fasta.kernel_library_builder; |
| 6 | 6 |
| 7 import 'package:kernel/ast.dart'; | 7 import 'package:kernel/ast.dart'; |
| 8 | 8 |
| 9 import 'package:kernel/clone.dart' show CloneVisitor; | 9 import 'package:kernel/clone.dart' show CloneVisitor; |
| 10 | 10 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 | 146 |
| 147 void addField(List<MetadataBuilder> metadata, int modifiers, | 147 void addField(List<MetadataBuilder> metadata, int modifiers, |
| 148 KernelTypeBuilder type, String name, int charOffset) { | 148 KernelTypeBuilder type, String name, int charOffset) { |
| 149 addBuilder( | 149 addBuilder( |
| 150 name, | 150 name, |
| 151 new KernelFieldBuilder( | 151 new KernelFieldBuilder( |
| 152 metadata, type, name, modifiers, this, charOffset), | 152 metadata, type, name, modifiers, this, charOffset), |
| 153 charOffset); | 153 charOffset); |
| 154 } | 154 } |
| 155 | 155 |
| 156 String computeConstructorName(String name) { |
| 157 assert(isConstructorName(name, currentDeclaration.name)); |
| 158 int index = name.indexOf("."); |
| 159 return index == -1 ? "" : name.substring(index + 1); |
| 160 } |
| 161 |
| 156 void addProcedure( | 162 void addProcedure( |
| 157 List<MetadataBuilder> metadata, | 163 List<MetadataBuilder> metadata, |
| 158 int modifiers, | 164 int modifiers, |
| 159 KernelTypeBuilder returnType, | 165 KernelTypeBuilder returnType, |
| 160 String name, | 166 String name, |
| 161 List<TypeVariableBuilder> typeVariables, | 167 List<TypeVariableBuilder> typeVariables, |
| 162 List<FormalParameterBuilder> formals, | 168 List<FormalParameterBuilder> formals, |
| 163 AsyncMarker asyncModifier, | 169 AsyncMarker asyncModifier, |
| 164 ProcedureKind kind, | 170 ProcedureKind kind, |
| 165 int charOffset, | 171 int charOffset, |
| 166 int charEndOffset, | 172 int charEndOffset, |
| 167 String nativeMethodName, | 173 String nativeMethodName, |
| 168 {bool isTopLevel}) { | 174 {bool isTopLevel}) { |
| 169 // Nested declaration began in `OutlineBuilder.beginMethod` or | 175 // Nested declaration began in `OutlineBuilder.beginMethod` or |
| 170 // `OutlineBuilder.beginTopLevelMethod`. | 176 // `OutlineBuilder.beginTopLevelMethod`. |
| 171 endNestedDeclaration().resolveTypes(typeVariables, this); | 177 endNestedDeclaration().resolveTypes(typeVariables, this); |
| 172 ProcedureBuilder procedure; | 178 ProcedureBuilder procedure; |
| 173 if (!isTopLevel && isConstructorName(name, currentDeclaration.name)) { | 179 if (!isTopLevel && isConstructorName(name, currentDeclaration.name)) { |
| 174 int index = name.indexOf("."); | 180 name = computeConstructorName(name); |
| 175 name = index == -1 ? "" : name.substring(index + 1); | |
| 176 procedure = new KernelConstructorBuilder( | 181 procedure = new KernelConstructorBuilder( |
| 177 metadata, | 182 metadata, |
| 178 modifiers & ~abstractMask, | 183 modifiers & ~abstractMask, |
| 179 returnType, | 184 returnType, |
| 180 name, | 185 name, |
| 181 typeVariables, | 186 typeVariables, |
| 182 formals, | 187 formals, |
| 183 this, | 188 this, |
| 184 charOffset, | 189 charOffset, |
| 185 charEndOffset, | 190 charEndOffset, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 212 List<FormalParameterBuilder> formals, | 217 List<FormalParameterBuilder> formals, |
| 213 AsyncMarker asyncModifier, | 218 AsyncMarker asyncModifier, |
| 214 ConstructorReferenceBuilder redirectionTarget, | 219 ConstructorReferenceBuilder redirectionTarget, |
| 215 int charOffset, | 220 int charOffset, |
| 216 int charEndOffset, | 221 int charEndOffset, |
| 217 String nativeMethodName) { | 222 String nativeMethodName) { |
| 218 // Nested declaration began in `OutlineBuilder.beginFactoryMethod`. | 223 // Nested declaration began in `OutlineBuilder.beginFactoryMethod`. |
| 219 DeclarationBuilder<KernelTypeBuilder> factoryDeclaration = | 224 DeclarationBuilder<KernelTypeBuilder> factoryDeclaration = |
| 220 endNestedDeclaration(); | 225 endNestedDeclaration(); |
| 221 String name = constructorName.name; | 226 String name = constructorName.name; |
| 222 int index = name.indexOf("."); | 227 if (isConstructorName(name, currentDeclaration.name)) { |
| 223 name = index == -1 ? "" : name.substring(index + 1); | 228 name = computeConstructorName(name); |
| 229 } |
| 224 assert(constructorName.suffix == null); | 230 assert(constructorName.suffix == null); |
| 225 KernelProcedureBuilder procedure = new KernelProcedureBuilder( | 231 KernelProcedureBuilder procedure = new KernelProcedureBuilder( |
| 226 metadata, | 232 metadata, |
| 227 staticMask | modifiers, | 233 staticMask | modifiers, |
| 228 null, | 234 null, |
| 229 name, | 235 name, |
| 230 <TypeVariableBuilder>[], | 236 <TypeVariableBuilder>[], |
| 231 formals, | 237 formals, |
| 232 asyncModifier, | 238 asyncModifier, |
| 233 ProcedureKind.Factory, | 239 ProcedureKind.Factory, |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 } | 433 } |
| 428 } | 434 } |
| 429 | 435 |
| 430 bool isConstructorName(String name, String className) { | 436 bool isConstructorName(String name, String className) { |
| 431 if (name.startsWith(className)) { | 437 if (name.startsWith(className)) { |
| 432 if (name.length == className.length) return true; | 438 if (name.length == className.length) return true; |
| 433 if (name.startsWith(".", className.length)) return true; | 439 if (name.startsWith(".", className.length)) return true; |
| 434 } | 440 } |
| 435 return false; | 441 return false; |
| 436 } | 442 } |
| OLD | NEW |