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

Unified Diff: pkg/front_end/lib/src/fasta/builder/shadow_ast.dart

Issue 2769723004: Introduce a shadow hierarchy and factory class for use by fasta's BodyBuilder. (Closed)
Patch Set: Created 3 years, 9 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/builder/shadow_ast.dart
diff --git a/pkg/front_end/lib/src/fasta/builder/shadow_ast.dart b/pkg/front_end/lib/src/fasta/builder/shadow_ast.dart
new file mode 100644
index 0000000000000000000000000000000000000000..fa08c51ef64d8ab59343b5ff56ad8c58f9d2e50b
--- /dev/null
+++ b/pkg/front_end/lib/src/fasta/builder/shadow_ast.dart
@@ -0,0 +1,112 @@
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
ahe 2017/03/24 12:00:40 This comment is so last year ;-)
Paul Berry 2017/03/24 14:55:23 Done.
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+/// This file declares mixins which can be used to create a shadow hierarchy
+/// of either the kernel or the analyzer AST representations.
+///
+/// These classes are intended to be used by [BodyBuilder] as a form of
+/// indirection so that it can manipulate either kernel or analyzer ASTs.
+///
+/// All methods, getters, and setters defined in this file start with the prefix
+/// "shadow" in order to avoid naming conflicts with code in kernel or analyzer.
ahe 2017/03/24 12:00:40 It would probably help debugging if we also add Sh
Paul Berry 2017/03/24 14:55:23 Fair enough. Done.
+///
+/// Note that the analyzer AST representation closely parallels Dart syntax,
+/// whereas the kernel AST representation is desugared. The classes in the
+/// shadow hierarchy represent the full language (prior to desugaring).
+import 'package:kernel/ast.dart' show DartType;
+
+/// Shadow mixin representing a statement block.
+abstract class Block implements Statement {
+ /// Iterates through the statements contained in the block.
+ Iterable<Statement> get shadowStatements;
+}
+
+/// Common interface for shadow mixins representing expressions.
+///
+/// TODO(paulberry): add an abstract `shadowInfer` method here to do type
+/// inference.
+abstract class Expression {}
+
+/// Shadow mixin representing a function expression.
+abstract class FunctionExpression implements Expression {
+ /// Gets the body of the function expression.
+ Statement get shadowBody;
+
+ /// Indicates whether the function is asynchronous (`async` or `async*`)
+ bool get shadowIsAsync;
+
+ /// Indicates whether the function was declared using `=>` syntax.
+ bool get shadowIsExpressionFunction;
+
+ /// Indicates whether the function is a generator (`sync*` or `async*`)
+ bool get shadowIsGenerator;
+
+ /// Sets the return type of the function expression.
+ ///
+ /// Intended for use by type inference.
+ void set shadowReturnType(DartType type);
+
+ /// Creates a [DartType] representing the type of the function expression.
+ ///
+ /// If type inference has already been performed, returns the inferred type.
+ /// Otherwise returns the declared type.
+ DartType shadowMakeFunctionType();
scheglov 2017/03/24 03:19:17 Why not getter?
Paul Berry 2017/03/24 14:55:23 Done.
+}
+
+/// Shadow mixin representing an integer literal.
+abstract class IntLiteral implements Expression {}
+
+/// Shadow mixin representing a list literal.
+abstract class ListLiteral implements Expression {
+ /// Iterates through the expressions contained in the list literal.
+ Iterable<Expression> get shadowExpressions;
+
+ /// Gets the type argument of the list literal. If type inference has not
+ /// been performed and no explicit type argument was specified, returns
+ /// `null`.
+ DartType get shadowTypeArgument;
+
+ /// Sets the type argument of the list literal.
+ ///
+ /// Intended for use by type inference.
+ void set shadowTypeArgument(DartType type);
+}
+
+/// Shadow mixin representing a null literal.
+abstract class NullLiteral implements Expression {}
+
+/// Shadow mixin representing a return statement.
+abstract class ReturnStatement implements Statement {
+ /// Gets the expression being returned, or `null` if this is a bare "return"
+ /// statement.
+ Expression get shadowExpression;
+}
+
+/// Common interface for shadow mixins representing statements.
+///
+/// TODO(paulberry): add an abstract `shadowInfer` method here to do type
+/// inference.
+abstract class Statement {}
+
+/// Shadow mixin representing a declaration of a single variable.
+abstract class VariableDeclaration implements Statement {
+ /// Gets the initializer expression for the variable, or `null` if the
+ /// variable has no initializer.
+ Expression get shadowInitializer;
+
+ /// Gets the type of the variable. If type inference has not been performed
+ /// and no explicit type was specified, returns `null`.
+ DartType get shadowType;
+
+ /// Sets the type of the variable.
+ ///
+ /// Intended for use by type inference.
+ void set shadowType(DartType type);
+}
+
+/// Shadow mixin representing a "read" reference to a variable.
scheglov 2017/03/24 03:19:16 I don't understand this yet. Is it a node or eleme
Paul Berry 2017/03/24 14:55:23 I haven't prototyped this yet, but here's my curre
+abstract class VariableGet implements Expression {
+ /// Gets the variable declaration which is being referenced.
+ VariableDeclaration get shadowDeclaration;
+}

Powered by Google App Engine
This is Rietveld 408576698