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

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

Issue 2876813002: Implement generalized function types. (Closed)
Patch Set: Fixes for analyzer and dart2js. 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 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, MemberKind, 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/builder/ast_factory.dart' show AstFactory; 14 import 'package:front_end/src/fasta/builder/ast_factory.dart' show AstFactory;
15 15
16 import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart' 16 import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart'
17 show 17 show
18 KernelArguments, 18 KernelArguments,
19 KernelField, 19 KernelField,
20 KernelFunctionDeclaration, 20 KernelFunctionDeclaration,
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 @override 329 @override
330 void endTopLevelFields(int count, Token beginToken, Token endToken) { 330 void endTopLevelFields(int count, Token beginToken, Token endToken) {
331 debugEvent("TopLevelFields"); 331 debugEvent("TopLevelFields");
332 doFields(count); 332 doFields(count);
333 // There's no metadata here because of a slight asymmetry between 333 // There's no metadata here because of a slight asymmetry between
334 // [parseTopLevelMember] and [parseMember]. This asymmetry leads to 334 // [parseTopLevelMember] and [parseMember]. This asymmetry leads to
335 // DietListener discarding top-level member metadata. 335 // DietListener discarding top-level member metadata.
336 } 336 }
337 337
338 @override 338 @override
339 void endFields( 339 void endFields(int count, Token beginToken, Token endToken) {
340 int count, Token covariantKeyword, Token beginToken, Token endToken) {
341 debugEvent("Fields"); 340 debugEvent("Fields");
342 doFields(count); 341 doFields(count);
343 pop(); // Metadata. 342 pop(); // Metadata.
344 } 343 }
345 344
346 void doFields(int count) { 345 void doFields(int count) {
347 for (int i = 0; i < count; i++) { 346 for (int i = 0; i < count; i++) {
348 Expression initializer = pop(); 347 Expression initializer = pop();
349 Identifier identifier = pop(); 348 Identifier identifier = pop();
350 if (initializer != null) { 349 if (initializer != null) {
(...skipping 1120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1471 if (!isInstanceContext && type.parameter.parent is Class) { 1470 if (!isInstanceContext && type.parameter.parent is Class) {
1472 pop(); 1471 pop();
1473 warning("Type variables can only be used in instance methods.", 1472 warning("Type variables can only be used in instance methods.",
1474 beginToken.charOffset); 1473 beginToken.charOffset);
1475 push(const DynamicType()); 1474 push(const DynamicType());
1476 } 1475 }
1477 } 1476 }
1478 } 1477 }
1479 1478
1480 @override 1479 @override
1480 void handleFunctionType(Token functionToken, Token endToken) {
1481 FormalParameters formals = pop();
1482 ignore(Unhandled.TypeVariables);
1483 DartType returnType = pop();
1484 push(formals.toFunctionType(returnType));
1485 }
1486
1487 @override
1481 void handleVoidKeyword(Token token) { 1488 void handleVoidKeyword(Token token) {
1482 debugEvent("VoidKeyword"); 1489 debugEvent("VoidKeyword");
1483 push(const VoidType()); 1490 push(const VoidType());
1484 } 1491 }
1485 1492
1486 @override 1493 @override
1487 void handleAsOperator(Token operator, Token endToken) { 1494 void handleAsOperator(Token operator, Token endToken) {
1488 debugEvent("AsOperator"); 1495 debugEvent("AsOperator");
1489 DartType type = pop(); 1496 DartType type = pop();
1490 Expression expression = popForValue(); 1497 Expression expression = popForValue();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1522 Expression expression = popForValue(); 1529 Expression expression = popForValue();
1523 if (constantExpressionRequired) { 1530 if (constantExpressionRequired) {
1524 push(buildCompileTimeError( 1531 push(buildCompileTimeError(
1525 "Not a constant expression.", throwToken.charOffset)); 1532 "Not a constant expression.", throwToken.charOffset));
1526 } else { 1533 } else {
1527 push(astFactory.throwExpression(throwToken, expression)); 1534 push(astFactory.throwExpression(throwToken, expression));
1528 } 1535 }
1529 } 1536 }
1530 1537
1531 @override 1538 @override
1532 void endFormalParameter(Token covariantKeyword, Token thisKeyword, 1539 void endFormalParameter(Token thisKeyword, Token nameToken,
1533 Token nameToken, FormalParameterType kind) { 1540 FormalParameterType kind, MemberKind memberKind) {
1534 debugEvent("FormalParameter"); 1541 debugEvent("FormalParameter");
1535 // TODO(ahe): Need beginToken here.
1536 int charOffset = thisKeyword?.charOffset;
1537 if (thisKeyword != null) { 1542 if (thisKeyword != null) {
1538 if (!inConstructor) { 1543 if (!inConstructor) {
1539 addCompileTimeError(thisKeyword.charOffset, 1544 addCompileTimeError(thisKeyword.charOffset,
1540 "'this' parameters can only be used on constructors."); 1545 "'this' parameters can only be used on constructors.");
1541 thisKeyword = null; 1546 thisKeyword = null;
1542 } 1547 }
1543 } 1548 }
1544 Identifier name = pop(); 1549 Identifier name = pop();
1545 DartType type = pop(); 1550 DartType type = pop();
1546 int modifiers = Modifier.validate(pop()); 1551 int modifiers = Modifier.validate(pop());
1547 if (inCatchClause) { 1552 if (inCatchClause) {
1548 modifiers |= finalMask; 1553 modifiers |= finalMask;
1549 } 1554 }
1550 bool isConst = (modifiers & constMask) != 0; 1555 bool isConst = (modifiers & constMask) != 0;
1551 bool isFinal = (modifiers & finalMask) != 0; 1556 bool isFinal = (modifiers & finalMask) != 0;
1552 ignore(Unhandled.Metadata); 1557 ignore(Unhandled.Metadata);
1553 VariableDeclaration variable; 1558 VariableDeclaration variable;
1554 if (!inCatchClause && functionNestingLevel == 0) { 1559 if (!inCatchClause &&
1555 dynamic builder = formalParameterScope.lookup(name.name, charOffset, uri); 1560 functionNestingLevel == 0 &&
1561 memberKind != MemberKind.GeneralizedFunctionType) {
1562 dynamic builder = formalParameterScope.lookup(
1563 name.name, offsetForToken(name.token), uri);
1556 if (builder == null) { 1564 if (builder == null) {
1557 if (thisKeyword == null) { 1565 if (thisKeyword == null) {
1558 internalError("Internal error: formal missing for '${name.name}'"); 1566 internalError("Internal error: formal missing for '${name.name}'");
1559 } else { 1567 } else {
1560 addCompileTimeError(thisKeyword.charOffset, 1568 addCompileTimeError(thisKeyword.charOffset,
1561 "'${name.name}' isn't a field in this class."); 1569 "'${name.name}' isn't a field in this class.");
1562 thisKeyword = null; 1570 thisKeyword = null;
1563 } 1571 }
1564 } else if (thisKeyword == null) { 1572 } else if (thisKeyword == null) {
1565 variable = builder.build(library); 1573 variable = builder.build(library);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1602 } 1610 }
1603 1611
1604 @override 1612 @override
1605 void beginFunctionTypedFormalParameter(Token token) { 1613 void beginFunctionTypedFormalParameter(Token token) {
1606 debugEvent("beginFunctionTypedFormalParameter"); 1614 debugEvent("beginFunctionTypedFormalParameter");
1607 functionNestingLevel++; 1615 functionNestingLevel++;
1608 } 1616 }
1609 1617
1610 @override 1618 @override
1611 void endFunctionTypedFormalParameter( 1619 void endFunctionTypedFormalParameter(
1612 Token covariantKeyword, Token thisKeyword, FormalParameterType kind) { 1620 Token thisKeyword, FormalParameterType kind) {
1613 debugEvent("FunctionTypedFormalParameter"); 1621 debugEvent("FunctionTypedFormalParameter");
1614 if (inCatchClause || functionNestingLevel != 0) { 1622 if (inCatchClause || functionNestingLevel != 0) {
1615 exitLocalScope(); 1623 exitLocalScope();
1616 } 1624 }
1617 FormalParameters formals = pop(); 1625 FormalParameters formals = pop();
1618 ignore(Unhandled.TypeVariables); 1626 ignore(Unhandled.TypeVariables);
1619 Identifier name = pop(); 1627 Identifier name = pop();
1620 DartType returnType = pop(); 1628 DartType returnType = pop();
1621 push(formals.toFunctionType(returnType)); 1629 push(formals.toFunctionType(returnType));
1622 push(name); 1630 push(name);
1623 functionNestingLevel--; 1631 functionNestingLevel--;
1624 } 1632 }
1625 1633
1626 @override 1634 @override
1627 void handleValuedFormalParameter(Token equals, Token token) { 1635 void handleValuedFormalParameter(Token equals, Token token) {
1628 debugEvent("ValuedFormalParameter"); 1636 debugEvent("ValuedFormalParameter");
1629 Expression initializer = popForValue(); 1637 Expression initializer = popForValue();
1630 Identifier name = pop(); 1638 Identifier name = pop();
1631 push(new InitializedIdentifier(name.token, initializer)); 1639 push(new InitializedIdentifier(name.token, initializer));
1632 } 1640 }
1633 1641
1634 @override 1642 @override
1635 void handleFormalParameterWithoutValue(Token token) { 1643 void handleFormalParameterWithoutValue(Token token) {
1636 debugEvent("FormalParameterWithoutValue"); 1644 debugEvent("FormalParameterWithoutValue");
1637 } 1645 }
1638 1646
1639 @override 1647 @override
1640 void endFormalParameters(int count, Token beginToken, Token endToken) { 1648 void endFormalParameters(
1649 int count, Token beginToken, Token endToken, MemberKind kind) {
1641 debugEvent("FormalParameters"); 1650 debugEvent("FormalParameters");
1642 OptionalFormals optional; 1651 OptionalFormals optional;
1643 if (count > 0 && peek() is OptionalFormals) { 1652 if (count > 0 && peek() is OptionalFormals) {
1644 optional = pop(); 1653 optional = pop();
1645 count--; 1654 count--;
1646 } 1655 }
1647 FormalParameters formals = new FormalParameters( 1656 FormalParameters formals = new FormalParameters(
1648 popList(count) ?? <VariableDeclaration>[], 1657 popList(count) ?? <VariableDeclaration>[],
1649 optional, 1658 optional,
1650 beginToken.charOffset); 1659 beginToken.charOffset);
(...skipping 868 matching lines...) Expand 10 before | Expand all | Expand 10 after
2519 @override 2528 @override
2520 void handleModifiers(int count) { 2529 void handleModifiers(int count) {
2521 debugEvent("Modifiers"); 2530 debugEvent("Modifiers");
2522 // TODO(ahe): Copied from outline_builder.dart. 2531 // TODO(ahe): Copied from outline_builder.dart.
2523 push(popList(count) ?? NullValue.Modifiers); 2532 push(popList(count) ?? NullValue.Modifiers);
2524 } 2533 }
2525 2534
2526 @override 2535 @override
2527 void handleRecoverableError(Token token, FastaMessage message) { 2536 void handleRecoverableError(Token token, FastaMessage message) {
2528 bool silent = hasParserError; 2537 bool silent = hasParserError;
2529 super.handleRecoverableError(token, message);
2530 addCompileTimeError(message.charOffset, message.message, silent: silent); 2538 addCompileTimeError(message.charOffset, message.message, silent: silent);
2531 } 2539 }
2532 2540
2533 @override 2541 @override
2534 Token handleUnrecoverableError(Token token, FastaMessage message) { 2542 Token handleUnrecoverableError(Token token, FastaMessage message) {
2535 if (isDartLibrary && message.code == codeExpectedFunctionBody) { 2543 if (isDartLibrary && message.code == codeExpectedFunctionBody) {
2536 Token recover = library.loader.target.skipNativeClause(token); 2544 Token recover = library.loader.target.skipNativeClause(token);
2537 if (recover != null) return recover; 2545 if (recover != null) return recover;
2538 } else if (message.code == codeExpectedButGot) { 2546 } else if (message.code == codeExpectedButGot) {
2539 String expected = message.arguments["string"]; 2547 String expected = message.arguments["string"];
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after
3137 } else if (node is PrefixBuilder) { 3145 } else if (node is PrefixBuilder) {
3138 return node.name; 3146 return node.name;
3139 } else if (node is ThisAccessor) { 3147 } else if (node is ThisAccessor) {
3140 return node.isSuper ? "super" : "this"; 3148 return node.isSuper ? "super" : "this";
3141 } else if (node is FastaAccessor) { 3149 } else if (node is FastaAccessor) {
3142 return node.plainNameForRead; 3150 return node.plainNameForRead;
3143 } else { 3151 } else {
3144 return internalError("Unhandled: ${node.runtimeType}"); 3152 return internalError("Unhandled: ${node.runtimeType}");
3145 } 3153 }
3146 } 3154 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698