Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/ast/CodeTreeBuilder.java @ 10596:f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 01 Jul 2013 20:32:20 +0200 |
parents | 00b70a864d3b |
children |
comparison
equal
deleted
inserted
replaced
10595:47233c73ca58 | 10596:f43eb2f1bbbc |
---|---|
73 | 73 |
74 public static CodeTree singleString(String s) { | 74 public static CodeTree singleString(String s) { |
75 return new CodeTreeBuilder(null).string(s).getTree(); | 75 return new CodeTreeBuilder(null).string(s).getTree(); |
76 } | 76 } |
77 | 77 |
78 public static CodeTree singleType(TypeMirror s) { | |
79 return new CodeTreeBuilder(null).type(s).getTree(); | |
80 } | |
81 | |
78 private CodeTreeBuilder push(CodeTreeKind kind) { | 82 private CodeTreeBuilder push(CodeTreeKind kind) { |
79 return push(new BuilderCodeTree(kind, null, null)); | 83 return push(new BuilderCodeTree(kind, null, null)); |
80 } | 84 } |
81 | 85 |
82 private CodeTreeBuilder push(String string) { | 86 private CodeTreeBuilder push(String string) { |
468 string(" = "); | 472 string(" = "); |
469 defaultValue(type); | 473 defaultValue(type); |
470 end(); // statement | 474 end(); // statement |
471 } | 475 } |
472 return this; | 476 return this; |
477 } | |
478 | |
479 public CodeTreeBuilder declaration(TypeMirror type, String name, String init) { | |
480 return declaration(type, name, singleString(init)); | |
473 } | 481 } |
474 | 482 |
475 public CodeTreeBuilder declaration(TypeMirror type, String name, CodeTree init) { | 483 public CodeTreeBuilder declaration(TypeMirror type, String name, CodeTree init) { |
476 if (Utils.isVoid(type)) { | 484 if (Utils.isVoid(type)) { |
477 startStatement(); | 485 startStatement(); |
535 | 543 |
536 public CodeTree getRoot() { | 544 public CodeTree getRoot() { |
537 return root; | 545 return root; |
538 } | 546 } |
539 | 547 |
548 public CodeTreeBuilder cast(String baseClassName) { | |
549 string("(").string(baseClassName).string(") "); | |
550 return this; | |
551 } | |
552 | |
540 public CodeTreeBuilder cast(TypeMirror type, CodeTree content) { | 553 public CodeTreeBuilder cast(TypeMirror type, CodeTree content) { |
541 if (Utils.isVoid(type)) { | 554 if (Utils.isVoid(type)) { |
542 tree(content); | 555 tree(content); |
543 return this; | 556 return this; |
544 } else if (type.getKind() == TypeKind.DECLARED && Utils.getQualifiedName(type).equals("java.lang.Object")) { | 557 } else if (type.getKind() == TypeKind.DECLARED && Utils.getQualifiedName(type).equals("java.lang.Object")) { |
575 | 588 |
576 public CodeTreeBuilder returnTrue() { | 589 public CodeTreeBuilder returnTrue() { |
577 return startReturn().string("true").end(); | 590 return startReturn().string("true").end(); |
578 } | 591 } |
579 | 592 |
593 public CodeTreeBuilder instanceOf(CodeTree var, CodeTree type) { | |
594 tree(var).string(" instanceof ").tree(type); | |
595 return this; | |
596 } | |
597 | |
598 public CodeTreeBuilder instanceOf(String var, String type) { | |
599 return instanceOf(singleString(var), singleString(type)); | |
600 } | |
601 | |
580 public CodeTreeBuilder instanceOf(String var, TypeMirror type) { | 602 public CodeTreeBuilder instanceOf(String var, TypeMirror type) { |
581 string(var); | |
582 TypeElement element = Utils.fromTypeMirror(type); | 603 TypeElement element = Utils.fromTypeMirror(type); |
583 if (element == null) { | 604 if (element == null) { |
584 throw new IllegalArgumentException("Cannot call instanceof for a non supported type: " + type.getKind()); | 605 throw new IllegalArgumentException("Cannot call instanceof for a non supported type: " + type.getKind()); |
585 } | 606 } |
586 | 607 return instanceOf(singleString(var), singleType(type)); |
587 string(" instanceof ").type(type); | |
588 return this; | |
589 } | 608 } |
590 | 609 |
591 public CodeTreeBuilder defaultValue(TypeMirror mirror) { | 610 public CodeTreeBuilder defaultValue(TypeMirror mirror) { |
592 switch (mirror.getKind()) { | 611 switch (mirror.getKind()) { |
593 case VOID: | 612 case VOID: |