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

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

Issue 2676823002: Add option --compile-sdk to fasta compile and run. (Closed)
Patch Set: Address comments. Created 3 years, 10 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 881d8f3cdd4b486557a0ad43ae39a5a349b640ba..9b304e488f675c3b6fcc619d83f7e83b90c576de 100644
--- a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
@@ -25,6 +25,9 @@ import 'package:kernel/class_hierarchy.dart' show
import 'package:kernel/core_types.dart' show
CoreTypes;
+import '../parser/dart_vm_native.dart' show
+ skipNativeClause;
+
import 'package:front_end/src/fasta/scanner/token.dart' show
BeginGroupToken,
Token,
@@ -124,6 +127,8 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
final Scope enclosingScope;
+ final bool isDartLibrary;
+
Scope formalParameterScope;
bool isFirstIdentifier = false;
@@ -144,9 +149,16 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
CloneVisitor cloner;
- BodyBuilder(this.library, this.member, Scope scope, this.formalParameterScope,
- this.hierarchy, this.coreTypes, this.classBuilder, this.isInstanceMember)
+ /// Set to true each time we parse a native function body. It is reset in
+ /// [handleInvalidFunctionBody] which is called immediately after.
+ bool lastErrorWasNativeFunctionBody = false;
+
+ BodyBuilder(KernelLibraryBuilder library, this.member, Scope scope,
+ this.formalParameterScope, this.hierarchy, this.coreTypes,
+ this.classBuilder, this.isInstanceMember)
: enclosingScope = scope,
+ library = library,
+ isDartLibrary = library.uri.scheme == "dart",
super(scope);
bool get inConstructor {
@@ -2141,7 +2153,13 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
@override
Token handleUnrecoverableError(Token token, ErrorKind kind, Map arguments) {
- if (kind == ErrorKind.UnexpectedToken) {
+ if (isDartLibrary && kind == ErrorKind.ExpectedFunctionBody) {
+ Token recover = skipNativeClause(token);
+ if (recover != null) {
+ buildNative(unescapeString(token.next.value));
+ return recover;
+ }
+ } else if (kind == ErrorKind.UnexpectedToken) {
String expected = arguments["expected"];
const List<String> trailing = const <String>[")", "}", ";", ","];
if (trailing.contains(token.stringValue) && trailing.contains(expected)) {
@@ -2205,6 +2223,30 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
}
@override
+ void handleInvalidFunctionBody(Token token) {
+ if (!lastErrorWasNativeFunctionBody) {
+ push(new Block(<Statement>[new InvalidStatement()]));
+ }
+ lastErrorWasNativeFunctionBody = false;
+ }
+
+ void buildNative(String native) {
+ lastErrorWasNativeFunctionBody = true;
+
+ // From dartk:
+ //
+ // currentMember.isExternal = true;
+ // currentMember.addAnnotation(new ast.ConstructorInvocation(
+ // scope.loader.getCoreClassConstructorReference('ExternalName',
+ // library: 'dart:_internal'),
+ // new ast.Arguments(<ast.Expression>[
+ // new ast.StringLiteral(body.stringLiteral.stringValue)
+ // ]),
+ // isConst: true));
+ push(new Block(<Statement>[new InvalidStatement()]));
+ }
+
+ @override
void debugEvent(String name) {
// printEvent(name);
}
« no previous file with comments | « pkg/front_end/lib/src/fasta/compiler_command_line.dart ('k') | pkg/front_end/lib/src/fasta/kernel/kernel_target.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698