private CodeTree createGetSuppliedChildren() { ArrayType nodeArray = context.getEnvironment().getTypeUtils().getArrayType(getType(Node.class)); CodeTreeBuilder builder = CodeTreeBuilder.createBuilder(); builder.startNewArray(nodeArray, null); for (int i = 0; i < node.getChildExecutions().size(); i++) { NodeExecutionData execution = node.getChildExecutions().get(i); if (execution.isShortCircuit()) { builder.nullLiteral(); } if (execution.getChild() == null) { builder.nullLiteral(); } else { builder.tree(accessParent(nodeFieldName(execution))); } } builder.end(); return builder.build(); }
private CodeExecutableElement createCreateMethod(ExecutableElement constructor) { CodeExecutableElement method = CodeExecutableElement.clone(context.getEnvironment(), constructor); method.setSimpleName(CodeNames.of("create")); method.getModifiers().clear(); method.getModifiers().add(Modifier.PUBLIC); method.getModifiers().add(Modifier.STATIC); method.setReturnType(node.getNodeType()); CodeTreeBuilder body = method.createBuilder(); body.startReturn(); if (node.getSpecializations().isEmpty()) { body.nullLiteral(); } else { body.startNew(NodeGenFactory.nodeType(node)); for (VariableElement var : method.getParameters()) { body.string(var.getSimpleName().toString()); } body.end(); } body.end(); return method; } }
private CodeExecutableElement createCreateMethod(ExecutableElement constructor) { CodeExecutableElement method = CodeExecutableElement.clone(context.getEnvironment(), constructor); method.setSimpleName(CodeNames.of("create")); method.getModifiers().clear(); method.getModifiers().add(Modifier.PUBLIC); method.getModifiers().add(Modifier.STATIC); method.setReturnType(node.getNodeType()); CodeTreeBuilder body = method.createBuilder(); body.startReturn(); if (node.getSpecializations().isEmpty()) { body.nullLiteral(); } else { body.startNew(NodeCodeGenerator.nodeType(node)); for (VariableElement var : method.getParameters()) { body.string(var.getSimpleName().toString()); } body.end(); } body.end(); return method; } }
public void addReferencesTo(CodeTreeBuilder builder, String... optionalNames) { for (String var : optionalNames) { LocalVariable local = values.get(var); if (local == null) { builder.nullLiteral(); } else { builder.tree(local.createReference()); } } List<NodeExecutionData> executions = factory.node.getChildExecutions(); for (NodeExecutionData execution : executions) { if (execution.isShortCircuit()) { LocalVariable shortCircuitVar = getShortCircuit(execution); if (shortCircuitVar != null) { builder.tree(shortCircuitVar.createReference()); } } LocalVariable var = getValue(execution); if (var != null) { builder.startGroup(); if (executions.size() == 1 && ElementUtils.typeEquals(var.getTypeMirror(), factory.getType(Object[].class))) { // if the current type is Object[] do not use varargs for a single argument builder.string("(Object) "); } builder.tree(var.createReference()); builder.end(); } } }
private CodeTree createCallSharedExecuteChild(NodeExecutionData execution, LocalVariable targetValue, LocalContext currentValues) { if (!isExecuteChildShared(execution, targetValue.getTypeMirror())) { throw new AssertionError("Execute child not shared with method but called."); } usedExecuteChildMethods.add(execution); CodeTreeBuilder builder = CodeTreeBuilder.createBuilder(); builder.tree(targetValue.createReference()).string(" = "); builder.startCall(executeChildMethodName(execution, targetValue.getTypeMirror())); if (currentValues.get(FRAME_VALUE) == null) { builder.nullLiteral(); } else { builder.string(FRAME_VALUE); } CodeVariableElement implicitProfile = createImplicitProfileParameter(execution, targetValue.getTypeMirror()); if (implicitProfile != null) { builder.string(implicitProfile.getName()); } for (int i = 0; i < execution.getChild().getExecuteWith().size(); i++) { builder.tree(currentValues.getValue(i).createReference()); } builder.end(); return builder.build(); }
private CodeTree createFastPathExecute(CodeTreeBuilder parent, final ExecutableTypeData forType, SpecializationData specialization, FrameState frameState) { CodeTreeBuilder builder = parent.create(); int ifCount = 0; if (specialization.isFallback()) { builder.startIf().startCall(METHOD_FALLBACK_GUARD); if (fallbackNeedsFrame) { if (frameState.get(FRAME_VALUE) != null) { builder.string(FRAME_VALUE); } else { builder.nullLiteral(); } } if (fallbackNeedsState) { builder.string(STATE_VALUE); } frameState.addReferencesTo(builder); builder.end(); builder.end(); builder.startBlock(); ifCount++; } builder.tree(createExecute(builder, frameState, forType, specialization, NodeExecutionMode.FAST_PATH)); builder.end(ifCount); return builder.build(); }
builder.string(FRAME_VALUE); } else { builder.nullLiteral();
private CodeExecutableElement createGetImplicitClass(TypeMirror type) { CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC, STATIC), context.getType(Class.class), TypeSystemCodeGenerator.getImplicitClass(typeSystem, type)); method.addParameter(new CodeVariableElement(context.getType(Object.class), LOCAL_VALUE)); List<TypeMirror> sourceTypes = typeSystem.lookupSourceTypes(type); CodeTreeBuilder builder = method.createBuilder(); boolean elseIf = false; for (TypeMirror sourceType : sourceTypes) { elseIf = builder.startIf(elseIf); builder.tree(check(typeSystem, sourceType, LOCAL_VALUE)).end(); builder.end().startBlock(); builder.startReturn().typeLiteral(sourceType).end(); builder.end(); } builder.startElseIf().string(LOCAL_VALUE).string(" == ").nullLiteral().end(); builder.startBlock(); builder.startReturn().typeLiteral(context.getType(Object.class)).end(); builder.end(); builder.startElseBlock(); builder.tree(createTransferToInterpreterAndInvalidate()); builder.startThrow().startNew(context.getType(IllegalArgumentException.class)).doubleQuote("Illegal type ").end().end(); builder.end(); return method; }