/** Boolean operator code generation Optimized operations are: || */
  public void generateOptimizedBoolean(
      BlockScope currentScope,
      CodeStream codeStream,
      BranchLabel trueLabel,
      BranchLabel falseLabel,
      boolean valueRequired) {
    if (this.constant != Constant.NotAConstant) {
      super.generateOptimizedBoolean(
          currentScope, codeStream, trueLabel, falseLabel, valueRequired);
      return;
    }

    // <expr> || false --> <expr>
    Constant cst = this.right.constant;
    if (cst != Constant.NotAConstant && cst.booleanValue() == false) {
      int pc = codeStream.position;
      this.left.generateOptimizedBoolean(
          currentScope, codeStream, trueLabel, falseLabel, valueRequired);
      if (this.mergedInitStateIndex != -1) {
        codeStream.removeNotDefinitelyAssignedVariables(currentScope, this.mergedInitStateIndex);
      }
      codeStream.recordPositionsFrom(pc, this.sourceStart);
      return;
    }

    cst = this.left.optimizedBooleanConstant();
    boolean leftIsConst = cst != Constant.NotAConstant;
    boolean leftIsTrue = leftIsConst && cst.booleanValue() == true;

    cst = this.right.optimizedBooleanConstant();
    boolean rightIsConst = cst != Constant.NotAConstant;
    boolean rightIsTrue = rightIsConst && cst.booleanValue() == true;

    // default case
    generateOperands:
    {
      if (falseLabel == null) {
        if (trueLabel != null) {
          // implicit falling through the FALSE case
          this.left.generateOptimizedBoolean(
              currentScope, codeStream, trueLabel, null, !leftIsConst);
          // need value, e.g. if (a == 1 || ((b = 2) > 0)) {} -> shouldn't initialize 'b' if a==1
          if (leftIsTrue) {
            if (valueRequired) codeStream.goto_(trueLabel);
            codeStream.recordPositionsFrom(codeStream.position, this.left.sourceEnd);
            break generateOperands; // no need to generate right operand
          }
          if (this.rightInitStateIndex != -1) {
            codeStream.addDefinitelyAssignedVariables(currentScope, this.rightInitStateIndex);
          }
          this.right.generateOptimizedBoolean(
              currentScope, codeStream, trueLabel, null, valueRequired && !rightIsConst);
          if (valueRequired && rightIsTrue) {
            codeStream.goto_(trueLabel);
            codeStream.recordPositionsFrom(codeStream.position, this.sourceEnd);
          }
        }
      } else {
        // implicit falling through the TRUE case
        if (trueLabel == null) {
          BranchLabel internalTrueLabel = new BranchLabel(codeStream);
          this.left.generateOptimizedBoolean(
              currentScope, codeStream, internalTrueLabel, null, !leftIsConst);
          // need value, e.g. if (a == 1 || ((b = 2) > 0)) {} -> shouldn't initialize 'b' if a==1
          if (leftIsTrue) {
            internalTrueLabel.place();
            break generateOperands; // no need to generate right operand
          }
          if (this.rightInitStateIndex != -1) {
            codeStream.addDefinitelyAssignedVariables(currentScope, this.rightInitStateIndex);
          }
          this.right.generateOptimizedBoolean(
              currentScope, codeStream, null, falseLabel, valueRequired && !rightIsConst);
          int pc = codeStream.position;
          if (valueRequired && rightIsConst && !rightIsTrue) {
            codeStream.goto_(falseLabel);
            codeStream.recordPositionsFrom(pc, this.sourceEnd);
          }
          internalTrueLabel.place();
        } else {
          // no implicit fall through TRUE/FALSE --> should never occur
        }
      }
    }
    if (this.mergedInitStateIndex != -1) {
      codeStream.removeNotDefinitelyAssignedVariables(currentScope, this.mergedInitStateIndex);
    }
  }