Chromium Code Reviews| Index: pkg/front_end/lib/src/fasta/source/directive_listener.dart |
| diff --git a/pkg/front_end/lib/src/fasta/source/directive_listener.dart b/pkg/front_end/lib/src/fasta/source/directive_listener.dart |
| index ce4709a5a2390c8173dc0a1450757fe4ac08c9a1..8a775887611bb6dc40e2e9141eb5b2cfba0b9cff 100644 |
| --- a/pkg/front_end/lib/src/fasta/source/directive_listener.dart |
| +++ b/pkg/front_end/lib/src/fasta/source/directive_listener.dart |
| @@ -11,7 +11,6 @@ import '../parser/identifier_context.dart'; |
| import '../parser/listener.dart'; |
| import '../quote.dart'; |
| import '../scanner/token.dart'; |
| -import 'stack_listener.dart'; |
| /// Listener that records imports, exports, and part directives. |
| /// |
| @@ -21,95 +20,91 @@ import 'stack_listener.dart'; |
| /// any top-level declaration, but we recommend to continue parsing the entire |
| /// file in order to gracefully handle input errors. |
| class DirectiveListener extends Listener { |
| - final Stack _stack = new Stack(); |
| - |
| /// Export directives with URIs and combinators. |
|
Siggi Cherem (dart-lang)
2017/05/16 21:42:04
Export => Import
scheglov
2017/05/17 00:07:31
Done.
|
| - final List<ImportDirective> imports = <ImportDirective>[]; |
| + final List<NamespaceDirective> imports = <NamespaceDirective>[]; |
| /// Export directives with URIs and combinators. |
| - final List<ExportDirective> exports = <ExportDirective>[]; |
| + final List<NamespaceDirective> exports = <NamespaceDirective>[]; |
| /// Collects URIs that occur on any part directive. |
| final Set<String> parts = new Set<String>(); |
| - bool _inDirective = false; |
| + bool _inPart = false; |
| + String _uri; |
| + List<NamespaceCombinator> _combinators; |
| + List<String> _combinatorNames; |
| DirectiveListener(); |
| @override |
| beginExport(_) { |
| - _inDirective = true; |
| + _combinators = <NamespaceCombinator>[]; |
| + } |
| + |
| + @override |
| + void beginHide(Token hideKeyword) { |
| + _combinatorNames = <String>[]; |
| } |
| @override |
| beginImport(_) { |
| - _inDirective = true; |
| + _combinators = <NamespaceCombinator>[]; |
| } |
| @override |
| void beginLiteralString(Token token) { |
| - if (_inDirective) { |
| - _push(unescapeString(token.lexeme)); |
| + if (_combinators != null || _inPart) { |
|
Siggi Cherem (dart-lang)
2017/05/16 21:42:04
let's add a simple getter with this formula:
bo
scheglov
2017/05/17 00:07:31
I think the class is small enough to make relation
|
| + _uri = unescapeString(token.lexeme); |
| } |
| } |
| @override |
| beginPart(_) { |
| - _inDirective = true; |
| + _inPart = true; |
| } |
| @override |
| - void endCombinators(int count) { |
| - List<String> names = _popList(count); |
| - _push(names); |
| + void beginShow(Token showKeyword) { |
| + _combinatorNames = <String>[]; |
| } |
| @override |
| endExport(export, semicolon) { |
| - List<NamespaceCombinator> combinators = _pop(); |
| - String uri = _pop(); |
| - exports.add(new ExportDirective(uri, combinators)); |
| - _inDirective = false; |
| + exports.add(new NamespaceDirective.export(_uri, _combinators)); |
| + _uri = null; |
| + _combinators = null; |
| } |
| @override |
| void endHide(Token hideKeyword) { |
| - List<String> names = _pop(); |
| - _push(new NamespaceCombinator.hide(names)); |
| - } |
| - |
| - @override |
| - void endIdentifierList(int count) { |
| - if (_inDirective) { |
| - _push(_popList(count) ?? <String>[]); |
| - } |
| + _combinators.add(new NamespaceCombinator.hide(_combinatorNames)); |
| + _combinatorNames = null; |
| } |
| @override |
| endImport(import, deferred, asKeyword, semicolon) { |
| - List<NamespaceCombinator> combinators = _pop(); |
| - String uri = _pop(); |
| - imports.add(new ImportDirective(uri, combinators)); |
| - _inDirective = false; |
| + imports.add(new NamespaceDirective.import(_uri, _combinators)); |
| + _uri = null; |
| + _combinators = null; |
| } |
| @override |
| endPart(part, semicolon) { |
| - String uri = _pop(); |
| - parts.add(uri); |
| - _inDirective = false; |
| + parts.add(_uri); |
| + _uri = null; |
| + _inPart = false; |
| } |
| @override |
| void endShow(Token showKeyword) { |
| - List<String> names = _pop(); |
| - _push(new NamespaceCombinator.show(names)); |
| + _combinators.add(new NamespaceCombinator.show(_combinatorNames)); |
| + _combinatorNames = null; |
| } |
| @override |
| void handleIdentifier(Token token, IdentifierContext context) { |
| - if (_inDirective && context == IdentifierContext.combinator) { |
| - _push(token.lexeme); |
| + if (_combinatorNames != null && context == IdentifierContext.combinator) { |
| + _combinatorNames.add(token.lexeme); |
| } |
| } |
| @@ -125,33 +120,6 @@ class DirectiveListener extends Listener { |
| } |
| return super.handleUnrecoverableError(token, message); |
| } |
| - |
| - T _pop<T>() { |
| - var value = _stack.pop() as T; |
| - return value; |
| - } |
| - |
| - List<T> _popList<T>(int n) { |
| - return _stack.popList(n); |
| - } |
| - |
| - void _push<T>(T value) { |
| - _stack.push(value); |
| - } |
| -} |
| - |
| -class ExportDirective { |
| - final String uri; |
| - final List<NamespaceCombinator> combinators; |
| - |
| - ExportDirective(this.uri, this.combinators); |
| -} |
| - |
| -class ImportDirective { |
| - final String uri; |
| - final List<NamespaceCombinator> combinators; |
| - |
| - ImportDirective(this.uri, this.combinators); |
| } |
| class NamespaceCombinator { |
| @@ -166,3 +134,13 @@ class NamespaceCombinator { |
| : isShow = true, |
| names = names.toSet(); |
| } |
| + |
| +class NamespaceDirective { |
| + final bool isImport; |
| + final String uri; |
| + final List<NamespaceCombinator> combinators; |
| + |
| + NamespaceDirective.export(this.uri, this.combinators) : isImport = false; |
| + |
| + NamespaceDirective.import(this.uri, this.combinators) : isImport = true; |
| +} |