Mercurial > hg > graal-compiler
diff graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/NodeData.java @ 20938:18c0f02fa4d2
Truffle-DSL: make type systems optional.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Tue, 14 Apr 2015 15:12:48 +0200 |
parents | f4792a544170 |
children | 476374f3fe9a |
line wrap: on
line diff
--- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/NodeData.java Tue Apr 14 22:12:03 2015 +0200 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/NodeData.java Tue Apr 14 15:12:48 2015 +0200 @@ -63,7 +63,7 @@ this.fields = new ArrayList<>(); this.children = new ArrayList<>(); this.childExecutions = new ArrayList<>(); - this.thisExecution = new NodeExecutionData(new NodeChildData(null, null, "this", getNodeType(), getNodeType(), null, Cardinality.ONE), -1, false); + this.thisExecution = new NodeExecutionData(new NodeChildData(null, null, "this", getNodeType(), getNodeType(), null, Cardinality.ONE), -1, -1, false); this.thisExecution.getChild().setNode(this); this.generateFactory = generateFactory; } @@ -105,15 +105,15 @@ return childExecutions; } - public Set<TypeData> findSpecializedTypes(NodeExecutionData execution) { - Set<TypeData> types = new HashSet<>(); + public Set<TypeMirror> findSpecializedTypes(NodeExecutionData execution) { + Set<TypeMirror> types = new HashSet<>(); for (SpecializationData specialization : getSpecializations()) { if (!specialization.isSpecialized()) { continue; } List<Parameter> parameters = specialization.findByExecutionData(execution); for (Parameter parameter : parameters) { - TypeData type = parameter.getTypeSystemType(); + TypeMirror type = parameter.getType(); if (type == null) { throw new AssertionError(); } @@ -123,13 +123,13 @@ return types; } - public Collection<TypeData> findSpecializedReturnTypes() { - Set<TypeData> types = new HashSet<>(); + public Collection<TypeMirror> findSpecializedReturnTypes() { + Set<TypeMirror> types = new HashSet<>(); for (SpecializationData specialization : getSpecializations()) { if (!specialization.isSpecialized()) { continue; } - types.add(specialization.getReturnType().getTypeSystemType()); + types.add(specialization.getReturnType().getType()); } return types; } @@ -233,7 +233,7 @@ public boolean supportsFrame() { if (executableTypes != null) { for (ExecutableTypeData execType : getExecutableTypes(-1)) { - if (execType.findParameter(TemplateMethod.FRAME_NAME) == null) { + if (execType.getFrameParameter() == null) { return false; } } @@ -258,7 +258,7 @@ } for (NodeExecutionData execution : childExecutions) { - if (execution.getName().equals(childName) && (execution.getIndex() == -1 || execution.getIndex() == index)) { + if (execution.getName().equals(childName) && (execution.getChildIndex() == -1 || execution.getChildIndex() == index)) { return execution; } } @@ -284,17 +284,25 @@ return enclosingNodes; } - public List<TemplateMethod> getAllTemplateMethods() { - List<TemplateMethod> methods = new ArrayList<>(); + public List<ExecutableElement> getAllTemplateMethods() { + List<ExecutableElement> methods = new ArrayList<>(); for (SpecializationData specialization : getSpecializations()) { - methods.add(specialization); + methods.add(specialization.getMethod()); + } + + for (ExecutableTypeData execType : getExecutableTypes()) { + methods.add(execType.getMethod()); } - methods.addAll(getExecutableTypes()); - methods.addAll(getShortCircuits()); + for (ShortCircuitData shortcircuit : getShortCircuits()) { + methods.add(shortcircuit.getMethod()); + } + if (getCasts() != null) { - methods.addAll(getCasts()); + for (CreateCastData castData : getCasts()) { + methods.add(castData.getMethod()); + } } return methods; @@ -303,13 +311,13 @@ public ExecutableTypeData findAnyGenericExecutableType(ProcessorContext context, int evaluatedCount) { List<ExecutableTypeData> types = findGenericExecutableTypes(context, evaluatedCount); for (ExecutableTypeData type : types) { - if (type.getType().isGeneric()) { + if (context.isType(type.getReturnType(), Object.class)) { return type; } } for (ExecutableTypeData type : types) { - if (!type.getType().isVoid()) { + if (!context.isType(type.getReturnType(), void.class)) { return type; } } @@ -349,9 +357,9 @@ return types; } - public ExecutableTypeData findExecutableType(TypeData prmitiveType, int evaluatedCount) { + public ExecutableTypeData findExecutableType(TypeMirror primitiveType, int evaluatedCount) { for (ExecutableTypeData type : getExecutableTypes(evaluatedCount)) { - if (ElementUtils.typeEquals(type.getType().getPrimitiveType(), prmitiveType.getPrimitiveType())) { + if (ElementUtils.typeEquals(type.getReturnType(), primitiveType)) { return type; } } @@ -496,6 +504,14 @@ return shortCircuits; } + public int getMinimalEvaluatedParameters() { + int minimalEvaluatedParameters = Integer.MAX_VALUE; + for (ExecutableTypeData type : getExecutableTypes()) { + minimalEvaluatedParameters = Math.min(minimalEvaluatedParameters, type.getEvaluatedCount()); + } + return minimalEvaluatedParameters; + } + public void setExecutableTypes(Map<Integer, List<ExecutableTypeData>> executableTypes) { this.executableTypes = executableTypes; } @@ -520,4 +536,29 @@ return getNodeId().compareTo(o.getNodeId()); } + public List<TypeMirror> getPossibleTypes(NodeExecutionData execution) { + List<TypeMirror> types = new ArrayList<>(); + + // add types possible through return types and evaluated parameters in execute methods + if (execution.getChild() != null) { + for (ExecutableTypeData executable : execution.getChild().getNodeData().getExecutableTypes()) { + if (executable.hasUnexpectedValue(getContext())) { + continue; + } + types.add(executable.getReturnType()); + } + } + + int executionIndex = execution.getIndex(); + if (executionIndex >= 0) { + for (ExecutableTypeData typeData : getExecutableTypes()) { + if (executionIndex < typeData.getEvaluatedCount()) { + types.add(typeData.getEvaluatedParameters().get(executionIndex)); + } + } + } + + return ElementUtils.uniqueSortedTypes(types); + } + }