Index: compiler/java/com/google/dart/compiler/parser/DartParser.java |
diff --git a/compiler/java/com/google/dart/compiler/parser/DartParser.java b/compiler/java/com/google/dart/compiler/parser/DartParser.java |
index 346fc722308c28f048e5cc05589c8a2fcc8def36..fcf3a7e1fcd9675d1a67a3a0dd5300ed75ecba1a 100644 |
--- a/compiler/java/com/google/dart/compiler/parser/DartParser.java |
+++ b/compiler/java/com/google/dart/compiler/parser/DartParser.java |
@@ -13,6 +13,7 @@ import com.google.dart.compiler.ErrorCode; |
import com.google.dart.compiler.InternalCompilerException; |
import com.google.dart.compiler.LibrarySource; |
import com.google.dart.compiler.Source; |
+import com.google.dart.compiler.SystemLibraryManager; |
import com.google.dart.compiler.ast.DartArrayAccess; |
import com.google.dart.compiler.ast.DartArrayLiteral; |
import com.google.dart.compiler.ast.DartAssertion; |
@@ -109,9 +110,10 @@ import java.util.Set; |
*/ |
public class DartParser extends CompletionHooksParserBase { |
+ private final boolean isDietParse; |
+ private final Set<String> prefixes; |
+ private final boolean corelibParse; |
private Set<Integer> errorHistory = new HashSet<Integer>(); |
- private Set<String> prefixes; |
- private boolean isDietParse; |
private boolean isParsingInterface; |
private boolean isTopLevelAbstract; |
private DartScanner.Position topLevelAbstractModifierPosition; |
@@ -182,6 +184,10 @@ public class DartParser extends CompletionHooksParserBase { |
super(ctx); |
this.isDietParse = isDietParse; |
this.prefixes = prefixes; |
+ { |
+ Source source = ctx.getSource(); |
+ this.corelibParse = source != null && SystemLibraryManager.isDartUri(source.getUri()); |
+ } |
} |
private DartParser(Source source, DartCompilerListener listener) throws IOException { |
@@ -609,14 +615,20 @@ public class DartParser extends CompletionHooksParserBase { |
// Deal with native clause for classes. |
DartStringLiteral nativeName = null; |
- if (!isParsingInterface && optionalPseudoKeyword(NATIVE_KEYWORD)) { |
+ if (optionalPseudoKeyword(NATIVE_KEYWORD)) { |
+ if (superType != null) { |
+ reportError(position(), ParserErrorCode.NATIVE_MUST_NOT_EXTEND); |
+ } |
+ if (isParsingInterface) { |
+ reportError(position(), ParserErrorCode.NATIVE_ONLY_CLASS); |
+ } |
+ if (!corelibParse) { |
+ reportError(position(), ParserErrorCode.NATIVE_ONLY_CORE_LIB); |
+ } |
beginLiteral(); |
if (expect(Token.STRING)) { |
nativeName = done(DartStringLiteral.get(ctx.getTokenString())); |
} |
- if (superType != null) { |
- reportError(position(), ParserErrorCode.EXTENDED_NATIVE_CLASS); |
- } |
} |
// Parse the members. |
@@ -1197,6 +1209,9 @@ public class DartParser extends CompletionHooksParserBase { |
if (!optionalPseudoKeyword(NATIVE_KEYWORD)) { |
throw new AssertionError(); |
} |
+ if (!corelibParse) { |
+ reportError(position(), ParserErrorCode.NATIVE_ONLY_CORE_LIB); |
+ } |
if (optional(Token.SEMICOLON)) { |
return done(new DartNativeBlock()); |
} else if (match(Token.LBRACE) || match(Token.ARROW)) { |