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

Side by Side Diff: pkg/compiler/lib/src/elements/entities.dart

Issue 2897273002: Add FunctionEntity.asyncMarker and refactor SourceInformationStrategy to avoid ResolvedAst (Closed)
Patch Set: Created 3 years, 7 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) 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 entities; 5 library entities;
6 6
7 import 'package:front_end/src/fasta/parser/async_modifier.dart'
8 show AsyncModifier;
9
7 import '../common.dart'; 10 import '../common.dart';
8 import '../universe/call_structure.dart' show CallStructure; 11 import '../universe/call_structure.dart' show CallStructure;
9 12
10 /// Abstract interface for entities. 13 /// Abstract interface for entities.
11 /// 14 ///
12 /// Implement this directly if the entity is not a Dart language entity. 15 /// Implement this directly if the entity is not a Dart language entity.
13 /// Entities defined within the Dart language should implement [Element]. 16 /// Entities defined within the Dart language should implement [Element].
14 /// 17 ///
15 /// For instance, the JavaScript backend need to create synthetic variables for 18 /// For instance, the JavaScript backend need to create synthetic variables for
16 /// calling intercepted classes and such variables do not correspond to an 19 /// calling intercepted classes and such variables do not correspond to an
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 /// 119 ///
117 /// Currently only [MethodElement] but later also kernel based Dart constructors 120 /// Currently only [MethodElement] but later also kernel based Dart constructors
118 /// and methods and/or Dart-in-JS function-like properties. 121 /// and methods and/or Dart-in-JS function-like properties.
119 abstract class FunctionEntity extends MemberEntity { 122 abstract class FunctionEntity extends MemberEntity {
120 /// Whether this function is external, i.e. the body is not defined in terms 123 /// Whether this function is external, i.e. the body is not defined in terms
121 /// of Dart code. 124 /// of Dart code.
122 bool get isExternal; 125 bool get isExternal;
123 126
124 /// The structure of the function parameters. 127 /// The structure of the function parameters.
125 ParameterStructure get parameterStructure; 128 ParameterStructure get parameterStructure;
129
130 /// The synchronous/asynchronous marker on this function.
131 AsyncMarker get asyncMarker;
132 }
133
134 /// Enum for the synchronous/asynchronous function body modifiers.
135 class AsyncMarker {
136 /// The default function body marker.
137 static const AsyncMarker SYNC = const AsyncMarker._(AsyncModifier.Sync);
138
139 /// The `sync*` function body marker.
140 static const AsyncMarker SYNC_STAR =
141 const AsyncMarker._(AsyncModifier.SyncStar, isYielding: true);
142
143 /// The `async` function body marker.
144 static const AsyncMarker ASYNC =
145 const AsyncMarker._(AsyncModifier.Async, isAsync: true);
146
147 /// The `async*` function body marker.
148 static const AsyncMarker ASYNC_STAR = const AsyncMarker._(
149 AsyncModifier.AsyncStar,
150 isAsync: true,
151 isYielding: true);
152
153 /// Is `true` if this marker defines the function body to have an
154 /// asynchronous result, that is, either a [Future] or a [Stream].
155 final bool isAsync;
156
157 /// Is `true` if this marker defines the function body to have a plural
158 /// result, that is, either an [Iterable] or a [Stream].
159 final bool isYielding;
160
161 final AsyncModifier asyncParserState;
162
163 const AsyncMarker._(this.asyncParserState,
164 {this.isAsync: false, this.isYielding: false});
165
166 String toString() {
167 return '${isAsync ? 'async' : 'sync'}${isYielding ? '*' : ''}';
168 }
169
170 /// Canonical list of marker values.
171 ///
172 /// Added to make [AsyncMarker] enum-like.
173 static const List<AsyncMarker> values = const <AsyncMarker>[
174 SYNC,
175 SYNC_STAR,
176 ASYNC,
177 ASYNC_STAR
178 ];
179
180 /// Index to this marker within [values].
181 ///
182 /// Added to make [AsyncMarker] enum-like.
183 int get index => values.indexOf(this);
126 } 184 }
127 185
128 /// Stripped down super interface for constructor like entities. 186 /// Stripped down super interface for constructor like entities.
129 /// 187 ///
130 /// Currently only [ConstructorElement] but later also kernel based Dart 188 /// Currently only [ConstructorElement] but later also kernel based Dart
131 /// constructors and/or Dart-in-JS constructor-like properties. 189 /// constructors and/or Dart-in-JS constructor-like properties.
132 // TODO(johnniwinther): Remove factory constructors from the set of 190 // TODO(johnniwinther): Remove factory constructors from the set of
133 // constructors. 191 // constructors.
134 abstract class ConstructorEntity extends FunctionEntity { 192 abstract class ConstructorEntity extends FunctionEntity {
135 /// Whether this is a generative constructor, possibly redirecting. 193 /// Whether this is a generative constructor, possibly redirecting.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 int get optionalParameters => 243 int get optionalParameters =>
186 positionalParameters - requiredParameters + namedParameters.length; 244 positionalParameters - requiredParameters + namedParameters.length;
187 245
188 /// Returns the [CallStructure] corresponding to a call site passing all 246 /// Returns the [CallStructure] corresponding to a call site passing all
189 /// parameters both required and optional. 247 /// parameters both required and optional.
190 CallStructure get callStructure { 248 CallStructure get callStructure {
191 return new CallStructure( 249 return new CallStructure(
192 positionalParameters + namedParameters.length, namedParameters); 250 positionalParameters + namedParameters.length, namedParameters);
193 } 251 }
194 } 252 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/elements/elements.dart ('k') | pkg/compiler/lib/src/io/multi_information.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698