public CodeTreeBuilder startTryBlock() { return string("try ").startBlock(); }
public CodeTreeBuilder startTryBlock() { return string("try ").startBlock(); }
public CodeTreeBuilder startFinallyBlock() { clearLast(CodeTreeKind.NEW_LINE); string(" finally "); return startBlock(); }
public CodeTreeBuilder startFinallyBlock() { clearLast(CodeTreeKind.NEW_LINE); string(" finally "); return startBlock(); }
public CodeTreeBuilder startDoBlock() { return startGroup().string("do ").startBlock(); }
public CodeTreeBuilder startDoBlock() { return startGroup().string("do ").startBlock(); }
public CodeTreeBuilder startElseBlock() { clearLast(CodeTreeKind.NEW_LINE); return startGroup().string(" else ").startBlock().endAfter(); }
public CodeTreeBuilder startElseBlock() { clearLast(CodeTreeKind.NEW_LINE); return startGroup().string(" else ").startBlock().endAfter(); }
public CodeTreeBuilder startSynchronized(CodeTree object) { return string("synchronized").startParantheses().tree(object).end().startBlock(); }
public CodeTreeBuilder startCatchBlock(TypeMirror exceptionType, String localVarName) { clearLast(CodeTreeKind.NEW_LINE); string(" catch (").type(exceptionType).string(" ").string(localVarName).string(") "); return startBlock(); }
public CodeTreeBuilder startCatchBlock(TypeMirror exceptionType, String localVarName) { clearLast(CodeTreeKind.NEW_LINE); string(" catch (").type(exceptionType).string(" ").string(localVarName).string(") "); return startBlock(); }
public CodeTreeBuilder startCatchBlock(TypeMirror[] exceptionTypes, String localVarName) { clearLast(CodeTreeKind.NEW_LINE); string(" catch ("); for (int i = 0; i < exceptionTypes.length; i++) { if (i != 0) { string(" | "); } type(exceptionTypes[i]); } string(" ").string(localVarName).string(") "); return startBlock(); }
public CodeTreeBuilder startCatchBlock(TypeMirror[] exceptionTypes, String localVarName) { clearLast(CodeTreeKind.NEW_LINE); string(" catch ("); for (int i = 0; i < exceptionTypes.length; i++) { if (i != 0) { string(" | "); } type(exceptionTypes[i]); } string(" ").string(localVarName).string(") "); return startBlock(); }
private void generateCheckNewPolymorphismState(CodeTreeBuilder builder) { builder.startIf().string(OLD_STATE + " != 0"); if (requiresExclude()) { builder.string(" || " + OLD_EXCLUDE + " != 0"); } builder.end(); builder.startBlock(); builder.string(CHECK_FOR_POLYMORPHIC_SPECIALIZE + "(" + OLD_STATE); if (requiresExclude()) { builder.string(", " + OLD_EXCLUDE); } if (requiresCacheCheck()) { builder.string(", " + OLD_CACHE_COUNT); } builder.string(");").newLine(); builder.end(); // block }
private static CodeTree createShortCircuit(LocalVariable targetValue, LocalVariable shortCircuitValue, CodeTree tryExecute) { if (shortCircuitValue == null) { return tryExecute; } CodeTreeBuilder builder = CodeTreeBuilder.createBuilder(); builder.tree(shortCircuitValue.createDeclaration(shortCircuitValue.createReference())); builder.tree(targetValue.createDeclaration(builder.create().defaultValue(targetValue.getTypeMirror()).build())); builder.startIf().string(shortCircuitValue.getName()).end().startBlock(); builder.tree(tryExecute); builder.end(); return builder.build(); }
private CodeTree createFastPathAssumptionCheck(CodeTreeBuilder parent, SpecializationData specialization, ExecutableTypeData forType, FrameState frameState) throws AssertionError { CodeTreeBuilder builder = parent.create(); builder.startIf(); String sep = ""; for (AssumptionExpression assumption : specialization.getAssumptionExpressions()) { builder.string(sep); builder.string("!"); builder.startCall("isValid_").tree(createAssumptionReference(frameState, specialization, assumption)).end(); isValidSignatures.put(ElementUtils.getQualifiedName(assumption.getExpression().getResolvedType()), assumption.getExpression().getResolvedType()); sep = " || "; } builder.end().startBlock(); builder.tree(createTransferToInterpreterAndInvalidate()); builder.tree(createRemoveThis(builder, frameState, forType, specialization)); builder.end(); return builder.build(); }
private Element createCheck() { String methodName = "check"; CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), context.getType(boolean.class), methodName); method.addParameter(new CodeVariableElement(context.getType(Object.class), "value")); CodeTreeBuilder builder = method.createBuilder(); boolean elseIf = false; for (TypeMirror sourceType : sourceTypes) { elseIf = builder.startIf(elseIf); builder.string(seenFieldName(sourceType)).string(" && ").tree(TypeSystemCodeGenerator.check(typeSystem, sourceType, "value")); builder.end(); builder.startBlock().returnTrue().end(); } builder.returnFalse(); return method; }
private void addUnsupportedMethod(CodeTypeElement clazz) { CodeVariableElement seenUnsupportedField = new CodeVariableElement(modifiers(PRIVATE), getType(boolean.class), "seenUnsupported0"); seenUnsupportedField.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(CompilationFinal.class))); clazz.add(seenUnsupportedField); LocalContext locals = LocalContext.load(this); CodeExecutableElement method = locals.createMethod(modifiers(PRIVATE), getType(UnsupportedSpecializationException.class), "unsupported", varArgsThreshold); CodeTreeBuilder builder = method.createBuilder(); builder.startIf().string("!").string(seenUnsupportedField.getName()).end().startBlock(); builder.startStatement().startStaticCall(getType(CompilerDirectives.class), "transferToInterpreterAndInvalidate").end().end(); builder.startStatement().string(seenUnsupportedField.getName()).string(" = true").end(); builder.end(); builder.startReturn(); builder.startNew(getType(UnsupportedSpecializationException.class)); builder.string("this"); builder.tree(createGetSuppliedChildren()); locals.addReferencesTo(builder); builder.end(); builder.end(); clazz.add(method); }
public static CodeExecutableElement createExpectMethod(Modifier visibility, TypeSystemData typeSystem, TypeMirror sourceTypeOriginal, TypeMirror expectedTypeOriginal) { TypeMirror expectedType = ElementUtils.fillInGenericWildcards(expectedTypeOriginal); TypeMirror sourceType = ElementUtils.fillInGenericWildcards(sourceTypeOriginal); if (ElementUtils.isObject(expectedType) || ElementUtils.isVoid(expectedType)) { return null; } CodeExecutableElement method = new CodeExecutableElement(modifiers(STATIC), expectedType, TypeSystemCodeGenerator.expectTypeMethodName(typeSystem, expectedType)); method.setVisibility(visibility); method.addParameter(new CodeVariableElement(sourceType, LOCAL_VALUE)); method.addThrownType(typeSystem.getContext().getTruffleTypes().getUnexpectedValueException()); CodeTreeBuilder body = method.createBuilder(); body.startIf().tree(check(typeSystem, expectedType, LOCAL_VALUE)).end().startBlock(); body.startReturn().tree(cast(typeSystem, expectedType, LOCAL_VALUE)).end(); body.end(); body.startThrow().startNew(typeSystem.getContext().getTruffleTypes().getUnexpectedValueException()).string(LOCAL_VALUE).end().end(); return method; }
static CodeExecutableElement createExpectMethod(Modifier visibility, TypeSystemData typeSystem, TypeMirror sourceTypeOriginal, TypeMirror expectedTypeOriginal) { TypeMirror expectedType = ElementUtils.fillInGenericWildcards(expectedTypeOriginal); TypeMirror sourceType = ElementUtils.fillInGenericWildcards(sourceTypeOriginal); if (ElementUtils.isObject(expectedType) || ElementUtils.isVoid(expectedType)) { return null; } CodeExecutableElement method = new CodeExecutableElement(modifiers(STATIC), expectedType, TypeSystemCodeGenerator.expectTypeMethodName(typeSystem, expectedType)); method.setVisibility(visibility); method.addParameter(new CodeVariableElement(sourceType, LOCAL_VALUE)); method.addThrownType(typeSystem.getContext().getTruffleTypes().getUnexpectedValueException()); CodeTreeBuilder body = method.createBuilder(); body.startIf().tree(check(typeSystem, expectedType, LOCAL_VALUE)).end().startBlock(); body.startReturn().tree(cast(typeSystem, expectedType, LOCAL_VALUE)).end(); body.end(); body.startThrow().startNew(typeSystem.getContext().getTruffleTypes().getUnexpectedValueException()).string(LOCAL_VALUE).end().end(); return method; }