Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Select alternative default calc operator more carefully #3963

Merged
merged 9 commits into from
May 9, 2023
Prev Previous commit
Next Next commit
Remove redundant qualifiers
  • Loading branch information
keyboardDrummer committed May 8, 2023
commit 2a53afa53c958c20404eea40988c0cf912bc381d
30 changes: 15 additions & 15 deletions Source/DafnyCore/AST/Statements/CalcStmt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public class BinaryCalcOp : CalcOp {
public override CalcOp ResultOp(CalcOp other) {
if (other is BinaryCalcOp) {
var o = (BinaryCalcOp)other;
if (this.Subsumes(o)) {
if (Subsumes(o)) {
return this;
} else if (o.Subsumes(this)) {
return other;
Expand Down Expand Up @@ -167,19 +167,19 @@ public class TernaryCalcOp : CalcOp {
/// </summary>
[CanBeNull]
public CalcOp GetInferredDefaultOp() {
CalcStmt.CalcOp alternativeOp = null;
CalcOp alternativeOp = null;
if (Lines.Count == 0) {
return null;
}

if (Expression.IsBoolLiteral(Lines.First(), out var firstOperatorIsBoolLiteral)) {
alternativeOp = new CalcStmt.BinaryCalcOp(firstOperatorIsBoolLiteral ? BinaryExpr.Opcode.Imp : BinaryExpr.Opcode.Exp);
alternativeOp = new BinaryCalcOp(firstOperatorIsBoolLiteral ? BinaryExpr.Opcode.Imp : BinaryExpr.Opcode.Exp);
} else if (Expression.IsBoolLiteral(Lines.Last(), out var lastOperatorIsBoolLiteral)) {
alternativeOp = new CalcStmt.BinaryCalcOp(lastOperatorIsBoolLiteral ? BinaryExpr.Opcode.Exp : BinaryExpr.Opcode.Imp);
alternativeOp = new BinaryCalcOp(lastOperatorIsBoolLiteral ? BinaryExpr.Opcode.Exp : BinaryExpr.Opcode.Imp);
} else if (Expression.IsEmptySetOrMultiset(Lines.First())) {
alternativeOp = new CalcStmt.BinaryCalcOp(BinaryExpr.Opcode.Ge);
alternativeOp = new BinaryCalcOp(BinaryExpr.Opcode.Ge);
} else if (Expression.IsEmptySetOrMultiset(Lines.Last())) {
alternativeOp = new CalcStmt.BinaryCalcOp(BinaryExpr.Opcode.Le);
alternativeOp = new BinaryCalcOp(BinaryExpr.Opcode.Le);
} else {
return null;
}
Expand Down Expand Up @@ -232,13 +232,13 @@ public CalcStmt(RangeToken rangeToken, CalcOp userSuppliedOp, List<Expression> l
Contract.Requires(cce.NonNullElements(hints));
Contract.Requires(hints.Count == Math.Max(lines.Count - 1, 0));
Contract.Requires(stepOps.Count == hints.Count);
this.UserSuppliedOp = userSuppliedOp;
this.Lines = lines;
this.Hints = hints;
UserSuppliedOp = userSuppliedOp;
Lines = lines;
Hints = hints;
Steps = new List<Expression>();
this.StepOps = stepOps;
this.Result = null;
this.Attributes = attrs;
StepOps = stepOps;
Result = null;
Attributes = attrs;
}

public CalcStmt Clone(Cloner cloner) {
Expand Down Expand Up @@ -334,7 +334,7 @@ public CalcStmt(RangeToken rangeToken, CalcOp userSuppliedOp, List<Expression> l
var inOrdinal = false;
var innerCalcIndent = indentBefore + formatter.SpaceTab;
var extraHintIndent = 0;
var ownedTokens = this.OwnedTokens;
var ownedTokens = OwnedTokens;
// First phase: We get the alignment
foreach (var token in ownedTokens) {
if (formatter.SetIndentLabelTokens(token, indentBefore)) {
Expand Down Expand Up @@ -409,7 +409,7 @@ public CalcStmt(RangeToken rangeToken, CalcOp userSuppliedOp, List<Expression> l
}
}

foreach (var hint in this.Hints) {
foreach (var hint in Hints) {
// This block
if (hint.Tok.pos != hint.EndToken.pos) {
foreach (var hintStep in hint.Body) {
Expand All @@ -418,7 +418,7 @@ public CalcStmt(RangeToken rangeToken, CalcOp userSuppliedOp, List<Expression> l
}
}

foreach (var expression in this.Lines) {
foreach (var expression in Lines) {
formatter.SetIndentations(expression.StartToken, innerCalcIndent, innerCalcIndent, innerCalcIndent);
}

Expand Down
Loading