Beispiel #1
0
  /**
   * generate the code for the steady state loop. Inline the work function inside of an infinite
   * while loop.
   *
   * @param filter The single fused filter of the application.
   * @return A JStatement that is a while loop with the work function inlined.
   */
  JStatement generateSteadyStateLoop(SIRFilter filter) {

    JBlock block = new JBlock(null, new JStatement[0], null);

    JBlock workBlock = (JBlock) ObjectDeepCloner.deepCopy(filter.getWork().getBody());

    // add the cloned work function to the block
    block.addStatement(workBlock);

    // return the infinite loop
    return new JWhileStatement(null, new JBooleanLiteral(null, true), block, null);
  }
Beispiel #2
0
  /**
   * Construct the main function.
   *
   * @param filter The single SIRFilter of the application.
   * @return A JBlock with the statements of the main function.
   */
  private JBlock mainFunction(SIRFilter filter) {

    JBlock statements = new JBlock(null, new JStatement[0], null);

    // create the params list, for some reason
    // calling toArray() on the list breaks a later pass
    List paramList = filter.getParams();
    JExpression[] paramArray;
    if (paramList == null || paramList.size() == 0) paramArray = new JExpression[0];
    else paramArray = (JExpression[]) paramList.toArray(new JExpression[0]);

    // add the call to the init function
    statements.addStatement(
        new JExpressionStatement(
            null,
            new JMethodCallExpression(
                null, new JThisExpression(null), filter.getInit().getName(), paramArray),
            null));

    // add the call to the pre(init)work function if this filter
    // is a two stage..
    if (filter instanceof SIRTwoStageFilter) {
      SIRTwoStageFilter two = (SIRTwoStageFilter) filter;
      statements.addStatement(
          new JExpressionStatement(
              null,
              new JMethodCallExpression(
                  null, new JThisExpression(null), two.getInitWork().getName(), new JExpression[0]),
              null));
    }

    // add the call to the work function
    statements.addStatement(generateSteadyStateLoop(filter));

    return statements;
  }