  public Object build(DirectiveBuilder builder, 
                      BuildContext bc) 
  throws BuildException {
    Object c = builder.getArg(IF_COND, bc);
    boolean cMacro = (c instanceof Macro);
    int elseifCount;
    DirectiveArgs elseArgs;
    DirectiveArgs[] elseifArgs = null;
    if (!cMacro && Expression.isTrue(c)) 
      return (Block) builder.getArg(IF_BLOCK, bc);
    elseArgs = builder.getSubdirective(IF_ELSE);
    elseifArgs = builder.getRepeatingSubdirective(IF_ELSEIF);
    elseifCount = (elseifArgs == null) ? 0 : elseifArgs.length;
    if (elseifCount == 0) {
      if (!cMacro) {
        return (elseArgs != null) 
          ? elseArgs.getArg(ELSE_BLOCK, bc) : "";
      }
      else {
        conditions = new Macro[1];
        blocks     = new Block[1];
        conditions[0] = (Macro) c;
        blocks[0]     = (Block) builder.getArg(IF_BLOCK, bc);
        if (elseArgs != null)
          elseBlock = (Block) elseArgs.getArg(ELSE_BLOCK, bc);
        return this;
      }
    }
    else {
      int i=0;
      nConditions=elseifCount;
      if (cMacro)
        ++nConditions;
      conditions = new Macro[nConditions];
      blocks     = new Block[nConditions];
      if (cMacro) {
        conditions[0] = (Macro) c;
        blocks[0]     = (Block) builder.getArg(IF_BLOCK, bc);
        ++i;
      }
      for (int j=0; j < elseifCount; j++) {
        c = elseifArgs[j].getArg(ELSEIF_COND, bc);
        if (c instanceof Macro) {
          conditions[i] = (Macro) c;
          blocks[i] = (Block) elseifArgs[j].getArg(ELSEIF_BLOCK, bc);
          ++i;
        }
        else if (Expression.isTrue(c)) {
          elseBlock = (Block) elseifArgs[j].getArg(ELSEIF_BLOCK, bc);
          if (i == 0)
            return elseBlock;
          else 
            break;
        }
        else {
        }
      }
      if (elseBlock == null && elseArgs != null) {
          elseBlock = (Block) elseArgs.getArg(ELSE_BLOCK, bc);
        if (i == 0)
          return elseBlock;
      }
      if (i < nConditions) {
        nConditions = i;
      }
    }
    return this;
  }

  public Object build(DirectiveBuilder builder, 
                      BuildContext bc) 
  throws BuildException {
    Object c = builder.getArg(IF_COND, bc);
    boolean cMacro = (c instanceof Macro);
    int elseifCount;
    DirectiveArgs elseArgs;
    DirectiveArgs[] elseifArgs = null;
    if (!cMacro && Expression.isTrue(c)) {
      return (Block) builder.getArg(IF_BLOCK, bc);
    }
    elseArgs = builder.getSubdirective(IF_ELSE);
    elseifArgs = builder.getRepeatingSubdirective(IF_ELSEIF);
    elseifCount = (elseifArgs == null) ? 0 : elseifArgs.length;
    if (elseifCount == 0) {
      if (!cMacro) {
        return (elseArgs != null) 
          ? elseArgs.getArg(ELSE_BLOCK, bc) : "";
      }
      else {
        nConditions = 1;
        conditions = new Macro[1];
        blocks     = new Block[1];
        conditions[0] = (Macro) c;
        blocks[0]     = (Block) builder.getArg(IF_BLOCK, bc);
        if (elseArgs != null)
          elseBlock = (Block) elseArgs.getArg(ELSE_BLOCK, bc);
        return this;
      }
    }
    else {
      int i=0;
      nConditions=elseifCount + (cMacro? 1 : 0);
      conditions = new Macro[nConditions];
      blocks     = new Block[nConditions];
      if (cMacro) {
        conditions[0] = (Macro) c;
        blocks[0]     = (Block) builder.getArg(IF_BLOCK, bc);
        ++i;
      }
      for (int j=0; j < elseifCount; j++) {
        c = elseifArgs[j].getArg(ELSEIF_COND, bc);
        if (c instanceof Macro) {
          conditions[i] = (Macro) c;
          blocks[i] = (Block) elseifArgs[j].getArg(ELSEIF_BLOCK, bc);
          ++i;
        }
        else if (Expression.isTrue(c)) {
          elseBlock = (Block) elseifArgs[j].getArg(ELSEIF_BLOCK, bc);
          if (i == 0)
            return elseBlock;
          else 
            break;
        }
        else {
        }
      }
      if (elseBlock == null && elseArgs != null) {
          elseBlock = (Block) elseArgs.getArg(ELSE_BLOCK, bc);
        if (i == 0)
          return elseBlock;
      }
      if (i < nConditions) {
        nConditions = i;
      }
    }
    return this;
  }
