From 05300ea2dff0e5cc63ec4288dba623116cd2c9a8 Mon Sep 17 00:00:00 2001 From: Dan Rubel Date: Sat, 25 Mar 2017 21:20:11 -0400 Subject: [PATCH] change "deferred" keyword isPseudo --> isBuiltIn Fix https://github.com/dart-lang/sdk/issues/29069 R=ahe@google.com, paulberry@google.com Review-Url: https://codereview.chromium.org/2769253002 . --- .../lib/src/fasta/scanner/keyword.dart | 19 +++---- .../lib/src/fasta/scanner/token.dart | 24 ++------ .../test/scanner_roundtrip_test.dart | 26 --------- pkg/front_end/test/token_test.dart | 56 ++++++++++++++++++- 4 files changed, 68 insertions(+), 57 deletions(-) diff --git a/pkg/front_end/lib/src/fasta/scanner/keyword.dart b/pkg/front_end/lib/src/fasta/scanner/keyword.dart index c643e7d2463..f1c85280770 100644 --- a/pkg/front_end/lib/src/fasta/scanner/keyword.dart +++ b/pkg/front_end/lib/src/fasta/scanner/keyword.dart @@ -72,7 +72,7 @@ class Keyword implements analyzer.Keyword { static const ASYNC = const Keyword("async", isPseudo: true); static const AWAIT = const Keyword("await", isPseudo: true); - static const DEFERRED = const Keyword("deferred", isPseudo: true); + static const DEFERRED = const Keyword("deferred", isBuiltIn: true); static const FUNCTION = const Keyword("Function", isPseudo: true); static const HIDE = const Keyword("hide", isPseudo: true); static const NATIVE = const Keyword("native", isPseudo: true); @@ -123,6 +123,7 @@ class Keyword implements analyzer.Keyword { ABSTRACT, AS, COVARIANT, + DEFERRED, DYNAMIC, EXPORT, EXTERNAL, @@ -139,7 +140,6 @@ class Keyword implements analyzer.Keyword { // ==== Pseudo ASYNC, AWAIT, - DEFERRED, FUNCTION, HIDE, NATIVE, @@ -178,16 +178,13 @@ class Keyword implements analyzer.Keyword { String toString() => syntax; + /// The term "pseudo-keyword" doesn't exist in the spec, and + /// Analyzer and Fasta have different notions of what it means. + /// Analyzer's notion of "pseudo-keyword" corresponds with Fasta's + /// notion of "built-in keyword". + /// Use [isBuiltIn] instead. @override - bool get isPseudoKeyword { - // The term "pseudo-keyword" doesn't exist in the spec, and - // Analyzer and Fasta have different notions of what it means. - // Analyzer's notion of "pseudo-keyword" corresponds with Fasta's - // notion of "built-in keyword". - - // TODO(danrubel) remove `this == DEFERRED` once dartbug.com/29069 is fixed. - return isBuiltIn || this == DEFERRED; - } + bool get isPseudoKeyword => isBuiltIn; @override String get name => syntax.toUpperCase(); diff --git a/pkg/front_end/lib/src/fasta/scanner/token.dart b/pkg/front_end/lib/src/fasta/scanner/token.dart index a380e482503..467f55d3644 100644 --- a/pkg/front_end/lib/src/fasta/scanner/token.dart +++ b/pkg/front_end/lib/src/fasta/scanner/token.dart @@ -317,11 +317,7 @@ class KeywordToken extends Token { bool get isPseudo => keyword.isPseudo; - bool get isBuiltInIdentifier { - // TODO(ahe): Remove special case for "deferred" once dartbug.com/29069 is - // fixed. - return keyword.isBuiltIn || identical("deferred", lexeme); - } + bool get isBuiltInIdentifier => keyword.isBuiltIn; String toString() => "KeywordToken($lexeme)"; @@ -329,22 +325,12 @@ class KeywordToken extends Token { Token copyWithoutComments() => new KeywordToken(keyword, charOffset); @override - Object value() { - // Analyzer has different set of keyword tokens - // TODO(danrubel): Remove special case for "deferred" once dartbug.com/29069 - // is fixed. - return isPseudo && !identical("deferred", lexeme) ? lexeme : keyword; - } + // Analyzer considers pseudo-keywords to have a different value + Object value() => isPseudo ? lexeme : keyword; @override - analyzer.TokenType get type { - // Analyzer considers pseudo-keywords to be identifiers - // TODO(danrubel): Remove special case for "deferred" once dartbug.com/29069 - // is fixed. - return isPseudo && !identical("deferred", lexeme) - ? IDENTIFIER_INFO - : KEYWORD_INFO; - } + // Analyzer considers pseudo-keywords to be identifiers + analyzer.TokenType get type => isPseudo ? IDENTIFIER_INFO : KEYWORD_INFO; } /** diff --git a/pkg/front_end/test/scanner_roundtrip_test.dart b/pkg/front_end/test/scanner_roundtrip_test.dart index 6acb2c30f1d..9594dd7d37d 100644 --- a/pkg/front_end/test/scanner_roundtrip_test.dart +++ b/pkg/front_end/test/scanner_roundtrip_test.dart @@ -73,32 +73,6 @@ class ScannerTest_RoundTrip extends ScannerTest { // syntax. super.test_comment_generic_method_type_list(); } - - void test_pseudo_keywords() { - var pseudoAnalyzerKeywords = new Set.from([ - Keyword.ABSTRACT, - Keyword.AS, - Keyword.COVARIANT, - Keyword.DEFERRED, - Keyword.DYNAMIC, - Keyword.EXPORT, - Keyword.EXTERNAL, - Keyword.FACTORY, - Keyword.GET, - Keyword.IMPLEMENTS, - Keyword.IMPORT, - Keyword.LIBRARY, - Keyword.OPERATOR, - Keyword.PART, - Keyword.SET, - Keyword.STATIC, - Keyword.TYPEDEF, - ]); - for (Keyword keyword in Keyword.values) { - expect(keyword.isPseudoKeyword, pseudoAnalyzerKeywords.contains(keyword), - reason: keyword.name); - } - } } class TestScanner extends analyzer.Scanner { diff --git a/pkg/front_end/test/token_test.dart b/pkg/front_end/test/token_test.dart index b6c5497e6c1..1e3a1227ff7 100644 --- a/pkg/front_end/test/token_test.dart +++ b/pkg/front_end/test/token_test.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import 'package:front_end/src/fasta/scanner/string_scanner.dart'; +import 'package:front_end/src/fasta/scanner/keyword.dart' as fasta; import 'package:front_end/src/fasta/scanner/token.dart' as fasta; import 'package:front_end/src/scanner/token.dart'; import 'package:front_end/src/scanner/reader.dart' as analyzer; @@ -154,6 +155,60 @@ class Foo { expect(token.matchesAny([TokenType.AMPERSAND]), false); } + /// Return all fasta and all analyzer keywords + List get _allKeywords => + new List.from(Keyword.values)..addAll(fasta.Keyword.values); + + void test_built_in_keywords() { + var builtInKeywords = new Set.from([ + Keyword.ABSTRACT, + Keyword.AS, + Keyword.COVARIANT, + Keyword.DEFERRED, + Keyword.DYNAMIC, + Keyword.EXPORT, + Keyword.EXTERNAL, + Keyword.FACTORY, + Keyword.GET, + Keyword.IMPLEMENTS, + Keyword.IMPORT, + Keyword.LIBRARY, + Keyword.OPERATOR, + Keyword.PART, + Keyword.SET, + Keyword.STATIC, + Keyword.TYPEDEF, + ]); + for (Keyword keyword in _allKeywords) { + var isBuiltIn = builtInKeywords.contains(keyword); + expect(keyword.isPseudoKeyword, isBuiltIn, reason: keyword.name); + expect((keyword as fasta.Keyword).isBuiltIn, isBuiltIn, + reason: keyword.name); + } + } + + void test_pseudo_keywords() { + var pseudoKeywords = new Set.from([ + fasta.Keyword.ASYNC, + fasta.Keyword.AWAIT, + fasta.Keyword.FUNCTION, + fasta.Keyword.HIDE, + fasta.Keyword.NATIVE, + fasta.Keyword.OF, + fasta.Keyword.ON, + fasta.Keyword.PATCH, + fasta.Keyword.SHOW, + fasta.Keyword.SOURCE, + fasta.Keyword.SYNC, + fasta.Keyword.YIELD, + ]); + for (Keyword keyword in _allKeywords) { + var isPseudo = pseudoKeywords.contains(keyword); + expect((keyword as fasta.Keyword).isPseudo, isPseudo, + reason: keyword.name); + } + } + void test_value() { var scanner = new StringScanner('true & "home"', includeComments: true); var token = scanner.tokenize(); @@ -166,7 +221,6 @@ class Foo { expect(token.value(), '&'); // String tokens token = token.next; - print('String token :: ${token.runtimeType}'); expect(token.lexeme, '"home"'); expect(token.value(), '"home"'); }