comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/NodeCodeGenerator.java @ 15477:fd18fa50a8e0

TruffleDSL: NodeCodeGenerator: avoid referencing BaseNode class in factory
author Andreas Woess <andreas.woess@jku.at>
date Fri, 02 May 2014 15:49:46 +0200
parents 97ee50d15882
children 4f397be8f424
comparison
equal deleted inserted replaced
15476:97ee50d15882 15477:fd18fa50a8e0
865 } 865 }
866 866
867 if (found == null) { 867 if (found == null) {
868 body.startThrow().startNew(getContext().getType(UnsupportedOperationException.class)).end().end(); 868 body.startThrow().startNew(getContext().getType(UnsupportedOperationException.class)).end().end();
869 } else { 869 } else {
870 body.startReturn().startCall(nodeSpecializationClassName(found), CREATE_SPECIALIZATION_NAME).startGroup().cast(baseClassName(node)).string(THIS_NODE_LOCAL_VAR_NAME).end().end().end(); 870 body.startReturn().startCall(nodeSpecializationClassName(found), CREATE_SPECIALIZATION_NAME).startGroup().string(THIS_NODE_LOCAL_VAR_NAME).end().end().end();
871 } 871 }
872 return method; 872 return method;
873 } 873 }
874 } 874 }
875 875
1737 if (target != null) { 1737 if (target != null) {
1738 replaceCall.startCall(target, "replace"); 1738 replaceCall.startCall(target, "replace");
1739 } else { 1739 } else {
1740 replaceCall.startCall("replace"); 1740 replaceCall.startCall("replace");
1741 } 1741 }
1742 replaceCall.startGroup().startCall(className, CREATE_SPECIALIZATION_NAME).string(source); 1742 replaceCall.startGroup().cast(baseClassName(current.getNode())).startCall(className, CREATE_SPECIALIZATION_NAME).string(source);
1743 for (ActualParameter param : current.getSignatureParameters()) { 1743 for (ActualParameter param : current.getSignatureParameters()) {
1744 NodeChildData child = param.getSpecification().getExecution().getChild(); 1744 NodeChildData child = param.getSpecification().getExecution().getChild();
1745 List<TypeData> types = child.getNodeData().getTypeSystem().lookupSourceTypes(param.getTypeSystemType()); 1745 List<TypeData> types = child.getNodeData().getTypeSystem().lookupSourceTypes(param.getTypeSystemType());
1746 if (types.size() > 1) { 1746 if (types.size() > 1) {
1747 replaceCall.string(implicitTypeName(param)); 1747 replaceCall.string(implicitTypeName(param));
2554 for (ExecutableElement constructor : ElementFilter.constructorsIn(clazz.getEnclosedElements())) { 2554 for (ExecutableElement constructor : ElementFilter.constructorsIn(clazz.getEnclosedElements())) {
2555 if (constructor.getParameters().size() == 1 && ((CodeVariableElement) constructor.getParameters().get(0)).getType().equals(nodeGen.asType())) { 2555 if (constructor.getParameters().size() == 1 && ((CodeVariableElement) constructor.getParameters().get(0)).getType().equals(nodeGen.asType())) {
2556 // skip copy constructor - not used 2556 // skip copy constructor - not used
2557 continue; 2557 continue;
2558 } 2558 }
2559 clazz.add(createConstructorFactoryMethod(nodeGen.asType(), specialization, constructor)); 2559 clazz.add(createConstructorFactoryMethod(specialization, constructor));
2560 } 2560 }
2561 } 2561 }
2562 } 2562 }
2563 2563
2564 protected void createConstructors(CodeTypeElement clazz) { 2564 protected void createConstructors(CodeTypeElement clazz) {
2927 protected CodeExecutableElement createCopyConstructorFactoryMethod(TypeMirror baseType, SpecializationData specialization) { 2927 protected CodeExecutableElement createCopyConstructorFactoryMethod(TypeMirror baseType, SpecializationData specialization) {
2928 List<ActualParameter> implicitTypeParams = getImplicitTypeParameters(specialization); 2928 List<ActualParameter> implicitTypeParams = getImplicitTypeParameters(specialization);
2929 CodeVariableElement[] parameters = new CodeVariableElement[implicitTypeParams.size() + 1]; 2929 CodeVariableElement[] parameters = new CodeVariableElement[implicitTypeParams.size() + 1];
2930 int i = 0; 2930 int i = 0;
2931 String baseName = "current"; 2931 String baseName = "current";
2932 parameters[i++] = new CodeVariableElement(baseType, baseName); 2932 parameters[i++] = new CodeVariableElement(specialization.getNode().getNodeType(), baseName);
2933 for (ActualParameter implicitTypeParam : implicitTypeParams) { 2933 for (ActualParameter implicitTypeParam : implicitTypeParams) {
2934 parameters[i++] = new CodeVariableElement(getContext().getType(Class.class), implicitTypeName(implicitTypeParam)); 2934 parameters[i++] = new CodeVariableElement(getContext().getType(Class.class), implicitTypeName(implicitTypeParam));
2935 } 2935 }
2936 CodeExecutableElement method = new CodeExecutableElement(modifiers(STATIC), baseType, CREATE_SPECIALIZATION_NAME, parameters); 2936 CodeExecutableElement method = new CodeExecutableElement(modifiers(STATIC), specialization.getNode().getNodeType(), CREATE_SPECIALIZATION_NAME, parameters);
2937 assert specialization != null; 2937 assert specialization != null;
2938 CodeTreeBuilder builder = method.createBuilder(); 2938 CodeTreeBuilder builder = method.createBuilder();
2939 builder.startReturn(); 2939 builder.startReturn();
2940 builder.startNew(getElement().asType()); 2940 builder.startNew(getElement().asType());
2941 builder.string(baseName); 2941 builder.startGroup().cast(baseType, CodeTreeBuilder.singleString(baseName)).end();
2942 for (ActualParameter param : implicitTypeParams) { 2942 for (ActualParameter param : implicitTypeParams) {
2943 builder.string(implicitTypeName(param)); 2943 builder.string(implicitTypeName(param));
2944 } 2944 }
2945 builder.end().end(); 2945 builder.end().end();
2946 return method; 2946 return method;
2947 } 2947 }
2948 2948
2949 protected CodeExecutableElement createConstructorFactoryMethod(TypeMirror baseType, SpecializationData specialization, ExecutableElement constructor) { 2949 protected CodeExecutableElement createConstructorFactoryMethod(SpecializationData specialization, ExecutableElement constructor) {
2950 List<? extends VariableElement> parameters = constructor.getParameters(); 2950 List<? extends VariableElement> parameters = constructor.getParameters();
2951 CodeExecutableElement method = new CodeExecutableElement(modifiers(STATIC), baseType, CREATE_SPECIALIZATION_NAME, parameters.toArray(new CodeVariableElement[parameters.size()])); 2951 CodeExecutableElement method = new CodeExecutableElement(modifiers(STATIC), specialization.getNode().getNodeType(), CREATE_SPECIALIZATION_NAME,
2952 parameters.toArray(new CodeVariableElement[parameters.size()]));
2952 assert specialization != null; 2953 assert specialization != null;
2953 CodeTreeBuilder builder = method.createBuilder(); 2954 CodeTreeBuilder builder = method.createBuilder();
2954 builder.startReturn(); 2955 builder.startReturn();
2955 builder.startNew(getElement().asType()); 2956 builder.startNew(getElement().asType());
2956 for (VariableElement param : parameters) { 2957 for (VariableElement param : parameters) {