Mercurial > hg > graal-compiler
diff graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/NodeCodeGenerator.java @ 11180:a9cb98ff8fd9
Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 29 Jul 2013 16:50:10 +0200 |
parents | 7a0ba9b20fec |
children | 5daaa0821406 |
line wrap: on
line diff
--- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/NodeCodeGenerator.java Mon Jul 29 12:11:59 2013 +0200 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/NodeCodeGenerator.java Mon Jul 29 16:50:10 2013 +0200 @@ -623,12 +623,22 @@ return false; } VariableElement var = element.getParameters().get(0); - TypeElement type = Utils.findNearestEnclosingType(var); - - if (!Utils.typeEquals(var.asType(), type.asType())) { - return false; + TypeElement enclosingType = Utils.findNearestEnclosingType(var); + if (Utils.typeEquals(var.asType(), enclosingType.asType())) { + return true; } - return true; + List<TypeElement> types = Utils.getDirectSuperTypes(enclosingType); + for (TypeElement type : types) { + if (!(type instanceof CodeTypeElement)) { + // no copy constructors which are not generated types + return false; + } + + if (Utils.typeEquals(var.asType(), type.asType())) { + return true; + } + } + return false; } @Override @@ -686,7 +696,7 @@ createFactoryMethods(node, clazz, createVisibility); - if (node.getPolymorphicDepth() > 1) { + if (node.isPolymorphic()) { PolymorphicNodeFactory generic = new PolymorphicNodeFactory(getContext(), generatedNode, true); add(generic, node.getGenericPolymorphicSpecialization()); @@ -1079,7 +1089,7 @@ if (node.needsRewrites(context)) { - if (node.getPolymorphicDepth() > 1) { + if (node.isPolymorphic()) { CodeVariableElement var = new CodeVariableElement(modifiers(PROTECTED), clazz.asType(), "next0"); var.getAnnotationMirrors().add(new CodeAnnotationMirror(getContext().getTruffleTypes().getChildAnnotation())); @@ -1359,9 +1369,7 @@ private CodeExecutableElement createCopyConstructor(CodeTypeElement type, ExecutableElement superConstructor) { CodeExecutableElement method = new CodeExecutableElement(null, type.getSimpleName().toString()); CodeTreeBuilder builder = method.createBuilder(); - if (!(superConstructor == null && type.getFields().isEmpty())) { - method.getParameters().add(new CodeVariableElement(type.asType(), "copy")); - } + method.getParameters().add(new CodeVariableElement(type.asType(), "copy")); if (superConstructor != null) { builder.startStatement().startSuperCall().string("copy").end().end(); @@ -1398,7 +1406,7 @@ } builder.end(); } - if (getModel().getNode().getPolymorphicDepth() > 1) { + if (getModel().getNode().isPolymorphic()) { builder.statement("this.next0 = adoptChild(copy.next0)"); } @@ -1554,7 +1562,7 @@ builder.startIf().string("allowed").end().startBlock(); } - if (!current.isGeneric() || node.getPolymorphicDepth() <= 1) { + if (!current.isGeneric() || !node.isPolymorphic()) { // generic rewrite builder.tree(createRewriteGeneric(builder, current)); } else { @@ -2175,7 +2183,7 @@ NodeData node = specialization.getNode(); - if (node.needsRewrites(getContext()) && node.getPolymorphicDepth() > 1) { + if (node.needsRewrites(getContext()) && node.isPolymorphic()) { createIsCompatible(clazz, specialization); } @@ -2185,15 +2193,25 @@ protected void createConstructors(CodeTypeElement clazz) { TypeElement superTypeElement = Utils.fromTypeMirror(clazz.getSuperclass()); + SpecializationData specialization = getModel(); + NodeData node = specialization.getNode(); for (ExecutableElement constructor : ElementFilter.constructorsIn(superTypeElement.getEnclosedElements())) { - if (getModel().getNode().getUninitializedSpecialization() != null && !getModel().isUninitialized() && - (constructor.getParameters().size() != 1 || constructor.getParameters().get(0).getSimpleName().toString().equals(baseClassName(getModel().getNode())))) { - continue; + if (specialization.isUninitialized()) { + // ignore copy constructors for uninitialized if not polymorphic + if (isCopyConstructor(constructor) && !node.isPolymorphic()) { + continue; + } + } else if (node.getUninitializedSpecialization() != null) { + // ignore others than copy constructors for specialized nodes + if (!isCopyConstructor(constructor)) { + continue; + } } CodeExecutableElement superConstructor = createSuperConstructor(clazz, constructor); + if (superConstructor != null) { - if (getModel().isGeneric() && getModel().getNode().getPolymorphicDepth() > 1) { + if (getModel().isGeneric() && node.isPolymorphic()) { CodeTree body = superConstructor.getBodyTree(); CodeTreeBuilder builder = superConstructor.createBuilder(); builder.tree(body);