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

Side by Side Diff: lib/src/codegen/ast_builder.dart

Issue 961513002: Flesh out dynamic invocation code (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Fix ++ and -- Created 5 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 unified diff | Download patch
« no previous file with comments | « no previous file | lib/src/codegen/js_codegen.dart » ('j') | lib/src/codegen/js_codegen.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library ddc.src.codegen.ast_builder; 5 library ddc.src.codegen.ast_builder;
6 6
7 import 'package:analyzer/src/generated/ast.dart'; 7 import 'package:analyzer/src/generated/ast.dart';
8 import 'package:analyzer/src/generated/scanner.dart'; 8 import 'package:analyzer/src/generated/scanner.dart';
9 import 'package:analyzer/src/generated/utilities_dart.dart'; 9 import 'package:analyzer/src/generated/utilities_dart.dart';
10 import 'package:logging/logging.dart' as logger; 10 import 'package:logging/logging.dart' as logger;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 } 56 }
57 57
58 static BooleanLiteral booleanLiteral(bool b) { 58 static BooleanLiteral booleanLiteral(bool b) {
59 return RawAstBuilder.booleanLiteral(b); 59 return RawAstBuilder.booleanLiteral(b);
60 } 60 }
61 61
62 static NullLiteral nullLiteral() { 62 static NullLiteral nullLiteral() {
63 return RawAstBuilder.nullLiteral(); 63 return RawAstBuilder.nullLiteral();
64 } 64 }
65 65
66 static IntegerLiteral integerLiteral(int i) {
67 return RawAstBuilder.integerLiteral(i);
68 }
69
66 static StringLiteral stringLiteral(String s) { 70 static StringLiteral stringLiteral(String s) {
67 return RawAstBuilder.simpleStringLiteral(s); 71 return RawAstBuilder.simpleStringLiteral(s);
68 } 72 }
69 73
70 static StringLiteral multiLineStringLiteral(String s) { 74 static StringLiteral multiLineStringLiteral(String s) {
71 return RawAstBuilder.tripleQuotedStringLiteral(s); 75 return RawAstBuilder.tripleQuotedStringLiteral(s);
72 } 76 }
73 77
74 static AsExpression asExpression(Expression exp, TypeName type) { 78 static AsExpression asExpression(Expression exp, TypeName type) {
75 return RawAstBuilder.asExpression(exp, type); 79 return RawAstBuilder.asExpression(exp, type);
76 } 80 }
77 81
78 static IsExpression isExpression(Expression exp, TypeName type) { 82 static IsExpression isExpression(Expression exp, TypeName type) {
79 return RawAstBuilder.isExpression(exp, type); 83 return RawAstBuilder.isExpression(exp, type);
80 } 84 }
81 85
82 static ParenthesizedExpression parenthesizedExpression(Expression exp) { 86 static ParenthesizedExpression parenthesizedExpression(Expression exp) {
83 return RawAstBuilder.parenthesizedExpression(exp); 87 return RawAstBuilder.parenthesizedExpression(exp);
84 } 88 }
85 89
86 static Expression parenthesize(Expression exp) { 90 static Expression parenthesize(Expression exp) {
87 if (exp is Identifier || 91 if (exp is Identifier ||
88 exp is ParenthesizedExpression || 92 exp is ParenthesizedExpression ||
89 exp is FunctionExpressionInvocation || 93 exp is FunctionExpressionInvocation ||
90 exp is MethodInvocation) return exp; 94 exp is MethodInvocation) return exp;
91 return parenthesizedExpression(exp); 95 return parenthesizedExpression(exp);
92 } 96 }
93 97
98 static Token _binaryOperation(String oper) {
99 switch (oper) {
100 case '==':
101 return new Token(TokenType.EQ_EQ, 0);
102 case '+':
103 return new Token(TokenType.PLUS, 0);
104 case '-':
105 return new Token(TokenType.MINUS, 0);
106 }
107 // TODO(vsm): Add cases as needed.
108 assert(false);
109 return null;
110 }
111
94 static BinaryExpression binaryExpression( 112 static BinaryExpression binaryExpression(
95 Expression l, String oper, Expression r) { 113 Expression l, String oper, Expression r) {
96 if (oper == "==") return RawAstBuilder.equalityExpression(l, r); 114 Token token = _binaryOperation(oper);
97 assert(false); 115 return RawAstBuilder.binaryExpression(l, token, r);
98 return null;
99 } 116 }
100 117
101 static ConditionalExpression conditionalExpression( 118 static ConditionalExpression conditionalExpression(
102 Expression cond, Expression tExp, Expression fExp) { 119 Expression cond, Expression tExp, Expression fExp) {
103 return RawAstBuilder.conditionalExpression(cond, tExp, fExp); 120 return RawAstBuilder.conditionalExpression(cond, tExp, fExp);
104 } 121 }
105 122
106 static Expression application(Expression function, List<Expression> es) { 123 static Expression application(Expression function, List<Expression> es) {
107 ArgumentList args = argumentList(es); 124 ArgumentList args = argumentList(es);
108 return RawAstBuilder.functionExpressionInvocation(function, args); 125 return RawAstBuilder.functionExpressionInvocation(function, args);
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 static BooleanLiteral booleanLiteral(bool b) { 262 static BooleanLiteral booleanLiteral(bool b) {
246 var k = new KeywordToken(b ? Keyword.TRUE : Keyword.FALSE, 0); 263 var k = new KeywordToken(b ? Keyword.TRUE : Keyword.FALSE, 0);
247 return new BooleanLiteral(k, b); 264 return new BooleanLiteral(k, b);
248 } 265 }
249 266
250 static NullLiteral nullLiteral() { 267 static NullLiteral nullLiteral() {
251 var n = new KeywordToken(Keyword.NULL, 0); 268 var n = new KeywordToken(Keyword.NULL, 0);
252 return new NullLiteral(n); 269 return new NullLiteral(n);
253 } 270 }
254 271
272 static IntegerLiteral integerLiteral(int i) {
273 StringToken token = new StringToken(TokenType.INT, '$i', 0);
274 return new IntegerLiteral(token, i);
275 }
276
255 static SimpleStringLiteral simpleStringLiteral(String s) { 277 static SimpleStringLiteral simpleStringLiteral(String s) {
256 StringToken token = new StringToken(TokenType.STRING, "\"" + s + "\"", 0); 278 StringToken token = new StringToken(TokenType.STRING, "\"" + s + "\"", 0);
257 return new SimpleStringLiteral(token, s); 279 return new SimpleStringLiteral(token, s);
258 } 280 }
259 281
260 static SimpleStringLiteral tripleQuotedStringLiteral(String s) { 282 static SimpleStringLiteral tripleQuotedStringLiteral(String s) {
261 StringToken token = new StringToken(TokenType.STRING, '"""' + s + '"""', 0); 283 StringToken token = new StringToken(TokenType.STRING, '"""' + s + '"""', 0);
262 return new SimpleStringLiteral(token, s); 284 return new SimpleStringLiteral(token, s);
263 } 285 }
264 286
265 static AsExpression asExpression(Expression exp, TypeName type) { 287 static AsExpression asExpression(Expression exp, TypeName type) {
266 Token token = new KeywordToken(Keyword.AS, 0); 288 Token token = new KeywordToken(Keyword.AS, 0);
267 return new AsExpression(exp, token, type); 289 return new AsExpression(exp, token, type);
268 } 290 }
269 291
270 static IsExpression isExpression(Expression exp, TypeName type) { 292 static IsExpression isExpression(Expression exp, TypeName type) {
271 Token token = new KeywordToken(Keyword.IS, 0); 293 Token token = new KeywordToken(Keyword.IS, 0);
272 return new IsExpression(exp, token, null, type); 294 return new IsExpression(exp, token, null, type);
273 } 295 }
274 296
275 static ParenthesizedExpression parenthesizedExpression(Expression exp) { 297 static ParenthesizedExpression parenthesizedExpression(Expression exp) {
276 Token lp = new BeginToken(TokenType.OPEN_PAREN, exp.offset); 298 Token lp = new BeginToken(TokenType.OPEN_PAREN, exp.offset);
277 Token rp = new Token(TokenType.CLOSE_PAREN, exp.end); 299 Token rp = new Token(TokenType.CLOSE_PAREN, exp.end);
278 return new ParenthesizedExpression(lp, exp, rp); 300 return new ParenthesizedExpression(lp, exp, rp);
279 } 301 }
280 302
281 static BinaryExpression equalityExpression(Expression l, Expression r) { 303 static BinaryExpression binaryExpression(
282 var eq = new Token(TokenType.EQ_EQ, 0); 304 Expression l, Token op, Expression r) {
283 return new BinaryExpression(l, eq, r); 305 return new BinaryExpression(l, op, r);
284 } 306 }
285 307
286 static ConditionalExpression conditionalExpression( 308 static ConditionalExpression conditionalExpression(
287 Expression cond, Expression tExp, Expression fExp) { 309 Expression cond, Expression tExp, Expression fExp) {
288 var q = new Token(TokenType.QUESTION, 0); 310 var q = new Token(TokenType.QUESTION, 0);
289 var c = new Token(TokenType.COLON, 0); 311 var c = new Token(TokenType.COLON, 0);
290 return new ConditionalExpression(cond, q, tExp, c, fExp); 312 return new ConditionalExpression(cond, q, tExp, c, fExp);
291 } 313 }
292 314
293 static Expression functionExpressionInvocation( 315 static Expression functionExpressionInvocation(
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 404
383 static NamedExpression namedParameter(Identifier s, Expression e) { 405 static NamedExpression namedParameter(Identifier s, Expression e) {
384 return namedExpression(s, e); 406 return namedExpression(s, e);
385 } 407 }
386 408
387 static NamedExpression namedExpression(Identifier s, Expression e) { 409 static NamedExpression namedExpression(Identifier s, Expression e) {
388 Label l = new Label(s, new Token(TokenType.COLON, 0)); 410 Label l = new Label(s, new Token(TokenType.COLON, 0));
389 return new NamedExpression(l, e); 411 return new NamedExpression(l, e);
390 } 412 }
391 } 413 }
OLDNEW
« no previous file with comments | « no previous file | lib/src/codegen/js_codegen.dart » ('j') | lib/src/codegen/js_codegen.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698