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.body_builder; | 5 library fasta.body_builder; |
6 | 6 |
7 import '../fasta_codes.dart' | 7 import '../fasta_codes.dart' |
8 show FastaMessage, codeExpectedButGot, codeExpectedFunctionBody; | 8 show FastaMessage, codeExpectedButGot, codeExpectedFunctionBody; |
9 | 9 |
10 import '../parser/parser.dart' show FormalParameterType, optional; | 10 import '../parser/parser.dart' show FormalParameterType, optional; |
11 | 11 |
12 import '../parser/identifier_context.dart' show IdentifierContext; | 12 import '../parser/identifier_context.dart' show IdentifierContext; |
13 | 13 |
14 import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart' | |
ahe
2017/04/18 15:49:59
Make relative?
Paul Berry
2017/04/18 16:33:17
I actually prefer absolute imports, and I was hopi
| |
15 show KernelVariableDeclaration; | |
16 | |
17 import 'package:front_end/src/fasta/type_inference/type_inferrer.dart' | |
18 show TypeInferrer; | |
19 | |
14 import 'package:kernel/ast.dart'; | 20 import 'package:kernel/ast.dart'; |
15 | 21 |
16 import 'package:kernel/clone.dart' show CloneVisitor; | 22 import 'package:kernel/clone.dart' show CloneVisitor; |
17 | 23 |
18 import 'package:kernel/transformations/flags.dart' show TransformerFlag; | 24 import 'package:kernel/transformations/flags.dart' show TransformerFlag; |
19 | 25 |
20 import 'package:kernel/class_hierarchy.dart' show ClassHierarchy; | 26 import 'package:kernel/class_hierarchy.dart' show ClassHierarchy; |
21 | 27 |
22 import 'package:kernel/core_types.dart' show CoreTypes; | 28 import 'package:kernel/core_types.dart' show CoreTypes; |
23 | 29 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 final Map<String, FieldInitializer> fieldInitializers = | 78 final Map<String, FieldInitializer> fieldInitializers = |
73 <String, FieldInitializer>{}; | 79 <String, FieldInitializer>{}; |
74 | 80 |
75 final Scope enclosingScope; | 81 final Scope enclosingScope; |
76 | 82 |
77 final bool isDartLibrary; | 83 final bool isDartLibrary; |
78 | 84 |
79 @override | 85 @override |
80 final Uri uri; | 86 final Uri uri; |
81 | 87 |
88 final TypeInferrer<Statement, Expression, KernelVariableDeclaration, Field> | |
89 _typeInferrer; | |
ahe
2017/04/18 15:49:59
I prefer to keep things public unless implementing
Paul Berry
2017/04/18 16:33:17
Heh, I prefer the reverse. Let's talk about this
| |
90 | |
82 Scope formalParameterScope; | 91 Scope formalParameterScope; |
83 | 92 |
84 bool inInitializer = false; | 93 bool inInitializer = false; |
85 | 94 |
86 bool inCatchClause = false; | 95 bool inCatchClause = false; |
87 | 96 |
88 int functionNestingLevel = 0; | 97 int functionNestingLevel = 0; |
89 | 98 |
90 Statement compileTimeErrorInTry; | 99 Statement compileTimeErrorInTry; |
91 | 100 |
(...skipping 13 matching lines...) Expand all Loading... | |
105 | 114 |
106 BodyBuilder( | 115 BodyBuilder( |
107 KernelLibraryBuilder library, | 116 KernelLibraryBuilder library, |
108 this.member, | 117 this.member, |
109 Scope scope, | 118 Scope scope, |
110 this.formalParameterScope, | 119 this.formalParameterScope, |
111 this.hierarchy, | 120 this.hierarchy, |
112 this.coreTypes, | 121 this.coreTypes, |
113 this.classBuilder, | 122 this.classBuilder, |
114 this.isInstanceMember, | 123 this.isInstanceMember, |
115 this.uri) | 124 this.uri, |
125 this._typeInferrer) | |
116 : enclosingScope = scope, | 126 : enclosingScope = scope, |
117 library = library, | 127 library = library, |
118 isDartLibrary = library.uri.scheme == "dart", | 128 isDartLibrary = library.uri.scheme == "dart", |
119 super(scope); | 129 super(scope); |
120 | 130 |
121 bool get hasParserError => recoverableErrors.isNotEmpty; | 131 bool get hasParserError => recoverableErrors.isNotEmpty; |
122 | 132 |
123 bool get inConstructor { | 133 bool get inConstructor { |
124 return functionNestingLevel == 0 && member is KernelConstructorBuilder; | 134 return functionNestingLevel == 0 && member is KernelConstructorBuilder; |
125 } | 135 } |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
416 if (asyncModifier != AsyncMarker.Sync) { | 426 if (asyncModifier != AsyncMarker.Sync) { |
417 // TODO(ahe): Change this to a null check. | 427 // TODO(ahe): Change this to a null check. |
418 addCompileTimeError(body?.fileOffset, | 428 addCompileTimeError(body?.fileOffset, |
419 "Can't be marked as ${asyncModifier}: ${builder.name}"); | 429 "Can't be marked as ${asyncModifier}: ${builder.name}"); |
420 } | 430 } |
421 } else if (builder is KernelProcedureBuilder) { | 431 } else if (builder is KernelProcedureBuilder) { |
422 builder.asyncModifier = asyncModifier; | 432 builder.asyncModifier = asyncModifier; |
423 } else { | 433 } else { |
424 internalError("Unhandled: ${builder.runtimeType}"); | 434 internalError("Unhandled: ${builder.runtimeType}"); |
425 } | 435 } |
436 _typeInferrer.inferBody(body, uri); | |
426 builder.body = body; | 437 builder.body = body; |
427 if (formals?.optional != null) { | 438 if (formals?.optional != null) { |
428 Iterator<FormalParameterBuilder> formalBuilders = | 439 Iterator<FormalParameterBuilder> formalBuilders = |
429 builder.formals.skip(formals.required.length).iterator; | 440 builder.formals.skip(formals.required.length).iterator; |
430 for (VariableDeclaration parameter in formals.optional.formals) { | 441 for (VariableDeclaration parameter in formals.optional.formals) { |
431 bool hasMore = formalBuilders.moveNext(); | 442 bool hasMore = formalBuilders.moveNext(); |
432 assert(hasMore); | 443 assert(hasMore); |
433 VariableDeclaration realParameter = formalBuilders.current.target; | 444 VariableDeclaration realParameter = formalBuilders.current.target; |
434 Expression initializer = parameter.initializer ?? new NullLiteral(); | 445 Expression initializer = parameter.initializer ?? new NullLiteral(); |
435 realParameter.initializer = initializer..parent = realParameter; | 446 realParameter.initializer = initializer..parent = realParameter; |
(...skipping 2504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2940 } else if (node is PrefixBuilder) { | 2951 } else if (node is PrefixBuilder) { |
2941 return node.name; | 2952 return node.name; |
2942 } else if (node is ThisAccessor) { | 2953 } else if (node is ThisAccessor) { |
2943 return node.isSuper ? "super" : "this"; | 2954 return node.isSuper ? "super" : "this"; |
2944 } else if (node is FastaAccessor) { | 2955 } else if (node is FastaAccessor) { |
2945 return node.plainNameForRead; | 2956 return node.plainNameForRead; |
2946 } else { | 2957 } else { |
2947 return internalError("Unhandled: ${node.runtimeType}"); | 2958 return internalError("Unhandled: ${node.runtimeType}"); |
2948 } | 2959 } |
2949 } | 2960 } |
OLD | NEW |