| 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.fasta_accessors; | 5 library fasta.fasta_accessors; |
| 6 | 6 |
| 7 export 'frontend_accessors.dart' show wrapInvalid; | 7 export 'frontend_accessors.dart' show wrapInvalid; |
| 8 | 8 |
| 9 import 'frontend_accessors.dart' show Accessor, buildIsNull, makeLet; | 9 import 'frontend_accessors.dart' show Accessor, buildIsNull, makeLet; |
| 10 | 10 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 Member lookupSuperMember(Name name, {bool isSetter: false}); | 44 Member lookupSuperMember(Name name, {bool isSetter: false}); |
| 45 | 45 |
| 46 scopeLookup(Scope scope, String name, int offset, | 46 scopeLookup(Scope scope, String name, int offset, |
| 47 {bool isQualified: false, PrefixBuilder prefix}); | 47 {bool isQualified: false, PrefixBuilder prefix}); |
| 48 | 48 |
| 49 finishSend(Object receiver, Arguments arguments, int offset); | 49 finishSend(Object receiver, Arguments arguments, int offset); |
| 50 | 50 |
| 51 Expression buildCompileTimeError(error, [int offset]); | 51 Expression buildCompileTimeError(error, [int offset]); |
| 52 | 52 |
| 53 Initializer buildCompileTimeErrorIntializer(error, [int offset]); | 53 Initializer buildInvalidIntializer(Expression expression, [int offset]); |
| 54 |
| 55 Initializer buildSuperInitializer( |
| 56 Constructor constructor, Arguments arguments, |
| 57 [int offset]); |
| 58 |
| 59 Initializer buildRedirectingInitializer( |
| 60 Constructor constructor, Arguments arguments, |
| 61 [int charOffset = -1]); |
| 54 | 62 |
| 55 Expression buildStaticInvocation(Procedure target, Arguments arguments); | 63 Expression buildStaticInvocation(Procedure target, Arguments arguments); |
| 56 | 64 |
| 57 Expression buildProblemExpression(ProblemBuilder builder, int offset); | 65 Expression buildProblemExpression(ProblemBuilder builder, int offset); |
| 58 | 66 |
| 59 Expression throwNoSuchMethodError( | 67 Expression throwNoSuchMethodError( |
| 60 String name, Arguments arguments, int offset, | 68 String name, Arguments arguments, int offset, |
| 61 {bool isSuper: false, isGetter: false, isSetter: false}); | 69 {bool isSuper: false, isGetter: false, isSetter: false}); |
| 70 |
| 71 bool checkArguments(FunctionNode function, Arguments arguments, |
| 72 List<TypeParameter> typeParameters); |
| 62 } | 73 } |
| 63 | 74 |
| 64 abstract class FastaAccessor implements Accessor { | 75 abstract class FastaAccessor implements Accessor { |
| 65 BuilderHelper get helper; | 76 BuilderHelper get helper; |
| 66 | 77 |
| 67 String get plainNameForRead; | 78 String get plainNameForRead; |
| 68 | 79 |
| 69 Uri get uri => helper.uri; | 80 Uri get uri => helper.uri; |
| 70 | 81 |
| 71 String get plainNameForWrite => plainNameForRead; | 82 String get plainNameForWrite => plainNameForRead; |
| 72 | 83 |
| 84 bool get isInitializer => false; |
| 85 |
| 73 Expression buildForEffect() => buildSimpleRead(); | 86 Expression buildForEffect() => buildSimpleRead(); |
| 74 | 87 |
| 75 Initializer buildFieldInitializer( | 88 Initializer buildFieldInitializer( |
| 76 Map<String, FieldInitializer> initializers) { | 89 Map<String, FieldInitializer> initializers) { |
| 77 // TODO(ahe): This error message is really bad. | 90 return helper.buildInvalidIntializer( |
| 78 return helper.buildCompileTimeErrorIntializer( | 91 helper.buildCompileTimeError( |
| 79 "Can't use $plainNameForRead here.", offset); | 92 // TODO(ahe): This error message is really bad. |
| 93 "Can't use $plainNameForRead here.", |
| 94 offset), |
| 95 offset); |
| 80 } | 96 } |
| 81 | 97 |
| 82 Expression makeInvalidRead() { | 98 Expression makeInvalidRead() { |
| 83 return buildThrowNoSuchMethodError(new Arguments.empty(), isGetter: true); | 99 return buildThrowNoSuchMethodError(new Arguments.empty(), isGetter: true); |
| 84 } | 100 } |
| 85 | 101 |
| 86 Expression makeInvalidWrite(Expression value) { | 102 Expression makeInvalidWrite(Expression value) { |
| 87 return buildThrowNoSuchMethodError(new Arguments(<Expression>[value]), | 103 return buildThrowNoSuchMethodError(new Arguments(<Expression>[value]), |
| 88 isSetter: true); | 104 isSetter: true); |
| 89 } | 105 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 Name get name => internalError("Unsupported operation."); | 160 Name get name => internalError("Unsupported operation."); |
| 145 | 161 |
| 146 @override | 162 @override |
| 147 String get plainNameForRead => name.name; | 163 String get plainNameForRead => name.name; |
| 148 | 164 |
| 149 withReceiver(Object receiver, {bool isNullAware}) => this; | 165 withReceiver(Object receiver, {bool isNullAware}) => this; |
| 150 | 166 |
| 151 @override | 167 @override |
| 152 Initializer buildFieldInitializer( | 168 Initializer buildFieldInitializer( |
| 153 Map<String, FieldInitializer> initializers) { | 169 Map<String, FieldInitializer> initializers) { |
| 154 return new LocalInitializer(new VariableDeclaration.forValue( | 170 return helper.buildInvalidIntializer( |
| 155 buildError(new Arguments.empty(), isSetter: true))); | 171 buildError(new Arguments.empty(), isSetter: true)); |
| 156 } | 172 } |
| 157 | 173 |
| 158 @override | 174 @override |
| 159 doInvocation(int offset, Arguments arguments) { | 175 doInvocation(int offset, Arguments arguments) { |
| 160 return buildError(arguments, offset: offset); | 176 return buildError(arguments, offset: offset); |
| 161 } | 177 } |
| 162 | 178 |
| 163 @override | 179 @override |
| 164 buildPropertyAccess(IncompleteSend send, bool isNullAware) => this; | 180 buildPropertyAccess(IncompleteSend send, bool isNullAware) => this; |
| 165 | 181 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 return new ThisExpression(); | 275 return new ThisExpression(); |
| 260 } else { | 276 } else { |
| 261 return helper.buildCompileTimeError( | 277 return helper.buildCompileTimeError( |
| 262 "Can't use `super` as an expression.", offset); | 278 "Can't use `super` as an expression.", offset); |
| 263 } | 279 } |
| 264 } | 280 } |
| 265 | 281 |
| 266 Initializer buildFieldInitializer( | 282 Initializer buildFieldInitializer( |
| 267 Map<String, FieldInitializer> initializers) { | 283 Map<String, FieldInitializer> initializers) { |
| 268 String keyword = isSuper ? "super" : "this"; | 284 String keyword = isSuper ? "super" : "this"; |
| 269 return helper.buildCompileTimeErrorIntializer( | 285 return helper.buildInvalidIntializer( |
| 270 "Can't use '$keyword' here, did you mean '$keyword()'?", offset); | 286 helper.buildCompileTimeError( |
| 287 "Can't use '$keyword' here, did you mean '$keyword()'?", offset), |
| 288 offset); |
| 271 } | 289 } |
| 272 | 290 |
| 273 buildPropertyAccess(IncompleteSend send, bool isNullAware) { | 291 buildPropertyAccess(IncompleteSend send, bool isNullAware) { |
| 274 if (isInitializer && send is SendAccessor) { | 292 if (isInitializer && send is SendAccessor) { |
| 275 return buildConstructorInitializer( | 293 return buildConstructorInitializer( |
| 276 send.offset, send.name, send.arguments); | 294 send.offset, send.name, send.arguments); |
| 277 } | 295 } |
| 278 if (send is SendAccessor) { | 296 if (send is SendAccessor) { |
| 279 // Notice that 'this' or 'super' can't be null. So we can ignore the | 297 // Notice that 'this' or 'super' can't be null. So we can ignore the |
| 280 // value of [isNullAware]. | 298 // value of [isNullAware]. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 299 return buildConstructorInitializer(offset, new Name(""), arguments); | 317 return buildConstructorInitializer(offset, new Name(""), arguments); |
| 300 } else { | 318 } else { |
| 301 return buildMethodInvocation( | 319 return buildMethodInvocation( |
| 302 new ThisExpression(), callName, arguments, offset); | 320 new ThisExpression(), callName, arguments, offset); |
| 303 } | 321 } |
| 304 } | 322 } |
| 305 | 323 |
| 306 Initializer buildConstructorInitializer( | 324 Initializer buildConstructorInitializer( |
| 307 int offset, Name name, Arguments arguments) { | 325 int offset, Name name, Arguments arguments) { |
| 308 Constructor constructor = helper.lookupConstructor(name, isSuper: isSuper); | 326 Constructor constructor = helper.lookupConstructor(name, isSuper: isSuper); |
| 309 Initializer result; | 327 if (constructor == null || |
| 310 if (constructor == null) { | 328 !helper.checkArguments( |
| 311 result = new LocalInitializer(new VariableDeclaration.forValue( | 329 constructor.function, arguments, <TypeParameter>[])) { |
| 330 return helper.buildInvalidIntializer( |
| 312 buildThrowNoSuchMethodError(arguments, | 331 buildThrowNoSuchMethodError(arguments, |
| 313 isSuper: isSuper, name: name.name, offset: offset))); | 332 isSuper: isSuper, name: name.name, offset: offset), |
| 333 offset); |
| 314 } else if (isSuper) { | 334 } else if (isSuper) { |
| 315 result = new SuperInitializer(constructor, arguments); | 335 return helper.buildSuperInitializer(constructor, arguments, offset); |
| 316 } else { | 336 } else { |
| 317 result = new RedirectingInitializer(constructor, arguments); | 337 return helper.buildRedirectingInitializer(constructor, arguments, offset); |
| 318 } | 338 } |
| 319 return result..fileOffset = offset; | |
| 320 } | 339 } |
| 321 | 340 |
| 322 Expression buildAssignment(Expression value, {bool voidContext: false}) { | 341 Expression buildAssignment(Expression value, {bool voidContext: false}) { |
| 323 return buildAssignmentError(); | 342 return buildAssignmentError(); |
| 324 } | 343 } |
| 325 | 344 |
| 326 Expression buildNullAwareAssignment(Expression value, DartType type, | 345 Expression buildNullAwareAssignment(Expression value, DartType type, |
| 327 {bool voidContext: false}) { | 346 {bool voidContext: false}) { |
| 328 return buildAssignmentError(); | 347 return buildAssignmentError(); |
| 329 } | 348 } |
| (...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 new ConditionalExpression( | 891 new ConditionalExpression( |
| 873 buildIsNull(new VariableGet(variable)), | 892 buildIsNull(new VariableGet(variable)), |
| 874 new NullLiteral(), | 893 new NullLiteral(), |
| 875 new MethodInvocation(new VariableGet(variable), name, arguments) | 894 new MethodInvocation(new VariableGet(variable), name, arguments) |
| 876 ..fileOffset = offset, | 895 ..fileOffset = offset, |
| 877 const DynamicType())); | 896 const DynamicType())); |
| 878 } else { | 897 } else { |
| 879 return new MethodInvocation(receiver, name, arguments)..fileOffset = offset; | 898 return new MethodInvocation(receiver, name, arguments)..fileOffset = offset; |
| 880 } | 899 } |
| 881 } | 900 } |
| OLD | NEW |