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

Unified Diff: pkg/front_end/lib/src/fasta/kernel/body_builder.dart

Issue 2968093003: Improve parsing of function expressions. (Closed)
Patch Set: Update to new message API. Created 3 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: pkg/front_end/lib/src/fasta/kernel/body_builder.dart
diff --git a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
index d10042e5b453a8aff8f9d3ad0bfa489f9fb39c90..7e768cd69e87712806ad98efc64920f4dce936fc 100644
--- a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
@@ -2437,20 +2437,26 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
}
@override
- void beginFunction(Token token) {
- debugEvent("beginFunction");
+ void beginFunctionDeclaration(Token token) {
+ debugEvent("beginNamedFunctionExpression");
enterFunction();
}
@override
- void beginUnnamedFunction(Token token) {
- debugEvent("beginUnnamedFunction");
+ void beginNamedFunctionExpression(Token token) {
+ debugEvent("beginNamedFunctionExpression");
enterFunction();
}
@override
- void endFunction(Token getOrSet, Token endToken) {
- debugEvent("Function");
+ void beginFunctionExpression(Token token) {
+ debugEvent("beginFunctionExpression");
+ enterFunction();
+ }
+
+ @override
+ void endNamedFunctionExpression(Token endToken) {
+ debugEvent("NamedFunctionExpression");
Statement body = popStatement();
AsyncMarker asyncModifier = pop();
if (functionNestingLevel != 0) {
@@ -2458,16 +2464,39 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
}
FormalParameters formals = pop();
List<TypeParameter> typeParameters = typeVariableBuildersToKernel(pop());
- push(formals.addToFunction(new FunctionNode(body,
- typeParameters: typeParameters, asyncMarker: asyncModifier)
- ..fileOffset = formals.charOffset
- ..fileEndOffset = endToken.charOffset));
+
+ exitLocalScope();
+ KernelFunctionDeclaration declaration = pop();
+ VariableDeclaration variable = declaration.variable;
+ var returnType = pop();
+ returnType ??= const DynamicType();
+ pop(); // Modifiers.
+ exitFunction();
+
+ variable.initializer = new KernelFunctionExpression(formals.addToFunction(
+ new FunctionNode(body,
+ typeParameters: typeParameters, asyncMarker: asyncModifier)
+ ..fileOffset = formals.charOffset
+ ..fileEndOffset = endToken.charOffset))
+ ..parent = variable
+ ..fileOffset = formals.charOffset;
+ push(new Let(variable, new VariableGet(variable)));
}
@override
- void endFunctionDeclaration(Token token) {
+ void endFunctionDeclaration(Token endToken) {
debugEvent("FunctionDeclaration");
- FunctionNode function = pop();
+ Statement body = popStatement();
+ AsyncMarker asyncModifier = pop();
+ if (functionNestingLevel != 0) {
+ exitLocalScope();
+ }
+ FormalParameters formals = pop();
+ List<TypeParameter> typeParameters = typeVariableBuildersToKernel(pop());
+ FunctionNode function = formals.addToFunction(new FunctionNode(body,
+ typeParameters: typeParameters, asyncMarker: asyncModifier)
+ ..fileOffset = formals.charOffset
+ ..fileEndOffset = endToken.charOffset);
exitLocalScope();
var declaration = pop();
var returnType = pop();
@@ -2494,8 +2523,8 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
}
@override
- void endUnnamedFunction(Token beginToken, Token token) {
- debugEvent("UnnamedFunction");
+ void endFunctionExpression(Token beginToken, Token token) {
+ debugEvent("FunctionExpression");
Statement body = popStatement();
AsyncMarker asyncModifier = pop();
exitLocalScope();
« no previous file with comments | « pkg/front_end/lib/src/fasta/fasta_codes_generated.dart ('k') | pkg/front_end/lib/src/fasta/parser/listener.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698