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

Side by Side Diff: pkg/js_ast/lib/src/template.dart

Issue 2748103010: Run dartfmt on js_ast (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 unified diff | Download patch
« no previous file with comments | « pkg/js_ast/lib/src/printer.dart ('k') | pkg/js_ast/test/printer_callback_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 part of js_ast; 5 part of js_ast;
6 6
7 class TemplateManager { 7 class TemplateManager {
8 Map<String, Template> expressionTemplates = new Map<String, Template>(); 8 Map<String, Template> expressionTemplates = new Map<String, Template>();
9 Map<String, Template> statementTemplates = new Map<String, Template>(); 9 Map<String, Template> statementTemplates = new Map<String, Template>();
10 10
11 TemplateManager(); 11 TemplateManager();
12 12
13
14 Template lookupExpressionTemplate(String source) { 13 Template lookupExpressionTemplate(String source) {
15 return expressionTemplates[source]; 14 return expressionTemplates[source];
16 } 15 }
17 16
18 Template defineExpressionTemplate(String source, Node ast) { 17 Template defineExpressionTemplate(String source, Node ast) {
19 Template template = 18 Template template =
20 new Template(source, ast, isExpression: true, forceCopy: false); 19 new Template(source, ast, isExpression: true, forceCopy: false);
21 expressionTemplates[source] = template; 20 expressionTemplates[source] = template;
22 return template; 21 return template;
23 } 22 }
(...skipping 24 matching lines...) Expand all
48 47
49 Instantiator instantiator; 48 Instantiator instantiator;
50 49
51 int positionalArgumentCount = -1; 50 int positionalArgumentCount = -1;
52 51
53 // Null, unless there are named holes. 52 // Null, unless there are named holes.
54 List<String> holeNames; 53 List<String> holeNames;
55 bool get isPositional => holeNames == null; 54 bool get isPositional => holeNames == null;
56 55
57 Template(this.source, this.ast, 56 Template(this.source, this.ast,
58 {this.isExpression: true, this.forceCopy: false}) { 57 {this.isExpression: true, this.forceCopy: false}) {
59 assert(this.isExpression ? ast is Expression : ast is Statement); 58 assert(this.isExpression ? ast is Expression : ast is Statement);
60 _compile(); 59 _compile();
61 } 60 }
62 61
63 Template.withExpressionResult(this.ast) 62 Template.withExpressionResult(this.ast)
64 : source = null, isExpression = true, forceCopy = false { 63 : source = null,
64 isExpression = true,
65 forceCopy = false {
65 assert(ast is Expression); 66 assert(ast is Expression);
66 assert(_checkNoPlaceholders()); 67 assert(_checkNoPlaceholders());
67 positionalArgumentCount = 0; 68 positionalArgumentCount = 0;
68 instantiator = (arguments) => ast; 69 instantiator = (arguments) => ast;
69 } 70 }
70 71
71 Template.withStatementResult(this.ast) 72 Template.withStatementResult(this.ast)
72 : source = null, isExpression = false, forceCopy = false { 73 : source = null,
74 isExpression = false,
75 forceCopy = false {
73 assert(ast is Statement); 76 assert(ast is Statement);
74 assert(_checkNoPlaceholders()); 77 assert(_checkNoPlaceholders());
75 positionalArgumentCount = 0; 78 positionalArgumentCount = 0;
76 instantiator = (arguments) => ast; 79 instantiator = (arguments) => ast;
77 } 80 }
78 81
79 bool _checkNoPlaceholders() { 82 bool _checkNoPlaceholders() {
80 InstantiatorGeneratorVisitor generator = 83 InstantiatorGeneratorVisitor generator =
81 new InstantiatorGeneratorVisitor(false); 84 new InstantiatorGeneratorVisitor(false);
82 generator.compile(ast); 85 generator.compile(ast);
83 return generator.analysis.count == 0; 86 return generator.analysis.count == 0;
84 } 87 }
85 88
86 void _compile() { 89 void _compile() {
87 InstantiatorGeneratorVisitor generator = 90 InstantiatorGeneratorVisitor generator =
88 new InstantiatorGeneratorVisitor(forceCopy); 91 new InstantiatorGeneratorVisitor(forceCopy);
89 instantiator = generator.compile(ast); 92 instantiator = generator.compile(ast);
90 positionalArgumentCount = generator.analysis.count; 93 positionalArgumentCount = generator.analysis.count;
91 Set<String> names = generator.analysis.holeNames; 94 Set<String> names = generator.analysis.holeNames;
92 holeNames = names.toList(growable:false); 95 holeNames = names.toList(growable: false);
93 } 96 }
94 97
95 /// Instantiates the template with the given [arguments]. 98 /// Instantiates the template with the given [arguments].
96 /// 99 ///
97 /// This method fills in the holes with the given arguments. The [arguments] 100 /// This method fills in the holes with the given arguments. The [arguments]
98 /// must be either a [List] or a [Map]. 101 /// must be either a [List] or a [Map].
99 Node instantiate(var arguments) { 102 Node instantiate(var arguments) {
100 if (arguments is List) { 103 if (arguments is List) {
101 if (arguments.length != positionalArgumentCount) { 104 if (arguments.length != positionalArgumentCount) {
102 throw 'Wrong number of template arguments, given ${arguments.length}, ' 105 throw 'Wrong number of template arguments, given ${arguments.length}, '
(...skipping 18 matching lines...) Expand all
121 } 124 }
122 } 125 }
123 126
124 /** 127 /**
125 * An Instantiator is a Function that generates a JS AST tree or List of 128 * An Instantiator is a Function that generates a JS AST tree or List of
126 * trees. [arguments] is a List for positional templates, or Map for 129 * trees. [arguments] is a List for positional templates, or Map for
127 * named templates. 130 * named templates.
128 */ 131 */
129 typedef Node Instantiator(var arguments); 132 typedef Node Instantiator(var arguments);
130 133
131
132 /** 134 /**
133 * InstantiatorGeneratorVisitor compiles a template. This class compiles a tree 135 * InstantiatorGeneratorVisitor compiles a template. This class compiles a tree
134 * containing [InterpolatedNode]s into a function that will create a copy of the 136 * containing [InterpolatedNode]s into a function that will create a copy of the
135 * tree with the interpolated nodes substituted with provided values. 137 * tree with the interpolated nodes substituted with provided values.
136 */ 138 */
137 class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> { 139 class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
138
139 final bool forceCopy; 140 final bool forceCopy;
140 141
141 InterpolatedNodeAnalysis analysis = new InterpolatedNodeAnalysis(); 142 InterpolatedNodeAnalysis analysis = new InterpolatedNodeAnalysis();
142 143
143 /** 144 /**
144 * The entire tree is cloned if [forceCopy] is true. 145 * The entire tree is cloned if [forceCopy] is true.
145 */ 146 */
146 InstantiatorGeneratorVisitor(this.forceCopy); 147 InstantiatorGeneratorVisitor(this.forceCopy);
147 148
148 Instantiator compile(Node node) { 149 Instantiator compile(Node node) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 if (node is InterpolatedExpression) { 216 if (node is InterpolatedExpression) {
216 var nameOrPosition = node.nameOrPosition; 217 var nameOrPosition = node.nameOrPosition;
217 return (arguments) { 218 return (arguments) {
218 var value = arguments[nameOrPosition]; 219 var value = arguments[nameOrPosition];
219 Expression toExpression(item) { 220 Expression toExpression(item) {
220 if (item is Expression) return item; 221 if (item is Expression) return item;
221 if (item is String) return convertStringToVariableUse(item); 222 if (item is String) return convertStringToVariableUse(item);
222 return error('Interpolated value #$nameOrPosition is not ' 223 return error('Interpolated value #$nameOrPosition is not '
223 'an Expression or List of Expressions: $value'); 224 'an Expression or List of Expressions: $value');
224 } 225 }
226
225 if (value is Iterable) return value.map(toExpression); 227 if (value is Iterable) return value.map(toExpression);
226 return toExpression(value); 228 return toExpression(value);
227 }; 229 };
228 } 230 }
229 return visit(node); 231 return visit(node);
230 } 232 }
231 233
232 Instantiator visitInterpolatedLiteral(InterpolatedLiteral node) { 234 Instantiator visitInterpolatedLiteral(InterpolatedLiteral node) {
233 var nameOrPosition = node.nameOrPosition; 235 var nameOrPosition = node.nameOrPosition;
234 return (arguments) { 236 return (arguments) {
235 var value = arguments[nameOrPosition]; 237 var value = arguments[nameOrPosition];
236 if (value is Literal) return value; 238 if (value is Literal) return value;
237 error('Interpolated value #$nameOrPosition is not a Literal: $value'); 239 error('Interpolated value #$nameOrPosition is not a Literal: $value');
238 }; 240 };
239 } 241 }
240 242
241 Instantiator visitInterpolatedParameter(InterpolatedParameter node) { 243 Instantiator visitInterpolatedParameter(InterpolatedParameter node) {
242 var nameOrPosition = node.nameOrPosition; 244 var nameOrPosition = node.nameOrPosition;
243 return (arguments) { 245 return (arguments) {
244 var value = arguments[nameOrPosition]; 246 var value = arguments[nameOrPosition];
245 247
246 Parameter toParameter(item) { 248 Parameter toParameter(item) {
247 if (item is Parameter) return item; 249 if (item is Parameter) return item;
248 if (item is String) return new Parameter(item); 250 if (item is String) return new Parameter(item);
249 return error('Interpolated value #$nameOrPosition is not a Parameter or' 251 return error('Interpolated value #$nameOrPosition is not a Parameter or'
250 ' List of Parameters: $value'); 252 ' List of Parameters: $value');
251 } 253 }
254
252 if (value is Iterable) return value.map(toParameter); 255 if (value is Iterable) return value.map(toParameter);
253 return toParameter(value); 256 return toParameter(value);
254 }; 257 };
255 } 258 }
256 259
257 Instantiator visitInterpolatedSelector(InterpolatedSelector node) { 260 Instantiator visitInterpolatedSelector(InterpolatedSelector node) {
258 // A selector is an expression, as in `a[selector]`. 261 // A selector is an expression, as in `a[selector]`.
259 // A String argument converted into a LiteralString, so `a.#` with argument 262 // A String argument converted into a LiteralString, so `a.#` with argument
260 // 'foo' generates `a["foo"]` which prints as `a.foo`. 263 // 'foo' generates `a["foo"]` which prints as `a.foo`.
261 var nameOrPosition = node.nameOrPosition; 264 var nameOrPosition = node.nameOrPosition;
(...skipping 14 matching lines...) Expand all
276 }; 279 };
277 } 280 }
278 281
279 Instantiator visitSplayableStatement(Node node) { 282 Instantiator visitSplayableStatement(Node node) {
280 if (node is InterpolatedStatement) { 283 if (node is InterpolatedStatement) {
281 var nameOrPosition = node.nameOrPosition; 284 var nameOrPosition = node.nameOrPosition;
282 return (arguments) { 285 return (arguments) {
283 var value = arguments[nameOrPosition]; 286 var value = arguments[nameOrPosition];
284 Statement toStatement(item) { 287 Statement toStatement(item) {
285 if (item is Statement) return item; 288 if (item is Statement) return item;
286 if (item is Expression) return item.toStatement();; 289 if (item is Expression) return item.toStatement();
290 ;
287 return error('Interpolated value #$nameOrPosition is not ' 291 return error('Interpolated value #$nameOrPosition is not '
288 'a Statement or List of Statements: $value'); 292 'a Statement or List of Statements: $value');
289 } 293 }
294
290 if (value is Iterable) return value.map(toStatement); 295 if (value is Iterable) return value.map(toStatement);
291 return toStatement(value); 296 return toStatement(value);
292 }; 297 };
293 } 298 }
294 return visit(node); 299 return visit(node);
295 } 300 }
296 301
297 Instantiator visitProgram(Program node) { 302 Instantiator visitProgram(Program node) {
298 List instantiators = node.body.map(visitSplayableStatement).toList(); 303 List instantiators = node.body.map(visitSplayableStatement).toList();
299 return (arguments) { 304 return (arguments) {
300 List<Statement> statements = <Statement>[]; 305 List<Statement> statements = <Statement>[];
301 void add(node) { 306 void add(node) {
302 if (node is EmptyStatement) return; 307 if (node is EmptyStatement) return;
303 if (node is Iterable) { 308 if (node is Iterable) {
304 statements.addAll(node); 309 statements.addAll(node);
305 } else { 310 } else {
306 statements.add(node.toStatement()); 311 statements.add(node.toStatement());
307 } 312 }
308 } 313 }
314
309 for (Instantiator instantiator in instantiators) { 315 for (Instantiator instantiator in instantiators) {
310 add(instantiator(arguments)); 316 add(instantiator(arguments));
311 } 317 }
312 return new Program(statements); 318 return new Program(statements);
313 }; 319 };
314 } 320 }
315 321
316 Instantiator visitBlock(Block node) { 322 Instantiator visitBlock(Block node) {
317 List instantiators = node.statements.map(visitSplayableStatement).toList(); 323 List instantiators = node.statements.map(visitSplayableStatement).toList();
318 return (arguments) { 324 return (arguments) {
319 List<Statement> statements = <Statement>[]; 325 List<Statement> statements = <Statement>[];
320 void add(node) { 326 void add(node) {
321 if (node is EmptyStatement) return; 327 if (node is EmptyStatement) return;
322 if (node is Iterable) { 328 if (node is Iterable) {
323 statements.addAll(node); 329 statements.addAll(node);
324 } else if (node is Block) { 330 } else if (node is Block) {
325 statements.addAll(node.statements); 331 statements.addAll(node.statements);
326 } else { 332 } else {
327 statements.add(node.toStatement()); 333 statements.add(node.toStatement());
328 } 334 }
329 } 335 }
336
330 for (Instantiator instantiator in instantiators) { 337 for (Instantiator instantiator in instantiators) {
331 add(instantiator(arguments)); 338 add(instantiator(arguments));
332 } 339 }
333 return new Block(statements); 340 return new Block(statements);
334 }; 341 };
335 } 342 }
336 343
337 Instantiator visitExpressionStatement(ExpressionStatement node) { 344 Instantiator visitExpressionStatement(ExpressionStatement node) {
338 Instantiator buildExpression = visit(node.expression); 345 Instantiator buildExpression = visit(node.expression);
339 return (arguments) { 346 return (arguments) {
(...skipping 13 matching lines...) Expand all
353 } 360 }
354 361
355 Instantiator visitIfConditionalCompilation(If node) { 362 Instantiator visitIfConditionalCompilation(If node) {
356 // Special version of visitInterpolatedExpression that permits bools. 363 // Special version of visitInterpolatedExpression that permits bools.
357 compileCondition(InterpolatedExpression node) { 364 compileCondition(InterpolatedExpression node) {
358 var nameOrPosition = node.nameOrPosition; 365 var nameOrPosition = node.nameOrPosition;
359 return (arguments) { 366 return (arguments) {
360 var value = arguments[nameOrPosition]; 367 var value = arguments[nameOrPosition];
361 if (value is bool) return value; 368 if (value is bool) return value;
362 if (value is Expression) return value; 369 if (value is Expression) return value;
363 if (value is String) return convertStringToVariableUse(value);; 370 if (value is String) return convertStringToVariableUse(value);
371 ;
364 error('Interpolated value #$nameOrPosition ' 372 error('Interpolated value #$nameOrPosition '
365 'is not an Expression: $value'); 373 'is not an Expression: $value');
366 }; 374 };
367 } 375 }
376
368 var makeCondition = compileCondition(node.condition); 377 var makeCondition = compileCondition(node.condition);
369 Instantiator makeThen = visit(node.then); 378 Instantiator makeThen = visit(node.then);
370 Instantiator makeOtherwise = visit(node.otherwise); 379 Instantiator makeOtherwise = visit(node.otherwise);
371 return (arguments) { 380 return (arguments) {
372 var condition = makeCondition(arguments); 381 var condition = makeCondition(arguments);
373 if (condition is bool) { 382 if (condition is bool) {
374 if (condition == true) { 383 if (condition == true) {
375 return makeThen(arguments); 384 return makeThen(arguments);
376 } else { 385 } else {
377 return makeOtherwise(arguments); 386 return makeOtherwise(arguments);
378 } 387 }
379 } 388 }
380 return new If( 389 return new If(condition, makeThen(arguments), makeOtherwise(arguments));
381 condition,
382 makeThen(arguments),
383 makeOtherwise(arguments));
384 }; 390 };
385 } 391 }
386 392
387 Instantiator visitIfNormal(If node) { 393 Instantiator visitIfNormal(If node) {
388 Instantiator makeCondition = visit(node.condition); 394 Instantiator makeCondition = visit(node.condition);
389 Instantiator makeThen = visit(node.then); 395 Instantiator makeThen = visit(node.then);
390 Instantiator makeOtherwise = visit(node.otherwise); 396 Instantiator makeOtherwise = visit(node.otherwise);
391 return (arguments) { 397 return (arguments) {
392 return new If( 398 return new If(makeCondition(arguments), makeThen(arguments),
393 makeCondition(arguments),
394 makeThen(arguments),
395 makeOtherwise(arguments)); 399 makeOtherwise(arguments));
396 }; 400 };
397 } 401 }
398 402
399 Instantiator visitFor(For node) { 403 Instantiator visitFor(For node) {
400 Instantiator makeInit = visitNullable(node.init); 404 Instantiator makeInit = visitNullable(node.init);
401 Instantiator makeCondition = visitNullable(node.condition); 405 Instantiator makeCondition = visitNullable(node.condition);
402 Instantiator makeUpdate = visitNullable(node.update); 406 Instantiator makeUpdate = visitNullable(node.update);
403 Instantiator makeBody = visit(node.body); 407 Instantiator makeBody = visit(node.body);
404 return (arguments) { 408 return (arguments) {
405 return new For( 409 return new For(makeInit(arguments), makeCondition(arguments),
406 makeInit(arguments), makeCondition(arguments), makeUpdate(arguments), 410 makeUpdate(arguments), makeBody(arguments));
407 makeBody(arguments));
408 }; 411 };
409 } 412 }
410 413
411 Instantiator visitForIn(ForIn node) { 414 Instantiator visitForIn(ForIn node) {
412 Instantiator makeLeftHandSide = visit(node.leftHandSide); 415 Instantiator makeLeftHandSide = visit(node.leftHandSide);
413 Instantiator makeObject = visit(node.object); 416 Instantiator makeObject = visit(node.object);
414 Instantiator makeBody = visit(node.body); 417 Instantiator makeBody = visit(node.body);
415 return (arguments) { 418 return (arguments) {
416 return new ForIn( 419 return new ForIn(makeLeftHandSide(arguments), makeObject(arguments),
417 makeLeftHandSide(arguments),
418 makeObject(arguments),
419 makeBody(arguments)); 420 makeBody(arguments));
420 }; 421 };
421 } 422 }
422 423
423 TODO(String name) { 424 TODO(String name) {
424 throw new UnimplementedError('$this.$name'); 425 throw new UnimplementedError('$this.$name');
425 } 426 }
426 427
427 Instantiator visitWhile(While node) { 428 Instantiator visitWhile(While node) {
428 Instantiator makeCondition = visit(node.condition); 429 Instantiator makeCondition = visit(node.condition);
(...skipping 17 matching lines...) Expand all
446 Instantiator visitBreak(Break node) => 447 Instantiator visitBreak(Break node) =>
447 (arguments) => new Break(node.targetLabel); 448 (arguments) => new Break(node.targetLabel);
448 449
449 Instantiator visitReturn(Return node) { 450 Instantiator visitReturn(Return node) {
450 Instantiator makeExpression = visitNullable(node.value); 451 Instantiator makeExpression = visitNullable(node.value);
451 return (arguments) => new Return(makeExpression(arguments)); 452 return (arguments) => new Return(makeExpression(arguments));
452 } 453 }
453 454
454 Instantiator visitDartYield(DartYield node) { 455 Instantiator visitDartYield(DartYield node) {
455 Instantiator makeExpression = visit(node.expression); 456 Instantiator makeExpression = visit(node.expression);
456 return (arguments) => new DartYield(makeExpression(arguments), node.hasStar) ; 457 return (arguments) =>
458 new DartYield(makeExpression(arguments), node.hasStar);
457 } 459 }
458 460
459 Instantiator visitThrow(Throw node) { 461 Instantiator visitThrow(Throw node) {
460 Instantiator makeExpression = visit(node.expression); 462 Instantiator makeExpression = visit(node.expression);
461 return (arguments) => new Throw(makeExpression(arguments)); 463 return (arguments) => new Throw(makeExpression(arguments));
462 } 464 }
463 465
464 Instantiator visitTry(Try node) { 466 Instantiator visitTry(Try node) {
465 Instantiator makeBody = visit(node.body); 467 Instantiator makeBody = visit(node.body);
466 Instantiator makeCatch = visitNullable(node.catchPart); 468 Instantiator makeCatch = visitNullable(node.catchPart);
467 Instantiator makeFinally = visitNullable(node.finallyPart); 469 Instantiator makeFinally = visitNullable(node.finallyPart);
468 return (arguments) => new Try( 470 return (arguments) => new Try(
469 makeBody(arguments), makeCatch(arguments), makeFinally(arguments)); 471 makeBody(arguments), makeCatch(arguments), makeFinally(arguments));
470 } 472 }
471 473
472 Instantiator visitCatch(Catch node) { 474 Instantiator visitCatch(Catch node) {
473 Instantiator makeDeclaration = visit(node.declaration); 475 Instantiator makeDeclaration = visit(node.declaration);
474 Instantiator makeBody = visit(node.body); 476 Instantiator makeBody = visit(node.body);
475 return (arguments) => new Catch( 477 return (arguments) =>
476 makeDeclaration(arguments), makeBody(arguments)); 478 new Catch(makeDeclaration(arguments), makeBody(arguments));
477 } 479 }
478 480
479 Instantiator visitSwitch(Switch node) { 481 Instantiator visitSwitch(Switch node) {
480 Instantiator makeKey = visit(node.key); 482 Instantiator makeKey = visit(node.key);
481 Iterable<Instantiator> makeCases = node.cases.map(visit); 483 Iterable<Instantiator> makeCases = node.cases.map(visit);
482 return (arguments) { 484 return (arguments) {
483 return new Switch(makeKey(arguments), 485 return new Switch(
484 makeCases.map((Instantiator makeCase) => makeCase(arguments)) 486 makeKey(arguments),
485 .toList()); 487 makeCases
488 .map((Instantiator makeCase) => makeCase(arguments))
489 .toList());
486 }; 490 };
487 } 491 }
488 492
489 Instantiator visitCase(Case node) { 493 Instantiator visitCase(Case node) {
490 Instantiator makeExpression = visit(node.expression); 494 Instantiator makeExpression = visit(node.expression);
491 Instantiator makeBody = visit(node.body); 495 Instantiator makeBody = visit(node.body);
492 return (arguments) { 496 return (arguments) {
493 return new Case(makeExpression(arguments), makeBody(arguments)); 497 return new Case(makeExpression(arguments), makeBody(arguments));
494 }; 498 };
495 } 499 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 return new VariableDeclarationList(declarations); 534 return new VariableDeclarationList(declarations);
531 }; 535 };
532 } 536 }
533 537
534 Instantiator visitAssignment(Assignment node) { 538 Instantiator visitAssignment(Assignment node) {
535 Instantiator makeLeftHandSide = visit(node.leftHandSide); 539 Instantiator makeLeftHandSide = visit(node.leftHandSide);
536 String op = node.op; 540 String op = node.op;
537 Instantiator makeValue = visitNullable(node.value); 541 Instantiator makeValue = visitNullable(node.value);
538 return (arguments) { 542 return (arguments) {
539 return new Assignment.compound( 543 return new Assignment.compound(
540 makeLeftHandSide(arguments), 544 makeLeftHandSide(arguments), op, makeValue(arguments));
541 op,
542 makeValue(arguments));
543 }; 545 };
544 } 546 }
545 547
546 Instantiator visitVariableInitialization(VariableInitialization node) { 548 Instantiator visitVariableInitialization(VariableInitialization node) {
547 Instantiator makeDeclaration = visit(node.declaration); 549 Instantiator makeDeclaration = visit(node.declaration);
548 Instantiator makeValue = visitNullable(node.value); 550 Instantiator makeValue = visitNullable(node.value);
549 return (arguments) { 551 return (arguments) {
550 return new VariableInitialization( 552 return new VariableInitialization(
551 makeDeclaration(arguments), makeValue(arguments)); 553 makeDeclaration(arguments), makeValue(arguments));
552 }; 554 };
553 } 555 }
554 556
555 Instantiator visitConditional(Conditional cond) { 557 Instantiator visitConditional(Conditional cond) {
556 Instantiator makeCondition = visit(cond.condition); 558 Instantiator makeCondition = visit(cond.condition);
557 Instantiator makeThen = visit(cond.then); 559 Instantiator makeThen = visit(cond.then);
558 Instantiator makeOtherwise = visit(cond.otherwise); 560 Instantiator makeOtherwise = visit(cond.otherwise);
559 return (arguments) => new Conditional( 561 return (arguments) => new Conditional(makeCondition(arguments),
560 makeCondition(arguments), 562 makeThen(arguments), makeOtherwise(arguments));
561 makeThen(arguments),
562 makeOtherwise(arguments));
563 } 563 }
564 564
565 Instantiator visitNew(New node) => 565 Instantiator visitNew(New node) =>
566 handleCallOrNew(node, (target, arguments) => new New(target, arguments)); 566 handleCallOrNew(node, (target, arguments) => new New(target, arguments));
567 567
568 Instantiator visitCall(Call node) => 568 Instantiator visitCall(Call node) =>
569 handleCallOrNew(node, (target, arguments) => new Call(target, arguments)); 569 handleCallOrNew(node, (target, arguments) => new Call(target, arguments));
570 570
571 Instantiator handleCallOrNew(Call node, finish(target, arguments)) { 571 Instantiator handleCallOrNew(Call node, finish(target, arguments)) {
572 Instantiator makeTarget = visit(node.target); 572 Instantiator makeTarget = visit(node.target);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 } 651 }
652 Statement body = makeBody(arguments); 652 Statement body = makeBody(arguments);
653 return new Fun(params, body); 653 return new Fun(params, body);
654 }; 654 };
655 } 655 }
656 656
657 Instantiator visitDeferredExpression(DeferredExpression node) => same(node); 657 Instantiator visitDeferredExpression(DeferredExpression node) => same(node);
658 658
659 Instantiator visitDeferredNumber(DeferredNumber node) => same(node); 659 Instantiator visitDeferredNumber(DeferredNumber node) => same(node);
660 660
661 Instantiator visitDeferredString(DeferredString node) => 661 Instantiator visitDeferredString(DeferredString node) => (arguments) => node;
662 (arguments) => node;
663 662
664 Instantiator visitLiteralBool(LiteralBool node) => 663 Instantiator visitLiteralBool(LiteralBool node) =>
665 (arguments) => new LiteralBool(node.value); 664 (arguments) => new LiteralBool(node.value);
666 665
667 Instantiator visitLiteralString(LiteralString node) => 666 Instantiator visitLiteralString(LiteralString node) =>
668 (arguments) => new LiteralString(node.value); 667 (arguments) => new LiteralString(node.value);
669 668
670 Instantiator visitLiteralNumber(LiteralNumber node) => 669 Instantiator visitLiteralNumber(LiteralNumber node) =>
671 (arguments) => new LiteralNumber(node.value); 670 (arguments) => new LiteralNumber(node.value);
672 671
673 Instantiator visitLiteralNull(LiteralNull node) => 672 Instantiator visitLiteralNull(LiteralNull node) =>
674 (arguments) => new LiteralNull(); 673 (arguments) => new LiteralNull();
675 674
676 Instantiator visitStringConcatenation(StringConcatenation node) { 675 Instantiator visitStringConcatenation(StringConcatenation node) {
677 List<Instantiator> partMakers = node.parts 676 List<Instantiator> partMakers =
678 .map(visit) 677 node.parts.map(visit).toList(growable: false);
679 .toList(growable: false);
680 return (arguments) { 678 return (arguments) {
681 List<Literal> parts = partMakers 679 List<Literal> parts = partMakers
682 .map((Instantiator instantiator) => instantiator(arguments)) 680 .map((Instantiator instantiator) => instantiator(arguments))
683 .toList(growable: false); 681 .toList(growable: false);
684 return new StringConcatenation(parts); 682 return new StringConcatenation(parts);
685 }; 683 };
686 } 684 }
687 685
688 Instantiator visitName(Name node) => same(node); 686 Instantiator visitName(Name node) => same(node);
689 687
690 Instantiator visitArrayInitializer(ArrayInitializer node) { 688 Instantiator visitArrayInitializer(ArrayInitializer node) {
691 // TODO(sra): Implement splicing? 689 // TODO(sra): Implement splicing?
692 List<Instantiator> elementMakers = node.elements 690 List<Instantiator> elementMakers =
693 .map(visit) 691 node.elements.map(visit).toList(growable: false);
694 .toList(growable: false);
695 return (arguments) { 692 return (arguments) {
696 List<Expression> elements = elementMakers 693 List<Expression> elements = elementMakers
697 .map((Instantiator instantiator) => instantiator(arguments)) 694 .map((Instantiator instantiator) => instantiator(arguments))
698 .toList(growable: false); 695 .toList(growable: false);
699 return new ArrayInitializer(elements); 696 return new ArrayInitializer(elements);
700 }; 697 };
701 } 698 }
702 699
703 Instantiator visitArrayHole(ArrayHole node) { 700 Instantiator visitArrayHole(ArrayHole node) {
704 return (arguments) => new ArrayHole(); 701 return (arguments) => new ArrayHole();
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 node.visitChildren(this); 763 node.visitChildren(this);
767 if (count != before) containsInterpolatedNode.add(node); 764 if (count != before) containsInterpolatedNode.add(node);
768 } 765 }
769 766
770 visitInterpolatedNode(InterpolatedNode node) { 767 visitInterpolatedNode(InterpolatedNode node) {
771 containsInterpolatedNode.add(node); 768 containsInterpolatedNode.add(node);
772 if (node.isNamed) holeNames.add(node.nameOrPosition); 769 if (node.isNamed) holeNames.add(node.nameOrPosition);
773 ++count; 770 ++count;
774 } 771 }
775 } 772 }
OLDNEW
« no previous file with comments | « pkg/js_ast/lib/src/printer.dart ('k') | pkg/js_ast/test/printer_callback_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698