Skip to content

Commit c66479f

Browse files
committed
Revert "Add support for the new function-type syntax."
This reverts commit c289af3. BUG= Review-Url: https://codereview.chromium.org/2710973002 .
1 parent c289af3 commit c66479f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+170
-1735
lines changed

.packages

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ dart_style:third_party/pkg_tested/dart_style/lib
3434
dartdoc:third_party/pkg/dartdoc/lib
3535
dev_compiler:pkg/dev_compiler/lib
3636
expect:pkg/expect/lib
37-
fasta:pkg/fasta/lib
3837
fixnum:third_party/pkg/fixnum/lib
3938
front_end:pkg/front_end/lib
4039
func:third_party/pkg/func/lib

pkg/compiler/lib/src/diagnostics/messages.dart

-11
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ enum MessageKind {
275275
INVALID_RECEIVER_IN_INITIALIZER,
276276
INVALID_SOURCE_FILE_LOCATION,
277277
INVALID_SYMBOL,
278-
INVALID_INLINE_FUNCTION_TYPE,
279278
INVALID_SYNC_MODIFIER,
280279
INVALID_TYPE_VARIABLE_BOUND,
281280
INVALID_UNNAMED_CONSTRUCTOR_NAME,
@@ -3320,16 +3319,6 @@ Please include the following information:
33203319
" require a preamble file located in:\n"
33213320
" <sdk>/lib/_internal/js_runtime/lib/preambles."),
33223321

3323-
MessageKind.INVALID_INLINE_FUNCTION_TYPE: const MessageTemplate(
3324-
MessageKind.INVALID_INLINE_FUNCTION_TYPE,
3325-
"Invalid inline function type.",
3326-
howToFix: "Try changing the inline function type (as in 'int f()') to"
3327-
" a prefixed function type using the `Function` keyword (as in "
3328-
"'int Function() f').",
3329-
examples:
3330-
const ["typedef F = Function(int f(String x)); main() { F f; }"],
3331-
),
3332-
33333322
MessageKind.INVALID_SYNC_MODIFIER: const MessageTemplate(
33343323
MessageKind.INVALID_SYNC_MODIFIER, "Invalid modifier 'sync'.",
33353324
howToFix: "Try replacing 'sync' with 'sync*'.",

pkg/compiler/lib/src/elements/elements.dart

-3
Original file line numberDiff line numberDiff line change
@@ -1208,9 +1208,6 @@ abstract class FormalElement extends Element
12081208
FunctionTypedElement get functionDeclaration;
12091209

12101210
VariableDefinitions get node;
1211-
1212-
/// Whether the parameter is unnamed in a function type.
1213-
bool get isUnnamed;
12141211
}
12151212

12161213
/// A formal parameter of a function or constructor.

pkg/compiler/lib/src/elements/modelx.dart

+1-10
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,7 @@ class TypedefElementX extends ElementX
13341334
ResolutionTypedefType computeType(Resolution resolution) {
13351335
if (thisTypeCache != null) return thisTypeCache;
13361336
Typedef node = parseNode(resolution.parsingContext);
1337-
setThisAndRawTypes(createTypeVariables(node.templateParameters));
1337+
setThisAndRawTypes(createTypeVariables(node.typeParameters));
13381338
ensureResolved(resolution);
13391339
return thisTypeCache;
13401340
}
@@ -1732,15 +1732,6 @@ class FormalElementX extends ElementX
17321732
: this.identifier = identifier,
17331733
super(identifier.source, elementKind, enclosingElement);
17341734

1735-
FormalElementX.unnamed(ElementKind elementKind,
1736-
FunctionTypedElement enclosingElement,
1737-
this.definitions)
1738-
: this.identifier = null,
1739-
super("<unnamed>", elementKind, enclosingElement);
1740-
1741-
/// Whether this is an unnamed parameter in a Function type.
1742-
bool get isUnnamed => identifier == null;
1743-
17441735
FunctionTypedElement get functionDeclaration => enclosingElement;
17451736

17461737
Modifiers get modifiers => definitions.modifiers;

