From 6c9a726b862afb14efe8c1400fc0c8da34929129 Mon Sep 17 00:00:00 2001 From: chrisly42 Date: Thu, 5 Aug 2021 15:46:16 +0200 Subject: [PATCH] Preprocessor statements now abort Dead Write analysis. --- .../m68k/inspections/M68kDeadWriteInspection.kt | 8 ++------ .../m68k/inspections/M68kSyntaxInspection.kt | 3 +-- .../inspectionDescriptions/M68kDeadWrite.html | 3 ++- .../inspections/M68kDeadWriteInspectionTest.kt | 15 +++++++++++++++ 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/main/java/de/platon42/intellij/plugins/m68k/inspections/M68kDeadWriteInspection.kt b/src/main/java/de/platon42/intellij/plugins/m68k/inspections/M68kDeadWriteInspection.kt index 678c2de..47fc815 100644 --- a/src/main/java/de/platon42/intellij/plugins/m68k/inspections/M68kDeadWriteInspection.kt +++ b/src/main/java/de/platon42/intellij/plugins/m68k/inspections/M68kDeadWriteInspection.kt @@ -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() } diff --git a/src/main/java/de/platon42/intellij/plugins/m68k/inspections/M68kSyntaxInspection.kt b/src/main/java/de/platon42/intellij/plugins/m68k/inspections/M68kSyntaxInspection.kt index fa0ed4d..2fd52ba 100644 --- a/src/main/java/de/platon42/intellij/plugins/m68k/inspections/M68kSyntaxInspection.kt +++ b/src/main/java/de/platon42/intellij/plugins/m68k/inspections/M68kSyntaxInspection.kt @@ -132,8 +132,7 @@ class M68kSyntaxInspection : AbstractBaseM68kLocalInspectionTool() { ) ) } - - + val supportedOpSizes = findSupportedOpSizes(matchingModeIsaDataIgnoringSize, op1, op2, specialReg) return arrayOf( when (supportedOpSizes) { diff --git a/src/main/resources/inspectionDescriptions/M68kDeadWrite.html b/src/main/resources/inspectionDescriptions/M68kDeadWrite.html index d6b95b1..5d36d20 100644 --- a/src/main/resources/inspectionDescriptions/M68kDeadWrite.html +++ b/src/main/resources/inspectionDescriptions/M68kDeadWrite.html @@ -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).

Note: As there is no evaluation of macros right now, the inspection might report some false positives.

diff --git a/src/test/java/de/platon42/intellij/plugins/m68k/inspections/M68kDeadWriteInspectionTest.kt b/src/test/java/de/platon42/intellij/plugins/m68k/inspections/M68kDeadWriteInspectionTest.kt index e51952d..fb5815a 100644 --- a/src/test/java/de/platon42/intellij/plugins/m68k/inspections/M68kDeadWriteInspectionTest.kt +++ b/src/test/java/de/platon42/intellij/plugins/m68k/inspections/M68kDeadWriteInspectionTest.kt @@ -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() + } } \ No newline at end of file