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

Unified Diff: lib/src/codegen/ast_builder.dart

Issue 1243503007: fixes #221, initial sync*, async, async* implementation (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 5 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 | « lib/src/checker/rules.dart ('k') | lib/src/codegen/js_codegen.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/codegen/ast_builder.dart
diff --git a/lib/src/codegen/ast_builder.dart b/lib/src/codegen/ast_builder.dart
index 4706d8f47d6c57a3d12f4a3c976808a2eb22defa..7090f2573db97a556f24865fdc96bf4bbe1fa629 100644
--- a/lib/src/codegen/ast_builder.dart
+++ b/lib/src/codegen/ast_builder.dart
@@ -328,11 +328,40 @@ class AstBuilder {
static NamedExpression namedExpression(String s, Expression e) {
return RawAstBuilder.namedExpression(identifierFromString(s), e);
}
+
+ /// Declares a single variable `var <name> = <init>` with the type and name
+ /// specified by the VariableElement. See also [variableStatement].
+ static VariableDeclarationList declareVariable(SimpleIdentifier name,
+ [Expression init]) {
+ var eqToken = init != null ? new Token(TokenType.EQ, 0) : null;
+ var varToken = new KeywordToken(Keyword.VAR, 0);
+ return new VariableDeclarationList(null, null, varToken, null,
+ [new VariableDeclaration(name, eqToken, init)]);
+ }
+
+ static VariableDeclarationStatement variableStatement(SimpleIdentifier name,
+ [Expression init]) {
+ return RawAstBuilder
+ .variableDeclarationStatement(declareVariable(name, init));
+ }
+
+ static InstanceCreationExpression instanceCreation(
+ ConstructorName ctor, List<Expression> args) {
+ var newToken = new KeywordToken(Keyword.NEW, 0);
+ return new InstanceCreationExpression(
+ newToken, ctor, RawAstBuilder.argumentList(args));
+ }
}
// This class provides a low-level wrapper around the constructors for
// the AST. It mostly simply abstracts from the lexical tokens.
class RawAstBuilder {
+ static ConstructorName constructorName(TypeName type,
+ [SimpleIdentifier name]) {
+ Token period = name != null ? new Token(TokenType.PERIOD, 0) : null;
+ return new ConstructorName(type, period, name);
+ }
+
static SimpleIdentifier identifierFromString(String name) {
StringToken token = new SyntheticStringToken(TokenType.IDENTIFIER, name, 0);
return new SimpleIdentifier(token);
@@ -532,4 +561,10 @@ class RawAstBuilder {
Label l = new Label(s, new Token(TokenType.COLON, 0));
return new NamedExpression(l, e);
}
+
+ static VariableDeclarationStatement variableDeclarationStatement(
+ VariableDeclarationList varDecl) {
+ var semi = new Token(TokenType.SEMICOLON, 0);
+ return new VariableDeclarationStatement(varDecl, semi);
+ }
}
« no previous file with comments | « lib/src/checker/rules.dart ('k') | lib/src/codegen/js_codegen.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698