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

Unified Diff: pkg/kernel/lib/ast.dart

Issue 2852373002: Add import/export declaration AST node boilerplate to kernel. (Closed)
Patch Set: Merge and adapt C++ code to upstream changes Created 3 years, 7 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
« no previous file with comments | « pkg/kernel/binary.md ('k') | pkg/kernel/lib/binary/ast_from_binary.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/kernel/lib/ast.dart
diff --git a/pkg/kernel/lib/ast.dart b/pkg/kernel/lib/ast.dart
index c1b6670b5cf8fd0152b0a4382d768d3b0ea3403d..01daa37834255a4d48acc57ce16705ceae4bba48 100644
--- a/pkg/kernel/lib/ast.dart
+++ b/pkg/kernel/lib/ast.dart
@@ -264,7 +264,7 @@ class Library extends NamedNode implements Comparable<Library> {
bool isExternal;
String name;
- final List<DeferredImport> deferredImports;
+ final List<LibraryDependency> dependencies;
final List<Typedef> typedefs;
final List<Class> classes;
final List<Procedure> procedures;
@@ -273,20 +273,20 @@ class Library extends NamedNode implements Comparable<Library> {
Library(this.importUri,
{this.name,
this.isExternal: false,
- List<DeferredImport> imports,
+ List<LibraryDependency> dependencies,
List<Typedef> typedefs,
List<Class> classes,
List<Procedure> procedures,
List<Field> fields,
this.fileUri,
Reference reference})
- : this.deferredImports = imports ?? <DeferredImport>[],
+ : this.dependencies = dependencies ?? <LibraryDependency>[],
this.typedefs = typedefs ?? <Typedef>[],
this.classes = classes ?? <Class>[],
this.procedures = procedures ?? <Procedure>[],
this.fields = fields ?? <Field>[],
super(reference) {
- setParents(this.deferredImports, this);
+ setParents(this.dependencies, this);
setParents(this.typedefs, this);
setParents(this.classes, this);
setParents(this.procedures, this);
@@ -338,10 +338,14 @@ class Library extends NamedNode implements Comparable<Library> {
}
}
+ void addDependency(LibraryDependency node) {
+ dependencies.add(node..parent = this);
+ }
+
accept(TreeVisitor v) => v.visitLibrary(this);
visitChildren(Visitor v) {
- visitList(deferredImports, v);
+ visitList(dependencies, v);
visitList(typedefs, v);
visitList(classes, v);
visitList(procedures, v);
@@ -349,7 +353,7 @@ class Library extends NamedNode implements Comparable<Library> {
}
transformChildren(Transformer v) {
- transformList(deferredImports, v, this);
+ transformList(dependencies, v, this);
transformList(typedefs, v, this);
transformList(classes, v, this);
transformList(procedures, v, this);
@@ -370,23 +374,104 @@ class Library extends NamedNode implements Comparable<Library> {
}
}
-/// An import of form: `import <url> deferred as <name>;`.
-class DeferredImport extends TreeNode {
+/// An import or export declaration in a library.
+///
+/// It can represent any of the following forms,
+///
+/// import <url>;
+/// import <url> as <name>;
+/// import <url> deferred as <name>;
+/// export <url>;
+///
+/// optionally with metadata and [Combinators].
+class LibraryDependency extends TreeNode {
+ int flags;
+
+ final List<Expression> annotations;
+
Reference importedLibraryReference;
+
+ /// The name of the import prefix, if any, or `null` if this is not an import
+ /// with a prefix.
+ ///
+ /// Must be non-null for deferred imports, and must be null for exports.
String name;
- DeferredImport(Library importedLibrary, String name)
- : this.byReference(importedLibrary.reference, name);
+ final List<Combinator> combinators;
- DeferredImport.byReference(this.importedLibraryReference, this.name);
+ LibraryDependency(int flags, List<Expression> annotations,
+ Library importedLibrary, String name, List<Combinator> combinators)
+ : this.byReference(
+ flags, annotations, importedLibrary.reference, name, combinators);
+
+ LibraryDependency.deferredImport(Library importedLibrary, String name,
+ {List<Combinator> combinators, List<Expression> annotations})
+ : this.byReference(DeferredFlag, annotations ?? <Expression>[],
+ importedLibrary.reference, name, combinators ?? <Combinator>[]);
+
+ LibraryDependency.import(Library importedLibrary,
+ {String name, List<Combinator> combinators, List<Expression> annotations})
+ : this.byReference(0, annotations ?? <Expression>[],
+ importedLibrary.reference, name, combinators ?? <Combinator>[]);
+
+ LibraryDependency.export(Library importedLibrary,
+ {List<Combinator> combinators, List<Expression> annotations})
+ : this.byReference(ExportFlag, annotations ?? <Expression>[],
+ importedLibrary.reference, null, combinators ?? <Combinator>[]);
+
+ LibraryDependency.byReference(this.flags, this.annotations,
+ this.importedLibraryReference, this.name, this.combinators) {
+ setParents(annotations, this);
+ setParents(combinators, this);
+ }
Library get enclosingLibrary => parent;
- Library get importedLibrary => importedLibraryReference.asLibrary;
+ Library get targetLibrary => importedLibraryReference.asLibrary;
+
+ static const int ExportFlag = 1 << 0;
+ static const int DeferredFlag = 1 << 1;
+
+ bool get isExport => flags & ExportFlag != 0;
+ bool get isImport => !isExport;
+ bool get isDeferred => flags & DeferredFlag != 0;
+
+ void addAnnotation(Expression annotation) {
+ annotations.add(annotation..parent = this);
+ }
+
+ accept(TreeVisitor v) => v.visitLibraryDependency(this);
+
+ visitChildren(Visitor v) {
+ visitList(annotations, v);
+ visitList(combinators, v);
+ }
+
+ transformChildren(Transformer v) {
+ transformList(annotations, v, this);
+ transformList(combinators, v, this);
+ }
+}
+
+/// A `show` or `hide` clause for an import or export.
+class Combinator extends TreeNode {
+ bool isShow;
+ final List<String> names;
+
+ LibraryDependency get dependency => parent;
+
+ Combinator(this.isShow, this.names);
+ Combinator.show(this.names) : isShow = true;
+ Combinator.hide(this.names) : isShow = false;
- accept(TreeVisitor v) => v.visitDeferredImport(this);
+ bool get isHide => !isShow;
+ @override
+ accept(TreeVisitor v) => v.visitCombinator(this);
+
+ @override
visitChildren(Visitor v) {}
+ @override
transformChildren(Transformer v) {}
}
@@ -2793,7 +2878,7 @@ class Let extends Expression {
/// to mark the deferred import as 'loaded' and return a future.
class LoadLibrary extends Expression {
/// Reference to a deferred import in the enclosing library.
- DeferredImport import;
+ LibraryDependency import;
LoadLibrary(this.import);
@@ -2811,7 +2896,7 @@ class LoadLibrary extends Expression {
/// Checks that the given deferred import has been marked as 'loaded'.
class CheckLibraryIsLoaded extends Expression {
/// Reference to a deferred import in the enclosing library.
- DeferredImport import;
+ LibraryDependency import;
CheckLibraryIsLoaded(this.import);
« no previous file with comments | « pkg/kernel/binary.md ('k') | pkg/kernel/lib/binary/ast_from_binary.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698