Mercurial > hg > graal-compiler
diff graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/codewriter/AbstractCodeWriter.java @ 9220:97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Sat, 20 Apr 2013 12:16:22 +0200 |
parents | 10d37f893471 |
children |
line wrap: on
line diff
--- a/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/codewriter/AbstractCodeWriter.java Tue Apr 16 11:03:40 2013 +0200 +++ b/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/codewriter/AbstractCodeWriter.java Sat Apr 20 12:16:22 2013 +0200 @@ -123,9 +123,9 @@ writeClassImpl(e); } - private String useImport(TypeMirror type) { + private String useImport(Element enclosedType, TypeMirror type) { if (imports != null) { - return imports.useImport(type); + return imports.createTypeReference(enclosedType, type); } else { return Utils.getSimpleName(type); } @@ -133,7 +133,7 @@ private void writeClassImpl(CodeTypeElement e) { for (AnnotationMirror annotation : e.getAnnotationMirrors()) { - visitAnnotation(annotation); + visitAnnotation(e, annotation); writeLn(); } @@ -145,12 +145,12 @@ } write(e.getSimpleName()); if (e.getSuperclass() != null && !getQualifiedName(e.getSuperclass()).equals("java.lang.Object")) { - write(" extends ").write(useImport(e.getSuperclass())); + write(" extends ").write(useImport(e, e.getSuperclass())); } if (e.getImplements().size() > 0) { write(" implements "); for (int i = 0; i < e.getImplements().size(); i++) { - write(useImport(e.getImplements().get(i))); + write(useImport(e, e.getImplements().get(i))); if (i < e.getImplements().size() - 1) { write(", "); } @@ -255,8 +255,8 @@ Element parent = f.getEnclosingElement(); for (AnnotationMirror annotation : f.getAnnotationMirrors()) { - visitAnnotation(annotation); - writeLn(); + visitAnnotation(f, annotation); + write(" "); } CodeTree init = null; @@ -275,7 +275,7 @@ } } else { writeModifiers(f.getModifiers()); - write(useImport(f.asType())); + write(useImport(f, f.asType())); if (f.getEnclosingElement().getKind() == ElementKind.METHOD) { ExecutableElement method = (ExecutableElement) f.getEnclosingElement(); @@ -294,8 +294,8 @@ return null; } - public void visitAnnotation(AnnotationMirror e) { - write("@").write(useImport(e.getAnnotationType())); + public void visitAnnotation(Element enclosedElement, AnnotationMirror e) { + write("@").write(useImport(enclosedElement, e.getAnnotationType())); if (!e.getElementValues().isEmpty()) { write("("); @@ -303,7 +303,7 @@ Map<? extends ExecutableElement, ? extends AnnotationValue> values = e.getElementValues(); if (defaultElement != null && values.size() == 1 && values.get(defaultElement) != null) { - visitAnnotationValue(values.get(defaultElement)); + visitAnnotationValue(enclosedElement, values.get(defaultElement)); } else { Set<? extends ExecutableElement> methodsSet = values.keySet(); List<ExecutableElement> methodsList = new ArrayList<>(); @@ -327,7 +327,7 @@ AnnotationValue value = values.get(method); write(method.getSimpleName().toString()); write(" = "); - visitAnnotationValue(value); + visitAnnotationValue(enclosedElement, value); if (i < methodsList.size() - 1) { write(", "); @@ -339,12 +339,18 @@ } } - public void visitAnnotationValue(AnnotationValue e) { - e.accept(new AnnotationValueWriterVisitor(), null); + public void visitAnnotationValue(Element enclosedElement, AnnotationValue e) { + e.accept(new AnnotationValueWriterVisitor(enclosedElement), null); } private class AnnotationValueWriterVisitor extends AbstractAnnotationValueVisitor7<Void, Void> { + private final Element enclosedElement; + + public AnnotationValueWriterVisitor(Element enclosedElement) { + this.enclosedElement = enclosedElement; + } + @Override public Void visitBoolean(boolean b, Void p) { write(Boolean.toString(b)); @@ -403,14 +409,14 @@ @Override public Void visitType(TypeMirror t, Void p) { - write(useImport(t)); + write(useImport(enclosedElement, t)); write(".class"); return null; } @Override public Void visitEnumConstant(VariableElement c, Void p) { - write(useImport(c.asType())); + write(useImport(enclosedElement, c.asType())); write("."); write(c.getSimpleName().toString()); return null; @@ -418,7 +424,7 @@ @Override public Void visitAnnotation(AnnotationMirror a, Void p) { - AbstractCodeWriter.this.visitAnnotation(a); + AbstractCodeWriter.this.visitAnnotation(enclosedElement, a); return null; } @@ -427,7 +433,7 @@ write("{"); for (int i = 0; i < vals.size(); i++) { AnnotationValue value = vals.get(i); - AbstractCodeWriter.this.visitAnnotationValue(value); + AbstractCodeWriter.this.visitAnnotationValue(enclosedElement, value); if (i < vals.size() - 1) { write(", "); } @@ -459,14 +465,14 @@ @Override public Void visitExecutable(CodeExecutableElement e, Void p) { for (AnnotationMirror annotation : e.getAnnotationMirrors()) { - visitAnnotation(annotation); + visitAnnotation(e, annotation); writeLn(); } writeModifiers(e.getModifiers()); if (e.getReturnType() != null) { - write(useImport(e.getReturnType())); + write(useImport(e, e.getReturnType())); write(" "); } write(e.getSimpleName()); @@ -485,7 +491,7 @@ if (throwables.size() > 0) { write(" throws "); for (int i = 0; i < throwables.size(); i++) { - write(useImport(throwables.get(i))); + write(useImport(e, throwables.get(i))); if (i < throwables.size() - 1) { write(", "); } @@ -549,20 +555,20 @@ break; case STATIC_FIELD_REFERENCE: if (e.getString() != null) { - write(imports.useStaticFieldImport(e.getType(), e.getString())); + write(imports.createStaticFieldReference(e, e.getType(), e.getString())); } else { write("null"); } break; case STATIC_METHOD_REFERENCE: if (e.getString() != null) { - write(imports.useStaticMethodImport(e.getType(), e.getString())); + write(imports.createStaticMethodReference(e, e.getType(), e.getString())); } else { write("null"); } break; case TYPE: - write(useImport(e.getType())); + write(useImport(e, e.getType())); break; default: assert false;