use of com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder in project graal by oracle.
the class FlatNodeGenFactory method callMethod.
private static CodeTree callMethod(CodeTree receiver, ExecutableElement method, CodeTree... boundValues) {
CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
if (method.getModifiers().contains(STATIC)) {
builder.startStaticCall(method.getEnclosingElement().asType(), method.getSimpleName().toString());
} else {
builder.startCall(receiver, method.getSimpleName().toString());
}
int index = -1;
for (VariableElement parameter : method.getParameters()) {
index++;
if (index < boundValues.length) {
CodeTree tree = boundValues[index];
if (tree != null) {
builder.tree(tree);
continue;
}
}
builder.defaultValue(parameter.asType());
}
builder.end();
return builder.build();
}
use of com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder in project graal by oracle.
the class FlatNodeGenFactory method createReturnUnexpectedResult.
private CodeTree createReturnUnexpectedResult(ExecutableTypeData forType, boolean needsCast) {
TypeMirror returnType = context.getType(Object.class);
CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
builder.startCall(needsCast ? "((UnexpectedResultException) ex)" : "ex", "getResult").end();
CodeTree call = builder.build();
builder = builder.create();
if (isVoid(forType.getReturnType())) {
builder.statement(call);
builder.returnStatement();
} else {
builder.startReturn();
builder.tree(expectOrCast(returnType, forType, call));
builder.end();
}
return builder.build();
}
use of com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder in project graal by oracle.
the class GeneratorUtils method createConstructorUsingFields.
public static CodeExecutableElement createConstructorUsingFields(Set<Modifier> modifiers, CodeTypeElement clazz, ExecutableElement constructor) {
CodeExecutableElement method = new CodeExecutableElement(modifiers, null, clazz.getSimpleName().toString());
CodeTreeBuilder builder = method.createBuilder();
if (constructor != null && constructor.getParameters().size() > 0) {
builder.startStatement();
builder.startSuperCall();
for (VariableElement parameter : constructor.getParameters()) {
method.addParameter(new CodeVariableElement(parameter.asType(), parameter.getSimpleName().toString()));
builder.string(parameter.getSimpleName().toString());
}
// super
builder.end();
// statement
builder.end();
}
for (VariableElement field : clazz.getFields()) {
if (field.getModifiers().contains(STATIC)) {
continue;
}
String fieldName = field.getSimpleName().toString();
method.addParameter(new CodeVariableElement(field.asType(), fieldName));
builder.startStatement();
builder.string("this.");
builder.string(fieldName);
builder.string(" = ");
builder.string(fieldName);
// statement
builder.end();
}
return method;
}
use of com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder in project graal by oracle.
the class GeneratorUtils method createTransferToInterpreterAndInvalidate.
static CodeTree createTransferToInterpreterAndInvalidate() {
ProcessorContext context = ProcessorContext.getInstance();
CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
builder.startStatement().startStaticCall(context.getType(CompilerDirectives.class), "transferToInterpreterAndInvalidate").end().end();
return builder.build();
}
use of com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder in project graal by oracle.
the class NodeFactoryFactory method createCreateNodeMethod.
private CodeExecutableElement createCreateNodeMethod() {
CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), node.getNodeType(), "createNode");
CodeVariableElement arguments = new CodeVariableElement(context.getType(Object.class), "arguments");
method.setVarArgs(true);
method.addParameter(arguments);
CodeTreeBuilder builder = method.createBuilder();
List<ExecutableElement> signatures = GeneratorUtils.findUserConstructors(createdFactoryElement.asType());
boolean ifStarted = false;
for (ExecutableElement element : signatures) {
ifStarted = builder.startIf(ifStarted);
builder.string("arguments.length == " + element.getParameters().size());
int index = 0;
for (VariableElement param : element.getParameters()) {
if (ElementUtils.isObject(param.asType())) {
index++;
continue;
}
builder.string(" && ");
if (!param.asType().getKind().isPrimitive()) {
builder.string("(arguments[" + index + "] == null || ");
}
builder.string("arguments[" + index + "] instanceof ");
builder.type(ElementUtils.eraseGenericTypes(ElementUtils.boxType(context, param.asType())));
if (!param.asType().getKind().isPrimitive()) {
builder.string(")");
}
index++;
}
builder.end();
builder.startBlock();
builder.startReturn().startCall("create");
index = 0;
for (VariableElement param : element.getParameters()) {
builder.startGroup();
if (!ElementUtils.isObject(param.asType())) {
builder.string("(").type(param.asType()).string(") ");
}
builder.string("arguments[").string(String.valueOf(index)).string("]");
builder.end();
index++;
}
builder.end().end();
// block
builder.end();
}
builder.startElseBlock();
builder.startThrow().startNew(context.getType(IllegalArgumentException.class));
builder.doubleQuote("Invalid create signature.");
builder.end().end();
// else block
builder.end();
return method;
}
Aggregations