mirror of
https://github.com/KarolS/millfork.git
synced 2024-08-31 10:29:26 +00:00
Don't emit warnings if an unused variable was assigned a simple expression
This commit is contained in:
parent
92dd5d6913
commit
9634ea9516
@ -68,7 +68,17 @@ object UnusedGlobalVariables extends NodeOptimization {
|
|||||||
case s: VariableDeclarationStatement =>
|
case s: VariableDeclarationStatement =>
|
||||||
if (globalsToRemove(s.name)) None else Some(s)
|
if (globalsToRemove(s.name)) None else Some(s)
|
||||||
case s@ExpressionStatement(FunctionCallExpression(op, VariableExpression(n) :: params)) if op.endsWith("=") =>
|
case s@ExpressionStatement(FunctionCallExpression(op, VariableExpression(n) :: params)) if op.endsWith("=") =>
|
||||||
if (globalsToRemove(n)) params.map(ExpressionStatement) else Some(s)
|
if (globalsToRemove(n)) {
|
||||||
|
params.flatMap {
|
||||||
|
case VariableExpression(_) => None
|
||||||
|
case LiteralExpression(_, _) => None
|
||||||
|
case x => Some(ExpressionStatement(x))
|
||||||
|
}
|
||||||
|
} else Some(s)
|
||||||
|
case s@Assignment(VariableExpression(n), VariableExpression(_)) =>
|
||||||
|
if (globalsToRemove(n)) Nil else Some(s)
|
||||||
|
case s@Assignment(VariableExpression(n), LiteralExpression(_, _)) =>
|
||||||
|
if (globalsToRemove(n)) Nil else Some(s)
|
||||||
case s@Assignment(VariableExpression(n), expr) =>
|
case s@Assignment(VariableExpression(n), expr) =>
|
||||||
if (globalsToRemove(n)) Some(ExpressionStatement(expr)) else Some(s)
|
if (globalsToRemove(n)) Some(ExpressionStatement(expr)) else Some(s)
|
||||||
case s@Assignment(SeparateBytesExpression(VariableExpression(h), VariableExpression(l)), expr) =>
|
case s@Assignment(SeparateBytesExpression(VariableExpression(h), VariableExpression(l)), expr) =>
|
||||||
|
@ -74,11 +74,21 @@ object UnusedLocalVariables extends NodeOptimization {
|
|||||||
removeVariables(statements, localsToRemove)
|
removeVariables(statements, localsToRemove)
|
||||||
}
|
}
|
||||||
|
|
||||||
def removeVariables(statements: List[Statement], localsToRemove: Set[String]): List[Statement] = statements.flatMap {
|
def removeVariables(statements: List[Statement], localsToRemove: Set[String]): List[Statement] = if (localsToRemove.isEmpty) statements else statements.flatMap {
|
||||||
case s: VariableDeclarationStatement =>
|
case s: VariableDeclarationStatement =>
|
||||||
if (localsToRemove(s.name)) None else Some(s)
|
if (localsToRemove(s.name)) None else Some(s)
|
||||||
case s@ExpressionStatement(FunctionCallExpression(op, VariableExpression(n) :: params)) if op.endsWith("=") =>
|
case s@ExpressionStatement(FunctionCallExpression(op, VariableExpression(n) :: params)) if op.endsWith("=") =>
|
||||||
if (localsToRemove(n)) params.map(ExpressionStatement) else Some(s)
|
if (localsToRemove(n)) {
|
||||||
|
params.flatMap {
|
||||||
|
case VariableExpression(_) => None
|
||||||
|
case LiteralExpression(_, _) => None
|
||||||
|
case x => Some(ExpressionStatement(x))
|
||||||
|
}
|
||||||
|
} else Some(s)
|
||||||
|
case s@Assignment(VariableExpression(n), VariableExpression(_)) =>
|
||||||
|
if (localsToRemove(n)) Nil else Some(s)
|
||||||
|
case s@Assignment(VariableExpression(n), LiteralExpression(_, _)) =>
|
||||||
|
if (localsToRemove(n)) Nil else Some(s)
|
||||||
case s@Assignment(VariableExpression(n), expr) =>
|
case s@Assignment(VariableExpression(n), expr) =>
|
||||||
if (localsToRemove(n)) Some(ExpressionStatement(expr)) else Some(s)
|
if (localsToRemove(n)) Some(ExpressionStatement(expr)) else Some(s)
|
||||||
case s@Assignment(SeparateBytesExpression(VariableExpression(h), VariableExpression(l)), expr) =>
|
case s@Assignment(SeparateBytesExpression(VariableExpression(h), VariableExpression(l)), expr) =>
|
||||||
|
Loading…
Reference in New Issue
Block a user