@@ -39,15 +39,89 @@ abstract class Expression implements Spec {
3939 return new BinaryExpression ._(toExpression (), other, '&&' );
4040 }
4141
42+ /// This expression preceding by `await` .
43+ Expression get awaited {
44+ return new BinaryExpression ._(
45+ const LiteralExpression ._('await' ),
46+ this ,
47+ '' ,
48+ );
49+ }
50+
51+ /// Return `{other} = {this}` .
52+ Expression assign (Expression other) {
53+ return new BinaryExpression ._(
54+ other,
55+ this ,
56+ '=' ,
57+ );
58+ }
59+
60+ /// Return `{other} ??= {this}` .
61+ Expression assignNullAware (Expression other) {
62+ return new BinaryExpression ._(
63+ other,
64+ this ,
65+ '??=' ,
66+ );
67+ }
68+
69+ /// Return `var {name} = {this}` .
70+ Expression assignVar (String name, [Reference type]) {
71+ return new BinaryExpression ._(
72+ type == null
73+ ? new LiteralExpression ._('var $name ' )
74+ : new BinaryExpression ._(
75+ type.toExpression (),
76+ new LiteralExpression ._(name),
77+ '' ,
78+ ),
79+ this ,
80+ '=' ,
81+ );
82+ }
83+
84+ /// Return `final {name} = {this}` .
85+ Expression assignFinal (String name, [Reference type]) {
86+ return new BinaryExpression ._(
87+ type == null
88+ ? const LiteralExpression ._('final' )
89+ : new BinaryExpression ._(
90+ const LiteralExpression ._('final' ),
91+ type.toExpression (),
92+ '' ,
93+ ),
94+ this ,
95+ '$name =' ,
96+ );
97+ }
98+
99+ /// Return `const {name} = {this}` .
100+ Expression assignConst (String name, [Reference type]) {
101+ return new BinaryExpression ._(
102+ type == null
103+ ? const LiteralExpression ._('const' )
104+ : new BinaryExpression ._(
105+ const LiteralExpression ._('const' ),
106+ type.toExpression (),
107+ '' ,
108+ ),
109+ this ,
110+ '$name =' ,
111+ );
112+ }
113+
42114 /// Call this expression as a method.
43115 Expression call (
44116 List <Expression > positionalArguments, [
45117 Map <String , Expression > namedArguments = const {},
118+ List <Reference > typeArguments = const [],
46119 ]) {
47120 return new InvokeExpression ._(
48121 this ,
49122 positionalArguments,
50123 namedArguments,
124+ typeArguments,
51125 );
52126 }
53127
@@ -65,27 +139,74 @@ abstract class Expression implements Spec {
65139 Expression newInstance (
66140 List <Expression > positionalArguments, [
67141 Map <String , Expression > namedArguments = const {},
142+ List <Reference > typeArguments = const [],
68143 ]) {
69144 return new InvokeExpression ._new (
70145 this ,
71146 positionalArguments,
72147 namedArguments,
148+ typeArguments,
149+ null ,
150+ );
151+ }
152+
153+ /// Returns a new instance of this expression with a named constructor.
154+ Expression newInstanceNamed (
155+ String name,
156+ List <Expression > positionalArguments, [
157+ Map <String , Expression > namedArguments = const {},
158+ List <Reference > typeArguments = const [],
159+ ]) {
160+ return new InvokeExpression ._new (
161+ this ,
162+ positionalArguments,
163+ namedArguments,
164+ typeArguments,
165+ name,
73166 );
74167 }
75168
76169 /// Returns a const instance of this expression.
77170 Expression constInstance (
78171 List <Expression > positionalArguments, [
79172 Map <String , Expression > namedArguments = const {},
173+ List <Reference > typeArguments = const [],
80174 ]) {
81175 return new InvokeExpression ._const (
82176 this ,
83177 positionalArguments,
84178 namedArguments,
179+ typeArguments,
180+ null ,
85181 );
86182 }
87183
88- /// May be overriden to support other types implementing [Expression] .
184+ /// Returns a const instance of this expression with a named constructor.
185+ Expression constInstanceNamed (
186+ String name,
187+ List <Expression > positionalArguments, [
188+ Map <String , Expression > namedArguments = const {},
189+ List <Reference > typeArguments = const [],
190+ ]) {
191+ return new InvokeExpression ._const (
192+ this ,
193+ positionalArguments,
194+ namedArguments,
195+ typeArguments,
196+ name,
197+ );
198+ }
199+
200+ /// This expression preceding by `return` .
201+ Expression get returned {
202+ return new BinaryExpression ._(
203+ const LiteralExpression ._('return' ),
204+ this ,
205+ '' ,
206+ );
207+ }
208+
209+ /// May be overridden to support other types implementing [Expression] .
89210 @visibleForOverriding
90211 Expression toExpression () => this ;
91212}
@@ -171,6 +292,16 @@ abstract class ExpressionEmitter implements ExpressionVisitor<StringSink> {
171292 break ;
172293 }
173294 expression.target.accept (this , output);
295+ if (expression.name != null ) {
296+ output..write ('.' )..write (expression.name);
297+ }
298+ if (expression.typeArguments.isNotEmpty) {
299+ output.write ('<' );
300+ visitAll <Reference >(expression.typeArguments, output, (type) {
301+ type.accept (this , output);
302+ });
303+ output.write ('>' );
304+ }
174305 output.write ('(' );
175306 visitAll <Spec >(expression.positionalArguments, output, (spec) {
176307 spec.accept (this , output);
0 commit comments