use of org.graalvm.compiler.core.match.MatchableNode in project graal by oracle.
the class MatchProcessor method processMatchableNode.
/**
* Build up the type table to be used during parsing of the MatchRule.
*/
private void processMatchableNode(Element element) {
if (!processedMatchableNode.contains(element)) {
try {
processedMatchableNode.add(element);
AnnotationMirror mirror = findAnnotationMirror(element, matchableNodesTypeMirror);
if (mirror == null) {
mirror = findAnnotationMirror(element, matchableNodeTypeMirror);
}
if (mirror == null) {
return;
}
TypeElement topDeclaringType = topDeclaringType(element);
List<AnnotationMirror> mirrors = null;
if (typeUtils().isSameType(mirror.getAnnotationType(), matchableNodesTypeMirror)) {
// Unpack the mirrors for a repeatable annotation
mirrors = getAnnotationValueList(AnnotationMirror.class, mirror, "value");
}
int i = 0;
for (MatchableNode matchableNode : element.getAnnotationsByType(MatchableNode.class)) {
processMatchableNode(element, topDeclaringType, matchableNode, mirrors != null ? mirrors.get(i++) : mirror);
}
} catch (Throwable t) {
reportExceptionThrow(element, t);
}
}
}
use of org.graalvm.compiler.core.match.MatchableNode in project graal by oracle.
the class MatchProcessor method processMatchableNode.
private void processMatchableNode(Element element, TypeElement topDeclaringType, MatchableNode matchable, AnnotationMirror mirror) throws GraalError {
logMessage("processMatchableNode %s %s %s\n", topDeclaringType, element, matchable);
String nodeClass;
String nodePackage;
TypeMirror nodeClassMirror = null;
try {
matchable.nodeClass();
} catch (MirroredTypeException e) {
nodeClassMirror = e.getTypeMirror();
}
if (nodeClassMirror == null) {
throw new GraalError("Can't get mirror for node class %s", element);
}
if (nodeClassMirror.toString().equals(MatchableNode.class.getName())) {
nodeClass = topDeclaringType.getQualifiedName().toString();
} else {
nodeClass = nodeClassMirror.toString();
}
TypeElement typeElement = processingEnv.getElementUtils().getTypeElement(nodeClass);
if (typeElement == null) {
errorMessage(element, mirror, "Class \"%s\" cannot be resolved to a type", nodeClass);
return;
}
nodePackage = findPackage(typeElement);
assert nodeClass.startsWith(nodePackage);
nodeClass = nodeClass.substring(nodePackage.length() + 1);
assert nodeClass.endsWith("Node");
String shortName = nodeClass.substring(0, nodeClass.length() - 4);
Types typeUtils = processingEnv.getTypeUtils();
TypeElement nodeClassElement = (TypeElement) typeUtils.asElement(nodeClassMirror);
for (String input : matchable.inputs()) {
boolean ok = false;
TypeElement current = nodeClassElement;
while (!ok && current != null) {
for (Element fieldElement : ElementFilter.fieldsIn(current.getEnclosedElements())) {
if (fieldElement.getSimpleName().toString().equals(input)) {
ok = true;
break;
}
}
TypeMirror theSuper = current.getSuperclass();
current = (TypeElement) typeUtils.asElement(theSuper);
}
if (!ok) {
errorMessage(element, mirror, "Input named \"%s\" doesn't exist in %s", input, nodeClassElement.getSimpleName());
}
}
declareType(nodeClassMirror, shortName, nodeClass, nodePackage, matchable.inputs(), matchable.commutative(), matchable.shareable(), element);
}
Aggregations