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/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 KernelField; | 17 show KernelArguments, KernelField; |
18 | 18 |
19 import 'package:front_end/src/fasta/kernel/utils.dart' show offsetForToken; | 19 import 'package:front_end/src/fasta/kernel/utils.dart' show offsetForToken; |
20 | 20 |
21 import 'package:front_end/src/fasta/type_inference/type_inference_engine.dart' | 21 import 'package:front_end/src/fasta/type_inference/type_inference_engine.dart' |
22 show FieldNode; | 22 show FieldNode; |
23 | 23 |
24 import 'package:front_end/src/fasta/type_inference/type_inferrer.dart' | 24 import 'package:front_end/src/fasta/type_inference/type_inferrer.dart' |
25 show TypeInferrer; | 25 show TypeInferrer; |
26 | 26 |
27 import 'package:front_end/src/fasta/type_inference/type_promotion.dart' | 27 import 'package:front_end/src/fasta/type_inference/type_promotion.dart' |
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 buildCompileTimeError( | 560 buildCompileTimeError( |
561 "Expected named argument.", arguments[i].fileOffset)); | 561 "Expected named argument.", arguments[i].fileOffset)); |
562 } | 562 } |
563 } | 563 } |
564 } | 564 } |
565 if (firstNamedArgumentIndex < arguments.length) { | 565 if (firstNamedArgumentIndex < arguments.length) { |
566 List<Expression> positional = new List<Expression>.from( | 566 List<Expression> positional = new List<Expression>.from( |
567 arguments.getRange(0, firstNamedArgumentIndex)); | 567 arguments.getRange(0, firstNamedArgumentIndex)); |
568 List<NamedExpression> named = new List<NamedExpression>.from( | 568 List<NamedExpression> named = new List<NamedExpression>.from( |
569 arguments.getRange(firstNamedArgumentIndex, arguments.length)); | 569 arguments.getRange(firstNamedArgumentIndex, arguments.length)); |
570 push(new Arguments(positional, named: named)); | 570 push(astFactory.arguments(positional, named: named)); |
571 } else { | 571 } else { |
572 push(new Arguments(arguments)); | 572 push(astFactory.arguments(arguments)); |
573 } | 573 } |
574 } | 574 } |
575 | 575 |
576 @override | 576 @override |
577 void handleParenthesizedExpression(BeginGroupToken token) { | 577 void handleParenthesizedExpression(BeginGroupToken token) { |
578 debugEvent("ParenthesizedExpression"); | 578 debugEvent("ParenthesizedExpression"); |
579 push(new ParenthesizedExpression(this, popForValue(), token.endGroup)); | 579 push(new ParenthesizedExpression(this, popForValue(), token.endGroup)); |
580 } | 580 } |
581 | 581 |
582 @override | 582 @override |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 message = "Method not found: '$errorName'."; | 776 message = "Method not found: '$errorName'."; |
777 } | 777 } |
778 if (constantExpressionRequired) { | 778 if (constantExpressionRequired) { |
779 return buildCompileTimeError(message, charOffset); | 779 return buildCompileTimeError(message, charOffset); |
780 } | 780 } |
781 warning(message, charOffset); | 781 warning(message, charOffset); |
782 Constructor constructor = | 782 Constructor constructor = |
783 coreTypes.getClass("dart:core", "NoSuchMethodError").constructors.first; | 783 coreTypes.getClass("dart:core", "NoSuchMethodError").constructors.first; |
784 return new Throw(new ConstructorInvocation( | 784 return new Throw(new ConstructorInvocation( |
785 constructor, | 785 constructor, |
786 new Arguments(<Expression>[ | 786 astFactory.arguments(<Expression>[ |
787 astFactory.nullLiteral(null), | 787 astFactory.nullLiteral(null), |
788 new SymbolLiteral(name), | 788 new SymbolLiteral(name), |
789 new ListLiteral(arguments.positional), | 789 new ListLiteral(arguments.positional), |
790 new MapLiteral(arguments.named.map((arg) { | 790 new MapLiteral(arguments.named.map((arg) { |
791 return new MapEntry(new SymbolLiteral(arg.name), arg.value); | 791 return new MapEntry(new SymbolLiteral(arg.name), arg.value); |
792 }).toList()), | 792 }).toList()), |
793 astFactory.nullLiteral(null) | 793 astFactory.nullLiteral(null) |
794 ]))); | 794 ]))); |
795 } | 795 } |
796 | 796 |
(...skipping 1128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1925 debugEvent("endConstLiteral"); | 1925 debugEvent("endConstLiteral"); |
1926 var literal = pop(); | 1926 var literal = pop(); |
1927 constantExpressionRequired = pop(); | 1927 constantExpressionRequired = pop(); |
1928 push(literal); | 1928 push(literal); |
1929 } | 1929 } |
1930 | 1930 |
1931 @override | 1931 @override |
1932 void endNewExpression(Token token) { | 1932 void endNewExpression(Token token) { |
1933 debugEvent("NewExpression"); | 1933 debugEvent("NewExpression"); |
1934 Token nameToken = token.next; | 1934 Token nameToken = token.next; |
1935 Arguments arguments = pop(); | 1935 KernelArguments arguments = pop(); |
1936 String name = pop(); | 1936 String name = pop(); |
1937 List<DartType> typeArguments = pop(); | 1937 List<DartType> typeArguments = pop(); |
1938 var type = pop(); | 1938 var type = pop(); |
1939 bool savedConstantExpressionRequired = pop(); | 1939 bool savedConstantExpressionRequired = pop(); |
1940 () { | 1940 () { |
1941 if (arguments == null) { | 1941 if (arguments == null) { |
1942 push(buildCompileTimeError("No arguments.", nameToken.charOffset)); | 1942 push(buildCompileTimeError("No arguments.", nameToken.charOffset)); |
1943 return; | 1943 return; |
1944 } | 1944 } |
1945 | 1945 |
1946 if (typeArguments != null) { | 1946 if (typeArguments != null) { |
1947 assert(arguments.types.isEmpty); | 1947 assert(arguments.types.isEmpty); |
1948 arguments.types.addAll(typeArguments); | 1948 astFactory.setExplicitArgumentTypes(arguments, typeArguments); |
1949 } | 1949 } |
1950 | 1950 |
1951 String errorName; | 1951 String errorName; |
1952 if (type is ClassBuilder) { | 1952 if (type is ClassBuilder) { |
1953 Builder b = type.findConstructorOrFactory(name, token.charOffset, uri); | 1953 Builder b = type.findConstructorOrFactory(name, token.charOffset, uri); |
1954 Member target; | 1954 Member target; |
1955 if (b == null) { | 1955 if (b == null) { |
1956 // Not found. Reported below. | 1956 // Not found. Reported below. |
1957 } else if (b.isConstructor) { | 1957 } else if (b.isConstructor) { |
1958 if (type.isAbstract) { | 1958 if (type.isAbstract) { |
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2538 } | 2538 } |
2539 return super.handleUnrecoverableError(token, message); | 2539 return super.handleUnrecoverableError(token, message); |
2540 } | 2540 } |
2541 | 2541 |
2542 @override | 2542 @override |
2543 Expression buildCompileTimeError(error, [int charOffset = -1]) { | 2543 Expression buildCompileTimeError(error, [int charOffset = -1]) { |
2544 addCompileTimeError(charOffset, error); | 2544 addCompileTimeError(charOffset, error); |
2545 String message = formatUnexpected(uri, charOffset, error); | 2545 String message = formatUnexpected(uri, charOffset, error); |
2546 Builder constructor = library.loader.getCompileTimeError(); | 2546 Builder constructor = library.loader.getCompileTimeError(); |
2547 return new Throw(buildStaticInvocation(constructor.target, | 2547 return new Throw(buildStaticInvocation(constructor.target, |
2548 new Arguments(<Expression>[new StringLiteral(message)]))); | 2548 astFactory.arguments(<Expression>[new StringLiteral(message)]))); |
2549 } | 2549 } |
2550 | 2550 |
2551 Expression buildAbstractClassInstantiationError(String className, | 2551 Expression buildAbstractClassInstantiationError(String className, |
2552 [int charOffset = -1]) { | 2552 [int charOffset = -1]) { |
2553 warning("The class '$className' is abstract and can't be instantiated.", | 2553 warning("The class '$className' is abstract and can't be instantiated.", |
2554 charOffset); | 2554 charOffset); |
2555 Builder constructor = library.loader.getAbstractClassInstantiationError(); | 2555 Builder constructor = library.loader.getAbstractClassInstantiationError(); |
2556 return new Throw(buildStaticInvocation(constructor.target, | 2556 return new Throw(buildStaticInvocation(constructor.target, |
2557 new Arguments(<Expression>[new StringLiteral(className)]))); | 2557 astFactory.arguments(<Expression>[new StringLiteral(className)]))); |
2558 } | 2558 } |
2559 | 2559 |
2560 Statement buildCompileTimeErrorStatement(error, [int charOffset = -1]) { | 2560 Statement buildCompileTimeErrorStatement(error, [int charOffset = -1]) { |
2561 return astFactory | 2561 return astFactory |
2562 .expressionStatement(buildCompileTimeError(error, charOffset)); | 2562 .expressionStatement(buildCompileTimeError(error, charOffset)); |
2563 } | 2563 } |
2564 | 2564 |
2565 @override | 2565 @override |
2566 Initializer buildInvalidIntializer(Expression expression, | 2566 Initializer buildInvalidIntializer(Expression expression, |
2567 [int charOffset = -1]) { | 2567 [int charOffset = -1]) { |
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3130 } else if (node is PrefixBuilder) { | 3130 } else if (node is PrefixBuilder) { |
3131 return node.name; | 3131 return node.name; |
3132 } else if (node is ThisAccessor) { | 3132 } else if (node is ThisAccessor) { |
3133 return node.isSuper ? "super" : "this"; | 3133 return node.isSuper ? "super" : "this"; |
3134 } else if (node is FastaAccessor) { | 3134 } else if (node is FastaAccessor) { |
3135 return node.plainNameForRead; | 3135 return node.plainNameForRead; |
3136 } else { | 3136 } else { |
3137 return internalError("Unhandled: ${node.runtimeType}"); | 3137 return internalError("Unhandled: ${node.runtimeType}"); |
3138 } | 3138 } |
3139 } | 3139 } |
OLD | NEW |