Preprocessor statements now abort Dead Write analysis.

This commit is contained in:
Chris Hodges 2021-08-05 15:46:16 +02:00
parent 921449cbb8
commit 6c9a726b86
4 changed files with 20 additions and 9 deletions

View File

@ -7,10 +7,7 @@ import com.intellij.psi.util.PsiTreeUtil
import com.intellij.util.SmartList
import de.platon42.intellij.plugins.m68k.asm.*
import de.platon42.intellij.plugins.m68k.asm.M68kIsa.findMatchingInstructions
import de.platon42.intellij.plugins.m68k.psi.M68kAddressModeUtil
import de.platon42.intellij.plugins.m68k.psi.M68kAsmInstruction
import de.platon42.intellij.plugins.m68k.psi.M68kGlobalLabel
import de.platon42.intellij.plugins.m68k.psi.M68kStatement
import de.platon42.intellij.plugins.m68k.psi.*
import de.platon42.intellij.plugins.m68k.utils.M68kIsaUtil
import de.platon42.intellij.plugins.m68k.utils.M68kIsaUtil.checkIfInstructionUsesRegister
import de.platon42.intellij.plugins.m68k.utils.M68kIsaUtil.evaluateRegisterUse
@ -63,7 +60,7 @@ class M68kDeadWriteInspection : AbstractBaseM68kLocalInspectionTool() {
currStatement = PsiTreeUtil.getNextSiblingOfType(currStatement, M68kStatement::class.java) ?: break
val globalLabel = PsiTreeUtil.findChildOfType(currStatement, M68kGlobalLabel::class.java)
if (globalLabel != null) break
if (PsiTreeUtil.getChildOfType(currStatement, M68kPreprocessorDirective::class.java) != null) break
val currAsmInstruction = PsiTreeUtil.getChildOfType(currStatement, M68kAsmInstruction::class.java) ?: continue
val (isaData, currAdrMode) = findExactIsaDataAndAllowedAdrModeForInstruction(currAsmInstruction) ?: continue
if (isaData.changesControlFlow) break
@ -95,7 +92,6 @@ class M68kDeadWriteInspection : AbstractBaseM68kLocalInspectionTool() {
}
}
}
}
return hints.toTypedArray()
}

View File

@ -132,8 +132,7 @@ class M68kSyntaxInspection : AbstractBaseM68kLocalInspectionTool() {
)
)
}
val supportedOpSizes = findSupportedOpSizes(matchingModeIsaDataIgnoringSize, op1, op2, specialReg)
return arrayOf(
when (supportedOpSizes) {

View File

@ -4,7 +4,8 @@ Finds dead writes to registers, i.e. writes that will not have any effect.
Issues a weak warning if the instruction affects only condition codes that are later tested.
Analysis is terminated at the next global label or instruction that reads the register or changes control flow.
Analysis is terminated at the next global label or instruction that reads the register or changes control flow
(or preprocessor statements, like conditional IF statements).
<!-- tooltip end -->
<p>Note: As there is no evaluation of macros right now, the inspection might report some false positives.</p>
</body>

View File

@ -154,4 +154,19 @@ internal class M68kDeadWriteInspectionTest : AbstractInspectionTest() {
)
assertHighlightings(myFixture, 1, "Register d3 is overwritten later without being used")
}
@Test
internal fun conditional_write_does_not_cause_a_warning(@MyFixture myFixture: CodeInsightTestFixture) {
myFixture.enableInspections(M68kDeadWriteInspection::class.java)
myFixture.configureByText(
"deadwrite.asm", """
IF 0
move.w #123,d3
ELSE
clr.w d3
ENDC
"""
)
assertThat(myFixture.doHighlighting()).isEmpty()
}
}