pkg/compiler/lib/src/elements/resolution_types.dart

-10
Original file line numberDiff line numberDiff line change
@@ -642,16 +642,6 @@ class ResolutionFunctionType extends ResolutionDartType
642642
optionalParameterTypes, namedParameters, namedParameterTypes);
643643
}
644644

645-
factory ResolutionFunctionType.generalized(
646-
ResolutionDartType returnType,
647-
List<ResolutionDartType> parameterTypes,
648-
List<ResolutionDartType> optionalParameterTypes,
649-
List<String> namedParameters,
650-
List<ResolutionDartType> namedParameterTypes) {
651-
return new ResolutionFunctionType.internal(null, returnType, parameterTypes,
652-
optionalParameterTypes, namedParameters, namedParameterTypes);
653-
}
654-
655645
ResolutionFunctionType.internal(FunctionTypedElement this.element,
656646
[ResolutionDartType returnType = const ResolutionDynamicType(),
657647
List<ResolutionDartType> parameterTypes = const <ResolutionDartType>[],

pkg/compiler/lib/src/js_backend/no_such_method_registry.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,7 @@ class NoSuchMethodRegistry {
219219
}
220220
if (expr is Send && expr.isTypeCast) {
221221
Send sendExpr = expr;
222-
var typeAnnotation = sendExpr.typeAnnotationFromIsCheckOrCast;
223-
var typeName = typeAnnotation.asNominalTypeAnnotation()?.typeName;
222+
var typeName = sendExpr.typeAnnotationFromIsCheckOrCast.typeName;
224223
if (typeName is Identifier && typeName.source == "dynamic") {
225224
expr = sendExpr.receiver;
226225
}

pkg/compiler/lib/src/kernel/kernel_visitor.dart

+2-18
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ import '../tree/tree.dart'
105105
ForIn,
106106
FunctionDeclaration,
107107
FunctionExpression,
108-
FunctionTypeAnnotation,
109108
Identifier,
110109
If,
111110
Label,
@@ -124,7 +123,6 @@ import '../tree/tree.dart'
124123
NewExpression,
125124
Node,
126125
NodeList,
127-
NominalTypeAnnotation,
128126
Operator,
129127
ParenthesizedExpression,
130128
RedirectingFactoryBody,
@@ -1123,28 +1121,14 @@ class KernelVisitor extends Object
11231121

11241122
@override
11251123
visitTypeAnnotation(TypeAnnotation node) {
1126-
// Shouldn't be called, as the resolver has already resolved types and
1124+
// Shouldn't be called, as the resolver have already resolved types and
11271125
// created [DartType] objects.
11281126
return internalError(node, "TypeAnnotation");
11291127
}
11301128

1131-
@override
1132-
visitNominalTypeAnnotation(NominalTypeAnnotation node) {
1133-
// Shouldn't be called, as the resolver has already resolved types and
1134-
// created [DartType] objects.
1135-
return internalError(node, "NominalTypeAnnotation");
1136-
}
1137-
1138-
@override
1139-
visitFunctionTypeAnnotation(FunctionTypeAnnotation node) {
1140-
// Shouldn't be called, as the resolver has already resolved types and
1141-
// created [DartType] objects.
1142-
return internalError(node, "FunctionTypeAnnotation");
1143-
}
1144-
11451129
@override
11461130
visitTypeVariable(TypeVariable node) {
1147-
// Shouldn't be called, as the resolver has already resolved types and
1131+
// Shouldn't be called, as the resolver have already resolved types and
11481132
// created [DartType] objects.
11491133
return internalError(node, "TypeVariable");
11501134
}

pkg/compiler/lib/src/native/behavior.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ class NativeBehavior {
262262
/// Each tag kind (including the 'type-tag's) can only occur once in the
263263
/// sequence.
264264
///
265-
/// [specString] is the specification string, [lookupType] resolves named
265+
/// [specString] is the specification string, [resolveType] resolves named
266266
/// types into type values, [typesReturned] and [typesInstantiated] collects
267267
/// the types defined by the specification string, and [objectType] and
268268
/// [nullType] define the types for `Object` and `Null`, respectively. The

pkg/compiler/lib/src/parser/diet_parser_task.dart

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ import 'package:front_end/src/fasta/parser.dart'
1717
class PartialParser extends TopLevelParser {
1818
PartialParser(Listener listener) : super(listener);
1919

20-
Token parseFormalParameters(Token token, {bool inFunctionType: false}) {
21-
return skipFormalParameters(token);
22-
}
20+
Token parseFormalParameters(Token token) => skipFormalParameters(token);
2321
}
2422

2523
class DietParserTask extends CompilerTask {

pkg/compiler/lib/src/parser/element_listener.dart

+9-32
Original file line numberDiff line numberDiff line change
@@ -287,18 +287,10 @@ class ElementListener extends Listener {
287287
}
288288

289289
@override
290-
void endFunctionTypeAlias(
291-
Token typedefKeyword, Token equals, Token endToken) {
292-
Identifier name;
293-
if (equals == null) {
294-
popNode(); // TODO(karlklose): do not throw away typeVariables.
295-
name = popNode();
296-
popNode(); // returnType
297-
} else {
298-
popNode(); // Function type.
299-
popNode(); // TODO(karlklose): do not throw away typeVariables.
300-
name = popNode();
301-
}
290+
void endFunctionTypeAlias(Token typedefKeyword, Token endToken) {
291+
popNode(); // TODO(karlklose): do not throw away typeVariables.
292+
Identifier name = popNode();
293+
popNode(); // returnType
302294
pushElement(new PartialTypedefElement(
303295
name.source, compilationUnitElement, typedefKeyword, endToken));
304296
rejectBuiltInIdentifier(name);
@@ -332,13 +324,13 @@ class ElementListener extends Listener {
332324
@override
333325
void endMixinApplication() {
334326
NodeList mixins = popNode();
335-
NominalTypeAnnotation superclass = popNode();
327+
TypeAnnotation superclass = popNode();
336328
pushNode(new MixinApplication(superclass, mixins));
337329
}
338330

339331
@override
340332
void handleVoidKeyword(Token token) {
341-
pushNode(new NominalTypeAnnotation(new Identifier(token), null));
333+
pushNode(new TypeAnnotation(new Identifier(token), null));
342334
}
343335

344336
@override
@@ -411,7 +403,7 @@ class ElementListener extends Listener {
411403

412404
@override
413405
void endTypeVariable(Token token, Token extendsOrSuper) {
414-
NominalTypeAnnotation bound = popNode();
406+
TypeAnnotation bound = popNode();
415407
Identifier name = popNode();
416408
pushNode(new TypeVariable(name, extendsOrSuper, bound));
417409
rejectBuiltInIdentifier(name);
@@ -438,21 +430,10 @@ class ElementListener extends Listener {
438430
}
439431

440432
@override
441-
void handleType(Token beginToken, Token endToken) {
433+
void endType(Token beginToken, Token endToken) {
442434
NodeList typeArguments = popNode();
443435
Expression typeName = popNode();
444-
pushNode(new NominalTypeAnnotation(typeName, typeArguments));
445-
}
446-
447-
void handleNoName(Token token) {
448-
pushNode(null);
449-
}
450-
451-
@override
452-
void handleFunctionType(Token functionToken, Token endToken) {
453-
popNode(); // Type parameters.
454-
popNode(); // Return type.
455-
pushNode(null);
436+
pushNode(new TypeAnnotation(typeName, typeArguments));
456437
}
457438

458439
@override
@@ -651,10 +632,6 @@ class ElementListener extends Listener {
651632
errorCode = MessageKind.BAD_INPUT_CHARACTER;
652633
break;
653634

654-
case ErrorKind.InvalidInlineFunctionType:
655-
errorCode = MessageKind.INVALID_INLINE_FUNCTION_TYPE;
656-
break;
657-
658635
case ErrorKind.InvalidSyncModifier:
659636
errorCode = MessageKind.INVALID_SYNC_MODIFIER;
660637
break;

pkg/compiler/lib/src/parser/node_listener.dart

+6-53
Original file line numberDiff line numberDiff line change
@@ -126,60 +126,13 @@ class NodeListener extends ElementListener {
126126
}
127127

128128
@override
129-
void endFunctionTypeAlias(
130-
Token typedefKeyword, Token equals, Token endToken) {
131-
bool isGeneralizedTypeAlias;
132-
NodeList templateParameters;
133-
TypeAnnotation returnType;
134-
Identifier name;
135-
NodeList typeParameters;
136-
NodeList formals;
137-
if (equals == null) {
138-
isGeneralizedTypeAlias = false;
139-
formals = popNode();
140-
templateParameters = popNode();
141-
name = popNode();
142-
returnType = popNode();
143-
} else {
144-
// TODO(floitsch): keep using the `FunctionTypeAnnotation' node.
145-
isGeneralizedTypeAlias = true;
146-
Node type = popNode();
147-
if (type.asFunctionTypeAnnotation() == null) {
148-
// TODO(floitsch): The parser should diagnose this problem, not
149-
// this listener.
150-
// However, this problem goes away, when we allow aliases for
151-
// non-function types too.
152-
reportFatalError(type, 'Expected a function type.');
153-
}
154-
FunctionTypeAnnotation functionType = type;
155-
templateParameters = popNode();
156-
name = popNode();
157-
returnType = functionType.returnType;
158-
typeParameters = functionType.typeParameters;
159-
formals = functionType.formals;
160-
}
161-
pushNode(new Typedef(
162-
isGeneralizedTypeAlias,
163-
templateParameters,
164-
returnType,
165-
name,
166-
typeParameters,
167-
formals,
168-
typedefKeyword,
169-
endToken));
170-
}
171-
172-
void handleNoName(Token token) {
173-
pushNode(null);
174-
}
175-
176-
@override
177-
void handleFunctionType(Token functionToken, Token endToken) {
129+
void endFunctionTypeAlias(Token typedefKeyword, Token endToken) {
178130
NodeList formals = popNode();
179131
NodeList typeParameters = popNode();
132+
Identifier name = popNode();
180133
TypeAnnotation returnType = popNode();
181-
pushNode(new FunctionTypeAnnotation(
182-
returnType, functionToken, typeParameters, formals));
134+
pushNode(new Typedef(
135+
returnType, name, typeParameters, formals, typedefKeyword, endToken));
183136
}
184137

185138
@override
@@ -276,7 +229,7 @@ class NodeListener extends ElementListener {
276229
NodeList typeArguments = popNode();
277230
Node classReference = popNode();
278231
if (typeArguments != null) {
279-
classReference = new NominalTypeAnnotation(classReference, typeArguments);
232+
classReference = new TypeAnnotation(classReference, typeArguments);
280233
} else {
281234
Identifier identifier = classReference.asIdentifier();
282235
Send send = classReference.asSend();
@@ -914,7 +867,7 @@ class NodeListener extends ElementListener {
914867
NodeList typeArguments = popNode();
915868
Node receiver = popNode();
916869
if (typeArguments != null) {
917-
receiver = new NominalTypeAnnotation(receiver, typeArguments);
870+
receiver = new TypeAnnotation(receiver, typeArguments);
918871
recoverableError(typeArguments, 'Type arguments are not allowed here.');
919872
} else {
920873
Identifier identifier = receiver.asIdentifier();

pkg/compiler/lib/src/parser/partial_elements.dart

+1-3
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ import 'node_listener.dart' show NodeListener;
4242
class ClassElementParser extends ClassMemberParser {
4343
ClassElementParser(Listener listener) : super(listener);
4444

45-
Token parseFormalParameters(Token token, {bool inFunctionType: false}) {
46-
return skipFormalParameters(token);
47-
}
45+
Token parseFormalParameters(Token token) => skipFormalParameters(token);
4846
}
4947

5048
abstract class PartialElement implements DeclarationSite {

0 commit comments

Comments
 (0)