Skip to content

Commit

Permalink
Apply @JaroslavTulach suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
kazcw committed Jul 24, 2024
1 parent dd81f5d commit 32e0df5
Showing 1 changed file with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -919,9 +919,7 @@ yield switch (op.codeRepr()) {
default -> {
var lhs = unnamedCallArgument(app.getLhs());
var rhs = unnamedCallArgument(app.getRhs());
var loc = getIdentifiedLocation(app);
var ir = applyOperator(op, lhs, rhs, loc);
attachTranslatedWarnings(ir, app);
var ir = applyOperator(op, lhs, rhs, app);
yield ir;
}
};
Expand All @@ -936,8 +934,7 @@ yield translateSyntaxError(l.getExpression().getExpression(),
Syntax.UnexpectedExpression$.MODULE$);
}
var rhs = unnamedCallArgument(l.getExpression().getExpression());
var loc = getIdentifiedLocation(app);
var both = applyOperator(op, lhs, rhs, loc);
var both = applyOperator(op, lhs, rhs, app);
expr = both;
lhs = new CallArgument.Specified(Option.empty(), expr, loc, meta(), diag());
}
Expand Down Expand Up @@ -1201,27 +1198,19 @@ yield translateFunction(fun, name, isOperator, fun.getArgs(), fun.getBody(),
};
}

private void attachTranslatedWarnings(IR ir, Tree tree) {
for (var warning : tree.getWarnings()) {
var message = Parser.getWarningMessage(warning);
var irWarning = new Warning.Syntax(ir, message);
ir.diagnostics().add(irWarning);
}
}

private Operator applyOperator(Token.Operator op, CallArgument lhs, CallArgument rhs,
Option<IdentifiedLocation> loc) {
private Operator applyOperator(Token.Operator op, CallArgument lhs, CallArgument rhs, Tree tree) {
var loc = getIdentifiedLocation(tree);
var name = new Name.Literal(
op.codeRepr(), true, getIdentifiedLocation(op), Option.empty(), meta(), diag()
op.codeRepr(), true, getIdentifiedLocation(op), Option.empty(), meta(), diag(op)
);
if (lhs == null && rhs == null) {
return new Section.Sides(name, loc, meta(), diag());
return new Section.Sides(name, loc, meta(), diag(tree));
} else if (lhs == null) {
return new Section.Right(name, rhs, loc, meta(), diag());
return new Section.Right(name, rhs, loc, meta(), diag(tree));
} else if (rhs == null) {
return new Section.Left(lhs, name, loc, meta(), diag());
return new Section.Left(lhs, name, loc, meta(), diag(tree));
} else {
return new Operator.Binary(lhs, name, rhs, loc, meta(), diag());
return new Operator.Binary(lhs, name, rhs, loc, meta(), diag(tree));
}
}

Expand Down Expand Up @@ -2038,6 +2027,17 @@ private DiagnosticStorage diag() {
return DiagnosticStorage.apply(nil());
}

private DiagnosticStorage diag(Tree tree) {
var warnings = tree.getWarnings().stream();
var diags = warnings.map(warning -> new Warning.Syntax(ir, Parser.getWarningMessage(warning)));
return DiagnosticStorage.apply(diags);
}

private DiagnosticStorage diag(Token token) {
// Tokens don't (currently) have warnings attached.
return diag();
}

private static int castToInt(long presumablyInt) {
int value = (int) presumablyInt;
if (value != presumablyInt) {
Expand Down

0 comments on commit 32e0df5

Please sign in to comment.