Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/java/transform/AbstractCodeWriter.java @ 16909:62cfffca9be2
Truffle-DSL: some more performance optimizations.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Sat, 23 Aug 2014 19:31:18 +0200 |
parents | 23415229349b |
children | c88ab4f1f04a |
comparison
equal
deleted
inserted
replaced
16908:d3f282a9e287 | 16909:62cfffca9be2 |
---|---|
260 | 260 |
261 if (parent.getKind() == ElementKind.ENUM && f.getModifiers().contains(Modifier.STATIC)) { | 261 if (parent.getKind() == ElementKind.ENUM && f.getModifiers().contains(Modifier.STATIC)) { |
262 write(f.getSimpleName()); | 262 write(f.getSimpleName()); |
263 if (init != null) { | 263 if (init != null) { |
264 write("("); | 264 write("("); |
265 init.acceptCodeElementScanner(this, p); | 265 visitTree(init, p, f); |
266 write(")"); | 266 write(")"); |
267 } | 267 } |
268 } else { | 268 } else { |
269 Element enclosing = f.getEnclosingElement(); | 269 Element enclosing = f.getEnclosingElement(); |
270 writeModifiers(f.getModifiers()); | 270 writeModifiers(f.getModifiers()); |
290 | 290 |
291 write(" "); | 291 write(" "); |
292 write(f.getSimpleName()); | 292 write(f.getSimpleName()); |
293 if (init != null) { | 293 if (init != null) { |
294 write(" = "); | 294 write(" = "); |
295 init.acceptCodeElementScanner(this, p); | 295 visitTree(init, p, f); |
296 } | 296 } |
297 } | 297 } |
298 return null; | 298 return null; |
299 } | 299 } |
300 | 300 |
457 return null; | 457 return null; |
458 } | 458 } |
459 | 459 |
460 @Override | 460 @Override |
461 public void visitImport(CodeImport e, Void p) { | 461 public void visitImport(CodeImport e, Void p) { |
462 write("import "); | |
462 if (e.isStaticImport()) { | 463 if (e.isStaticImport()) { |
463 write("import static ").write(e.getImportString()).write(";"); | 464 write("static "); |
464 } else { | 465 } |
465 write("import ").write(e.getImportString()).write(";"); | 466 write(e.getPackageName()); |
466 } | 467 write("."); |
468 write(e.getSymbolName()); | |
469 write(";"); | |
467 } | 470 } |
468 | 471 |
469 @Override | 472 @Override |
470 public Void visitExecutable(CodeExecutableElement e, Void p) { | 473 public Void visitExecutable(CodeExecutableElement e, Void p) { |
471 for (AnnotationMirror annotation : e.getAnnotationMirrors()) { | 474 for (AnnotationMirror annotation : e.getAnnotationMirrors()) { |
505 if (e.getModifiers().contains(Modifier.ABSTRACT)) { | 508 if (e.getModifiers().contains(Modifier.ABSTRACT)) { |
506 writeLn(";"); | 509 writeLn(";"); |
507 } else if (e.getBodyTree() != null) { | 510 } else if (e.getBodyTree() != null) { |
508 writeLn(" {"); | 511 writeLn(" {"); |
509 indent(1); | 512 indent(1); |
510 e.getBodyTree().acceptCodeElementScanner(this, p); | 513 visitTree(e.getBodyTree(), p, e); |
511 dedent(1); | 514 dedent(1); |
512 writeLn("}"); | 515 writeLn("}"); |
513 } else if (e.getBody() != null) { | 516 } else if (e.getBody() != null) { |
514 write(" {"); | 517 write(" {"); |
515 write(e.getBody()); | 518 write(e.getBody()); |
520 writeEmptyLn(); | 523 writeEmptyLn(); |
521 return null; | 524 return null; |
522 } | 525 } |
523 | 526 |
524 @Override | 527 @Override |
525 public void visitTree(CodeTree e, Void p) { | 528 public void visitTree(CodeTree e, Void p, Element enclosingElement) { |
526 CodeTreeKind kind = e.getCodeKind(); | 529 CodeTreeKind kind = e.getCodeKind(); |
527 | 530 |
528 switch (kind) { | 531 switch (kind) { |
529 case COMMA_GROUP: | 532 case COMMA_GROUP: |
530 List<CodeTree> children = e.getEnclosedElements(); | 533 List<CodeTree> children = e.getEnclosedElements(); |
531 for (int i = 0; i < children.size(); i++) { | 534 if (children != null) { |
532 children.get(i).acceptCodeElementScanner(this, p); | 535 for (int i = 0; i < children.size(); i++) { |
533 if (i < e.getEnclosedElements().size() - 1) { | 536 visitTree(children.get(i), p, enclosingElement); |
534 write(", "); | 537 if (i < e.getEnclosedElements().size() - 1) { |
538 write(", "); | |
539 } | |
535 } | 540 } |
536 } | 541 } |
537 break; | 542 break; |
538 case GROUP: | 543 case GROUP: |
539 for (CodeTree tree : e.getEnclosedElements()) { | 544 super.visitTree(e, p, enclosingElement); |
540 tree.acceptCodeElementScanner(this, p); | |
541 } | |
542 break; | 545 break; |
543 case INDENT: | 546 case INDENT: |
544 indent(1); | 547 indent(1); |
545 for (CodeTree tree : e.getEnclosedElements()) { | 548 super.visitTree(e, p, enclosingElement); |
546 tree.acceptCodeElementScanner(this, p); | |
547 } | |
548 dedent(1); | 549 dedent(1); |
549 break; | 550 break; |
550 case NEW_LINE: | 551 case NEW_LINE: |
551 writeLn(); | 552 writeLn(); |
552 break; | 553 break; |
557 write("null"); | 558 write("null"); |
558 } | 559 } |
559 break; | 560 break; |
560 case STATIC_FIELD_REFERENCE: | 561 case STATIC_FIELD_REFERENCE: |
561 if (e.getString() != null) { | 562 if (e.getString() != null) { |
562 write(imports.createStaticFieldReference(e, e.getType(), e.getString())); | 563 write(imports.createStaticFieldReference(enclosingElement, e.getType(), e.getString())); |
563 } else { | 564 } else { |
564 write("null"); | 565 write("null"); |
565 } | 566 } |
566 break; | 567 break; |
567 case STATIC_METHOD_REFERENCE: | 568 case STATIC_METHOD_REFERENCE: |
568 if (e.getString() != null) { | 569 if (e.getString() != null) { |
569 write(imports.createStaticMethodReference(e, e.getType(), e.getString())); | 570 write(imports.createStaticMethodReference(enclosingElement, e.getType(), e.getString())); |
570 } else { | 571 } else { |
571 write("null"); | 572 write("null"); |
572 } | 573 } |
573 break; | 574 break; |
574 case TYPE: | 575 case TYPE: |
575 write(useImport(e, e.getType())); | 576 write(useImport(enclosingElement, e.getType())); |
576 break; | 577 break; |
577 default: | 578 default: |
578 assert false; | 579 assert false; |
579 return; | 580 return; |
580 } | 581 } |
674 | 675 |
675 int end = Math.min(i + nextSize, string.length()); | 676 int end = Math.min(i + nextSize, string.length()); |
676 | 677 |
677 // TODO(CH): fails in normal usage - output ok though | 678 // TODO(CH): fails in normal usage - output ok though |
678 // assert lineLength + (end - i) + 2 < MAX_LINE_LENGTH; | 679 // assert lineLength + (end - i) + 2 < MAX_LINE_LENGTH; |
679 | 680 write("\""); |
680 write("\"" + string.substring(i, end) + "\""); | 681 write(string.substring(i, end)); |
682 write("\""); | |
681 size = nextSize; | 683 size = nextSize; |
682 } | 684 } |
683 | 685 |
684 return ""; | 686 return ""; |
685 } else if (!Character.isAlphabetic(firstCharacter) && firstCharacter != '+') { | 687 } else if (!Character.isAlphabetic(firstCharacter) && firstCharacter != '+') { |