use of com.oracle.truffle.dsl.processor.java.model.CodeTree in project graal by oracle.
the class AbstractCodeWriter method visitVariable.
@Override
public Void visitVariable(VariableElement f, Void p) {
Element parent = f.getEnclosingElement();
for (AnnotationMirror annotation : f.getAnnotationMirrors()) {
visitAnnotation(f, annotation);
write(" ");
}
CodeTree init = null;
if (f instanceof CodeVariableElement) {
init = ((CodeVariableElement) f).getInit();
}
if (parent != null && parent.getKind() == ElementKind.ENUM && f.getModifiers().contains(Modifier.STATIC)) {
write(f.getSimpleName());
if (init != null) {
write("(");
visitTree(init, p, f);
write(")");
}
} else {
writeModifiers(f.getModifiers(), true);
boolean varArgs = false;
if (parent != null && parent.getKind() == ElementKind.METHOD) {
ExecutableElement method = (ExecutableElement) parent;
if (method.isVarArgs() && method.getParameters().indexOf(f) == method.getParameters().size() - 1) {
varArgs = true;
}
}
TypeMirror varType = f.asType();
if (varArgs) {
if (varType.getKind() == TypeKind.ARRAY) {
varType = ((ArrayType) varType).getComponentType();
}
write(useImport(f, varType));
write("...");
} else {
write(useImport(f, varType));
}
write(" ");
write(f.getSimpleName());
if (init != null) {
write(" = ");
visitTree(init, p, f);
}
}
return null;
}
use of com.oracle.truffle.dsl.processor.java.model.CodeTree in project graal by oracle.
the class DSLExpressionGenerator method visitBinary.
public void visitBinary(Binary binary) {
CodeTree right = stack.pop();
CodeTree left = stack.pop();
stack.push(combine(left, string(" " + binary.getOperator() + " "), right));
}
use of com.oracle.truffle.dsl.processor.java.model.CodeTree in project graal by oracle.
the class DSLExpressionGenerator method visitVariable.
public void visitVariable(Variable variable) {
VariableElement resolvedVariable = variable.getResolvedVariable();
CodeTree tree;
if (variable.getResolvedType().getKind() == TypeKind.NULL) {
tree = CodeTreeBuilder.singleString("null");
} else if (variable.getReceiver() == null) {
if (isStatic(resolvedVariable)) {
tree = staticReference(resolvedVariable);
} else {
tree = bindings.get(variable);
boolean bound = true;
if (tree == null) {
tree = string(resolvedVariable.getSimpleName().toString());
bound = false;
}
if (root != null && !bound) {
tree = combine(root, string("."), tree);
}
}
} else {
if (isStatic(resolvedVariable)) {
throw new AssertionError("Static variables cannot have receivers.");
}
tree = combine(pop(), string("."), string(resolvedVariable.getSimpleName().toString()));
}
push(tree);
}
use of com.oracle.truffle.dsl.processor.java.model.CodeTree in project graal by oracle.
the class FlatNodeGenFactory method createCallSingleChildExecute.
private ChildExecutionResult createCallSingleChildExecute(NodeExecutionData execution, LocalVariable target, FrameState frameState, ExecutableTypeData executableType) {
CodeTree execute = callChildExecuteMethod(execution, executableType, frameState);
TypeMirror sourceType = executableType.getReturnType();
TypeMirror targetType = target.getTypeMirror();
CodeTree result = expect(sourceType, targetType, execute);
return new ChildExecutionResult(result, executableType.hasUnexpectedValue(context) || needsCastTo(sourceType, targetType));
}
use of com.oracle.truffle.dsl.processor.java.model.CodeTree in project graal by oracle.
the class FlatNodeGenFactory method createExecuteAndSpecialize.
private CodeExecutableElement createExecuteAndSpecialize() {
if (!node.needsRewrites(context)) {
return null;
}
final FrameState frameState = FrameState.load(this);
String frame = null;
if (needsFrameToExecute(reachableSpecializations)) {
frame = FRAME_VALUE;
}
TypeMirror returnType = executeAndSpecializeType.getReturnType();
CodeExecutableElement method = frameState.createMethod(modifiers(PRIVATE), returnType, "executeAndSpecialize", frame);
final CodeTreeBuilder builder = method.createBuilder();
builder.declaration(context.getType(Lock.class), "lock", "getLock()");
builder.declaration(context.getType(boolean.class), "hasLock", "true");
builder.statement("lock.lock()");
builder.tree(state.createLoad(frameState));
if (requiresExclude()) {
builder.tree(exclude.createLoad(frameState));
}
if (shouldReportPolymorphism(node, reachableSpecializations)) {
generateSaveOldPolymorphismState(builder, frameState);
}
builder.startTryBlock();
FrameState originalFrameState = frameState.copy();
SpecializationGroup group = createSpecializationGroups();
CodeTree execution = visitSpecializationGroup(builder, group, executeAndSpecializeType, frameState, null, NodeExecutionMode.SLOW_PATH);
builder.tree(execution);
if (group.hasFallthrough()) {
builder.tree(createTransferToInterpreterAndInvalidate());
builder.tree(createThrowUnsupported(builder, originalFrameState));
}
builder.end().startFinallyBlock();
if (shouldReportPolymorphism(node, reachableSpecializations)) {
generateCheckNewPolymorphismState(builder);
}
builder.startIf().string("hasLock").end().startBlock();
builder.statement("lock.unlock()");
builder.end();
builder.end();
return method;
}
Aggregations