@specs-feup/clava-misra 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitignore +8 -0
- package/README.md +53 -19
- package/dist/MISRA.d.ts +28 -10
- package/dist/MISRA.d.ts.map +1 -1
- package/dist/MISRA.js +30 -10
- package/dist/MISRA.js.map +1 -1
- package/dist/MISRAContext.d.ts +65 -11
- package/dist/MISRAContext.d.ts.map +1 -1
- package/dist/MISRAContext.js +131 -35
- package/dist/MISRAContext.js.map +1 -1
- package/dist/MISRARule.d.ts +38 -25
- package/dist/MISRARule.d.ts.map +1 -1
- package/dist/MISRARule.js +40 -18
- package/dist/MISRARule.js.map +1 -1
- package/dist/MISRATool.d.ts +46 -5
- package/dist/MISRATool.d.ts.map +1 -1
- package/dist/MISRATool.js +118 -45
- package/dist/MISRATool.js.map +1 -1
- package/dist/StandardGuideline.d.ts +22 -0
- package/dist/StandardGuideline.d.ts.map +1 -0
- package/dist/StandardGuideline.js +12 -0
- package/dist/StandardGuideline.js.map +1 -0
- package/dist/ast-visitor/Context.d.ts +11 -0
- package/dist/ast-visitor/Context.d.ts.map +1 -0
- package/dist/ast-visitor/Context.js +15 -0
- package/dist/ast-visitor/Context.js.map +1 -0
- package/dist/ast-visitor/Visit.d.ts +23 -0
- package/dist/ast-visitor/Visit.d.ts.map +1 -0
- package/dist/ast-visitor/Visit.js +18 -0
- package/dist/ast-visitor/Visit.js.map +1 -0
- package/dist/ast-visitor/VisitWithContext.d.ts +32 -0
- package/dist/ast-visitor/VisitWithContext.d.ts.map +1 -0
- package/dist/ast-visitor/VisitWithContext.js +26 -0
- package/dist/ast-visitor/VisitWithContext.js.map +1 -0
- package/dist/main.js +1 -2
- package/dist/main.js.map +1 -1
- package/dist/rules/Section13_SideEffects/Rule_13_6_SafeSizeOfOperand.d.ts +27 -0
- package/dist/rules/Section13_SideEffects/Rule_13_6_SafeSizeOfOperand.d.ts.map +1 -0
- package/dist/rules/Section13_SideEffects/Rule_13_6_SafeSizeOfOperand.js +98 -0
- package/dist/rules/Section13_SideEffects/Rule_13_6_SafeSizeOfOperand.js.map +1 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.d.ts +45 -6
- package/dist/rules/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.d.ts.map +1 -1
- package/dist/rules/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.js +91 -8
- package/dist/rules/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.js.map +1 -1
- package/dist/rules/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.d.ts +15 -5
- package/dist/rules/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.d.ts.map +1 -1
- package/dist/rules/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.js +20 -6
- package/dist/rules/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.js.map +1 -1
- package/dist/rules/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.d.ts +11 -5
- package/dist/rules/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.d.ts.map +1 -1
- package/dist/rules/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.js +13 -10
- package/dist/rules/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.js.map +1 -1
- package/dist/rules/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.d.ts +11 -6
- package/dist/rules/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.d.ts.map +1 -1
- package/dist/rules/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.js +19 -11
- package/dist/rules/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.js.map +1 -1
- package/dist/rules/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.d.ts +15 -5
- package/dist/rules/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.d.ts.map +1 -1
- package/dist/rules/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.js +24 -10
- package/dist/rules/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.js.map +1 -1
- package/dist/rules/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.d.ts +22 -6
- package/dist/rules/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.d.ts.map +1 -1
- package/dist/rules/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.js +37 -10
- package/dist/rules/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.js.map +1 -1
- package/dist/rules/Section17_Functions/Rule_17_3_ImplicitFunction.d.ts +66 -0
- package/dist/rules/Section17_Functions/Rule_17_3_ImplicitFunction.d.ts.map +1 -0
- package/dist/rules/Section17_Functions/Rule_17_3_ImplicitFunction.js +209 -0
- package/dist/rules/Section17_Functions/Rule_17_3_ImplicitFunction.js.map +1 -0
- package/dist/rules/Section17_Functions/Rule_17_4_NonVoidReturn.d.ts +37 -12
- package/dist/rules/Section17_Functions/Rule_17_4_NonVoidReturn.d.ts.map +1 -1
- package/dist/rules/Section17_Functions/Rule_17_4_NonVoidReturn.js +112 -39
- package/dist/rules/Section17_Functions/Rule_17_4_NonVoidReturn.js.map +1 -1
- package/dist/rules/Section17_Functions/Rule_17_6_StaticArraySizeParam.d.ts +15 -5
- package/dist/rules/Section17_Functions/Rule_17_6_StaticArraySizeParam.d.ts.map +1 -1
- package/dist/rules/Section17_Functions/Rule_17_6_StaticArraySizeParam.js +21 -7
- package/dist/rules/Section17_Functions/Rule_17_6_StaticArraySizeParam.js.map +1 -1
- package/dist/rules/Section17_Functions/Rule_17_7_UnusedReturnValue.d.ts +11 -6
- package/dist/rules/Section17_Functions/Rule_17_7_UnusedReturnValue.d.ts.map +1 -1
- package/dist/rules/Section17_Functions/Rule_17_7_UnusedReturnValue.js +17 -8
- package/dist/rules/Section17_Functions/Rule_17_7_UnusedReturnValue.js.map +1 -1
- package/dist/rules/Section21-StandardLibraries/DisallowedStdLibFunctionRule.d.ts +105 -0
- package/dist/rules/Section21-StandardLibraries/DisallowedStdLibFunctionRule.d.ts.map +1 -0
- package/dist/rules/Section21-StandardLibraries/DisallowedStdLibFunctionRule.js +258 -0
- package/dist/rules/Section21-StandardLibraries/DisallowedStdLibFunctionRule.js.map +1 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_10_NoTimeDateFunctions.d.ts +25 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_10_NoTimeDateFunctions.d.ts.map +1 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_10_NoTimeDateFunctions.js +27 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_10_NoTimeDateFunctions.js.map +1 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_11_NoTgmathFunctions.d.ts +29 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_11_NoTgmathFunctions.d.ts.map +1 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_11_NoTgmathFunctions.js +31 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_11_NoTgmathFunctions.js.map +1 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_3_NoDynamicMemory.d.ts +25 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_3_NoDynamicMemory.d.ts.map +1 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_3_NoDynamicMemory.js +27 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_3_NoDynamicMemory.js.map +1 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_6_NoStdIOFunctions.d.ts +25 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_6_NoStdIOFunctions.d.ts.map +1 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_6_NoStdIOFunctions.js +27 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_6_NoStdIOFunctions.js.map +1 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_7_NoNumericStringConversions.d.ts +25 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_7_NoNumericStringConversions.d.ts.map +1 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_7_NoNumericStringConversions.js +27 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_7_NoNumericStringConversions.js.map +1 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_8_NoProcessControlFunctions.d.ts +30 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_8_NoProcessControlFunctions.d.ts.map +1 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_8_NoProcessControlFunctions.js +32 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_8_NoProcessControlFunctions.js.map +1 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_9_NoGenericSearchOrSort.d.ts +25 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_9_NoGenericSearchOrSort.d.ts.map +1 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_9_NoGenericSearchOrSort.js +27 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_9_NoGenericSearchOrSort.js.map +1 -0
- package/dist/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.d.ts +6 -14
- package/dist/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.d.ts.map +1 -1
- package/dist/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.js +17 -27
- package/dist/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.js.map +1 -1
- package/dist/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.d.ts +13 -7
- package/dist/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.d.ts.map +1 -1
- package/dist/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.js +31 -17
- package/dist/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.js.map +1 -1
- package/dist/rules/Section2_UnusedCode/Rule_2_6_UnusedLabels.d.ts +26 -7
- package/dist/rules/Section2_UnusedCode/Rule_2_6_UnusedLabels.d.ts.map +1 -1
- package/dist/rules/Section2_UnusedCode/Rule_2_6_UnusedLabels.js +32 -14
- package/dist/rules/Section2_UnusedCode/Rule_2_6_UnusedLabels.js.map +1 -1
- package/dist/rules/Section2_UnusedCode/Rule_2_7_UnusedParameters.d.ts +48 -6
- package/dist/rules/Section2_UnusedCode/Rule_2_7_UnusedParameters.d.ts.map +1 -1
- package/dist/rules/Section2_UnusedCode/Rule_2_7_UnusedParameters.js +84 -34
- package/dist/rules/Section2_UnusedCode/Rule_2_7_UnusedParameters.js.map +1 -1
- package/dist/rules/Section3_Comments/Rule_3_1_CommentSequences.d.ts +24 -5
- package/dist/rules/Section3_Comments/Rule_3_1_CommentSequences.d.ts.map +1 -1
- package/dist/rules/Section3_Comments/Rule_3_1_CommentSequences.js +27 -7
- package/dist/rules/Section3_Comments/Rule_3_1_CommentSequences.js.map +1 -1
- package/dist/rules/Section5_Identifiers/IdentifierRenameRule.d.ts +46 -0
- package/dist/rules/Section5_Identifiers/IdentifierRenameRule.d.ts.map +1 -0
- package/dist/rules/Section5_Identifiers/IdentifierRenameRule.js +40 -0
- package/dist/rules/Section5_Identifiers/IdentifierRenameRule.js.map +1 -0
- package/dist/rules/Section5_Identifiers/Rule_5_1_DistinctExternalIdentifiers.d.ts +25 -0
- package/dist/rules/Section5_Identifiers/Rule_5_1_DistinctExternalIdentifiers.d.ts.map +1 -0
- package/dist/rules/Section5_Identifiers/Rule_5_1_DistinctExternalIdentifiers.js +46 -0
- package/dist/rules/Section5_Identifiers/Rule_5_1_DistinctExternalIdentifiers.js.map +1 -0
- package/dist/rules/Section5_Identifiers/Rule_5_6_UniqueTypedefNames.d.ts +26 -0
- package/dist/rules/Section5_Identifiers/Rule_5_6_UniqueTypedefNames.d.ts.map +1 -0
- package/dist/rules/Section5_Identifiers/Rule_5_6_UniqueTypedefNames.js +54 -0
- package/dist/rules/Section5_Identifiers/Rule_5_6_UniqueTypedefNames.js.map +1 -0
- package/dist/rules/Section5_Identifiers/Rule_5_7_UniqueTagNames.d.ts +27 -0
- package/dist/rules/Section5_Identifiers/Rule_5_7_UniqueTagNames.d.ts.map +1 -0
- package/dist/rules/Section5_Identifiers/Rule_5_7_UniqueTagNames.js +55 -0
- package/dist/rules/Section5_Identifiers/Rule_5_7_UniqueTagNames.js.map +1 -0
- package/dist/rules/Section5_Identifiers/Rule_5_8_UniqueExternalLinkIdentifiers.d.ts +24 -0
- package/dist/rules/Section5_Identifiers/Rule_5_8_UniqueExternalLinkIdentifiers.d.ts.map +1 -0
- package/dist/rules/Section5_Identifiers/Rule_5_8_UniqueExternalLinkIdentifiers.js +42 -0
- package/dist/rules/Section5_Identifiers/Rule_5_8_UniqueExternalLinkIdentifiers.js.map +1 -0
- package/dist/rules/Section5_Identifiers/Rule_5_9_UniqueInternalLinkIdentifiers.d.ts +24 -0
- package/dist/rules/Section5_Identifiers/Rule_5_9_UniqueInternalLinkIdentifiers.d.ts.map +1 -0
- package/dist/rules/Section5_Identifiers/Rule_5_9_UniqueInternalLinkIdentifiers.js +42 -0
- package/dist/rules/Section5_Identifiers/Rule_5_9_UniqueInternalLinkIdentifiers.js.map +1 -0
- package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_6_SingleExternalDefinition.d.ts +35 -0
- package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_6_SingleExternalDefinition.d.ts.map +1 -0
- package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_6_SingleExternalDefinition.js +98 -0
- package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_6_SingleExternalDefinition.js.map +1 -0
- package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_7_RestrictExternalLinkage.d.ts +35 -0
- package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_7_RestrictExternalLinkage.d.ts.map +1 -0
- package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_7_RestrictExternalLinkage.js +76 -0
- package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_7_RestrictExternalLinkage.js.map +1 -0
- package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_9_BlockScopeDefinition.d.ts +32 -0
- package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_9_BlockScopeDefinition.d.ts.map +1 -0
- package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_9_BlockScopeDefinition.js +57 -0
- package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_9_BlockScopeDefinition.js.map +1 -0
- package/dist/rules/UserConfigurableRule.d.ts +55 -0
- package/dist/rules/UserConfigurableRule.d.ts.map +1 -0
- package/dist/rules/UserConfigurableRule.js +16 -0
- package/dist/rules/UserConfigurableRule.js.map +1 -0
- package/dist/rules/index.d.ts +11 -18
- package/dist/rules/index.d.ts.map +1 -1
- package/dist/rules/index.js +47 -7
- package/dist/rules/index.js.map +1 -1
- package/dist/tests/Section17_Functions/misra_config.json +10 -0
- package/dist/tests/Section21-StandardLibraries/misra_config.json +88 -0
- package/dist/tests/Section21-StandardLibraries/problematic_misra_config.json +19 -0
- package/dist/tests/utils.d.ts +6 -3
- package/dist/tests/utils.d.ts.map +1 -1
- package/dist/tests/utils.js +33 -7
- package/dist/tests/utils.js.map +1 -1
- package/dist/utils/CallUtils.d.ts +15 -0
- package/dist/utils/CallUtils.d.ts.map +1 -0
- package/dist/utils/CallUtils.js +34 -0
- package/dist/utils/CallUtils.js.map +1 -0
- package/dist/utils/CommentUtils.d.ts +21 -0
- package/dist/utils/CommentUtils.d.ts.map +1 -0
- package/dist/utils/CommentUtils.js +27 -0
- package/dist/utils/CommentUtils.js.map +1 -0
- package/dist/utils/FileUtils.d.ts +67 -0
- package/dist/utils/FileUtils.d.ts.map +1 -0
- package/dist/utils/FileUtils.js +144 -0
- package/dist/utils/FileUtils.js.map +1 -0
- package/dist/utils/FunctionUtils.d.ts +47 -0
- package/dist/utils/FunctionUtils.d.ts.map +1 -0
- package/dist/utils/FunctionUtils.js +87 -0
- package/dist/utils/FunctionUtils.js.map +1 -0
- package/dist/utils/IdentifierUtils.d.ts +63 -0
- package/dist/utils/IdentifierUtils.d.ts.map +1 -0
- package/dist/utils/IdentifierUtils.js +133 -0
- package/dist/utils/IdentifierUtils.js.map +1 -0
- package/dist/utils/JoinpointUtils.d.ts +36 -0
- package/dist/utils/JoinpointUtils.d.ts.map +1 -0
- package/dist/utils/JoinpointUtils.js +63 -0
- package/dist/utils/JoinpointUtils.js.map +1 -0
- package/dist/utils/ProgramUtils.d.ts +39 -0
- package/dist/utils/ProgramUtils.d.ts.map +1 -0
- package/dist/utils/ProgramUtils.js +97 -0
- package/dist/utils/ProgramUtils.js.map +1 -0
- package/dist/utils/SwitchUtils.d.ts +21 -0
- package/dist/utils/SwitchUtils.d.ts.map +1 -0
- package/dist/utils/SwitchUtils.js +47 -0
- package/dist/utils/SwitchUtils.js.map +1 -0
- package/dist/utils/TypeDeclUtils.d.ts +35 -0
- package/dist/utils/TypeDeclUtils.d.ts.map +1 -0
- package/dist/utils/TypeDeclUtils.js +78 -0
- package/dist/utils/TypeDeclUtils.js.map +1 -0
- package/dist/utils/VarUtils.d.ts +51 -0
- package/dist/utils/VarUtils.d.ts.map +1 -0
- package/dist/utils/VarUtils.js +91 -0
- package/dist/utils/VarUtils.js.map +1 -0
- package/package.json +16 -7
- package/src/MISRA.ts +33 -17
- package/src/MISRAContext.ts +128 -30
- package/src/MISRARule.ts +61 -29
- package/src/MISRATool.ts +126 -42
- package/src/StandardGuideline.ts +23 -0
- package/src/ast-visitor/Context.ts +16 -0
- package/src/ast-visitor/Visit.ts +26 -0
- package/src/ast-visitor/VisitWithContext.ts +42 -0
- package/src/main.ts +1 -4
- package/src/rules/Section13_SideEffects/Rule_13_6_SafeSizeOfOperand.ts +114 -0
- package/src/rules/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.ts +103 -13
- package/src/rules/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.ts +24 -10
- package/src/rules/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.ts +17 -8
- package/src/rules/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.ts +20 -12
- package/src/rules/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.ts +23 -12
- package/src/rules/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.ts +44 -13
- package/src/rules/Section17_Functions/Rule_17_3_ImplicitFunction.ts +153 -104
- package/src/rules/Section17_Functions/Rule_17_4_NonVoidReturn.ts +114 -44
- package/src/rules/Section17_Functions/Rule_17_6_StaticArraySizeParam.ts +27 -10
- package/src/rules/Section17_Functions/Rule_17_7_UnusedReturnValue.ts +20 -12
- package/src/rules/Section21-StandardLibraries/DisallowedStdLibFunctionRule.ts +317 -0
- package/src/rules/Section21-StandardLibraries/Rule_21_10_NoTimeDateFunctions.ts +30 -0
- package/src/rules/Section21-StandardLibraries/Rule_21_11_NoTgmathFunctions.ts +35 -0
- package/src/rules/Section21-StandardLibraries/Rule_21_3_NoDynamicMemory.ts +30 -0
- package/src/rules/Section21-StandardLibraries/Rule_21_6_NoStdIOFunctions.ts +30 -0
- package/src/rules/Section21-StandardLibraries/Rule_21_7_NoNumericStringConversions.ts +29 -0
- package/src/rules/Section21-StandardLibraries/Rule_21_8_NoProcessControlFunctions.ts +36 -0
- package/src/rules/Section21-StandardLibraries/Rule_21_9_NoGenericSearchOrSort.ts +30 -0
- package/src/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.ts +14 -29
- package/src/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.ts +33 -19
- package/src/rules/Section2_UnusedCode/Rule_2_6_UnusedLabels.ts +33 -20
- package/src/rules/Section2_UnusedCode/Rule_2_7_UnusedParameters.ts +90 -45
- package/src/rules/Section3_Comments/Rule_3_1_CommentSequences.ts +27 -8
- package/src/rules/Section5_Identifiers/IdentifierRenameRule.ts +63 -0
- package/src/rules/Section5_Identifiers/Rule_5_1_DistinctExternalIdentifiers.ts +52 -0
- package/src/rules/Section5_Identifiers/Rule_5_6_UniqueTypedefNames.ts +62 -0
- package/src/rules/Section5_Identifiers/Rule_5_7_UniqueTagNames.ts +61 -0
- package/src/rules/Section5_Identifiers/Rule_5_8_UniqueExternalLinkIdentifiers.ts +47 -0
- package/src/rules/Section5_Identifiers/Rule_5_9_UniqueInternalLinkIdentifiers.ts +47 -0
- package/src/rules/Section8_DeclarationsAndDefinitions/Rule_8_6_SingleExternalDefinition.ts +118 -0
- package/src/rules/Section8_DeclarationsAndDefinitions/Rule_8_7_RestrictExternalLinkage.ts +89 -0
- package/src/rules/Section8_DeclarationsAndDefinitions/Rule_8_9_BlockScopeDefinition.ts +65 -0
- package/src/rules/UserConfigurableRule.ts +60 -0
- package/src/rules/index.ts +45 -7
- package/src/tests/Section13_SideEffects/Rule_13_6_SafeSizeOfOperand.test.ts +114 -0
- package/src/tests/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.test.ts +7 -5
- package/src/tests/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.test.ts +40 -13
- package/src/tests/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.test.ts +10 -12
- package/src/tests/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.test.ts +5 -5
- package/src/tests/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.test.ts +5 -5
- package/src/tests/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.test.ts +5 -5
- package/src/tests/Section17_Functions/Rule_17_3_ImplicitFunctions.test.ts +68 -40
- package/src/tests/Section17_Functions/Rule_17_3_ImplicitFunctions_MissingConfig.test.ts +98 -0
- package/src/tests/Section17_Functions/Rule_17_3_ImplicitFunctions_ProblematicConfig.test.ts +71 -0
- package/src/tests/Section17_Functions/Rule_17_4_NonVoidReturn.test.ts +103 -49
- package/src/tests/Section17_Functions/Rule_17_4_NonVoidReturn_MissingConfig.test.ts +7 -7
- package/src/tests/Section17_Functions/Rule_17_6_StaticArraySizeParam.test.ts +36 -7
- package/src/tests/Section17_Functions/Rule_17_7_UnusedReturnValue.test.ts +25 -21
- package/src/tests/Section17_Functions/misra_config.json +4 -3
- package/src/tests/Section21-StandardLibraries/Rule_21_10_NoTimeDateFunctions.test.ts +62 -0
- package/src/tests/Section21-StandardLibraries/Rule_21_11_NoTgmathFunctions.test.ts +67 -0
- package/src/tests/Section21-StandardLibraries/Rule_21_3_NoDynamicMemory.test.ts +84 -0
- package/src/tests/Section21-StandardLibraries/Rule_21_3_NoDynamicMemory_MissingConfig.test.ts +33 -0
- package/src/tests/Section21-StandardLibraries/Rule_21_3_NoDynamicMemory_ProblematicConfig.test.ts +71 -0
- package/src/tests/Section21-StandardLibraries/Rule_21_6_NoStdIOFunctions.test.ts +63 -0
- package/src/tests/Section21-StandardLibraries/Rule_21_7_NoNumericStringConversions.test.ts +91 -0
- package/src/tests/Section21-StandardLibraries/Rule_21_8_NoProcessControlFunctions.test.ts +65 -0
- package/src/tests/Section21-StandardLibraries/Rule_21_9_NoGenericSearchOrSort.test.ts +89 -0
- package/src/tests/Section21-StandardLibraries/misra_config.json +88 -0
- package/src/tests/Section21-StandardLibraries/problematic_misra_config.json +19 -0
- package/src/tests/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.test.ts +148 -113
- package/src/tests/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.test.ts +243 -163
- package/src/tests/Section2_UnusedCode/Rule_2_6_UnusedLabels.test.ts +32 -20
- package/src/tests/Section2_UnusedCode/Rule_2_7_UnusedParameters.test.ts +36 -30
- package/src/tests/Section3_Comments/Rule_3_1_CommentSequences.test.ts +37 -8
- package/src/tests/Section5_Identifiers/Rule_5_1_DistinctExternalIdentifiers.test.ts +78 -0
- package/src/tests/Section5_Identifiers/Rule_5_6_UniqueTypedefNames.test.ts +120 -0
- package/src/tests/Section5_Identifiers/Rule_5_7_UniqueTagNames.test.ts +51 -0
- package/src/tests/Section5_Identifiers/Rule_5_8_UniqueExternalLinkIdentifiers.test.ts +73 -0
- package/src/tests/Section5_Identifiers/Rule_5_9_UniqueInternalLinkIdentifiers.test.ts +97 -0
- package/src/tests/Section8_DeclarationsAndDefinitions/Rule_8_6_SingleExternalDefinition.test.ts +160 -0
- package/src/tests/Section8_DeclarationsAndDefinitions/Rule_8_7_RestrictExternalLinkage.test.ts +46 -0
- package/src/tests/Section8_DeclarationsAndDefinitions/Rule_8_9_BlockScopeDefinition.test.ts +69 -0
- package/src/tests/utils.ts +32 -7
- package/src/utils/CallUtils.ts +37 -0
- package/src/utils/CommentUtils.ts +29 -0
- package/src/utils/FileUtils.ts +169 -0
- package/src/utils/FunctionUtils.ts +97 -0
- package/src/utils/IdentifierUtils.ts +142 -0
- package/src/utils/JoinpointUtils.ts +70 -0
- package/src/utils/ProgramUtils.ts +107 -0
- package/src/utils/SwitchUtils.ts +52 -0
- package/src/utils/TypeDeclUtils.ts +88 -0
- package/src/utils/VarUtils.ts +102 -0
- package/tsconfig.json +2 -1
- package/src/rules/Section20-PreprocessingDirectives/Rule_20_2_InvalidHeaderFileName.ts +0 -120
- package/src/rules/Section3_Comments/Rule_3_2_LineSplicing.ts +0 -36
- package/src/utils/utils.ts +0 -280
|
@@ -1,40 +1,53 @@
|
|
|
1
|
-
import { Joinpoint,
|
|
1
|
+
import { Joinpoint, DeclStmt } from "@specs-feup/clava/api/Joinpoints.js";
|
|
2
2
|
import MISRARule from "../../MISRARule.js";
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { AnalysisType, MISRATransformationReport, MISRATransformationType } from "../../MISRA.js";
|
|
4
|
+
import { hasTypeDefDecl, isTypeDeclUsed } from "../../utils/TypeDeclUtils.js";
|
|
5
|
+
import { isTagDecl, TagDecl } from "../../utils/JoinpointUtils.js";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* MISRA-C Rule 2.4: A project should not contain unused tag declarations.
|
|
9
9
|
*/
|
|
10
10
|
export default class Rule_2_4_UnusedTagDecl extends MISRARule {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Scope of analysis
|
|
13
|
+
*/
|
|
14
|
+
readonly analysisType = AnalysisType.SYSTEM;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @returns Rule identifier according to MISRA-C:2012
|
|
18
|
+
*/
|
|
19
|
+
override get name(): string {
|
|
20
|
+
return "2.4";
|
|
15
21
|
}
|
|
16
22
|
|
|
17
23
|
/**
|
|
18
24
|
* Checks if the given joinpoint is an unused tag declaration
|
|
19
|
-
* A tag is considered
|
|
25
|
+
* A tag is considered unused if it has no references in the code or if it's only used within a typedef
|
|
20
26
|
*
|
|
21
27
|
* @param $jp - Joinpoint to analyze
|
|
22
28
|
* @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
|
|
23
29
|
* @returns Returns true if the joinpoint violates the rule, false otherwise
|
|
24
30
|
*/
|
|
25
31
|
match($jp: Joinpoint, logErrors: boolean = false): boolean {
|
|
26
|
-
if (!($jp instanceof
|
|
32
|
+
if (!(isTagDecl($jp) || ($jp instanceof DeclStmt && $jp.decls.length === 1))) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if ($jp instanceof DeclStmt && !isTagDecl($jp.decls[0])) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
27
39
|
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
|
|
40
|
+
const tagJp: TagDecl = $jp instanceof DeclStmt ? $jp.decls[0] as TagDecl : $jp;
|
|
41
|
+
const containsTypeDecl = hasTypeDefDecl(tagJp);
|
|
42
|
+
const jpName = tagJp.name;
|
|
43
|
+
if (containsTypeDecl && (jpName === undefined || jpName === null || (jpName as string).trim().length === 0)) {
|
|
31
44
|
return false;
|
|
32
45
|
}
|
|
33
46
|
|
|
34
|
-
const isUnused =
|
|
47
|
+
const isUnused = !isTypeDeclUsed(tagJp);
|
|
35
48
|
if (isUnused && logErrors) {
|
|
36
|
-
this.logMISRAError(
|
|
37
|
-
containsTypeDecl ? `The tag '${
|
|
49
|
+
this.logMISRAError(tagJp,
|
|
50
|
+
containsTypeDecl ? `The tag '${tagJp.name}' is declared but only used in a typedef.` : `The tag '${tagJp.name}' is declared but not used.`);
|
|
38
51
|
}
|
|
39
52
|
return isUnused;
|
|
40
53
|
}
|
|
@@ -47,12 +60,13 @@ export default class Rule_2_4_UnusedTagDecl extends MISRARule {
|
|
|
47
60
|
* @param $jp - Joinpoint to transform
|
|
48
61
|
* @returns Report detailing the transformation result
|
|
49
62
|
*/
|
|
50
|
-
|
|
63
|
+
apply($jp: Joinpoint): MISRATransformationReport {
|
|
51
64
|
if (!this.match($jp))
|
|
52
65
|
return new MISRATransformationReport(MISRATransformationType.NoChange);
|
|
53
66
|
|
|
54
|
-
|
|
55
|
-
|
|
67
|
+
const tagJp: TagDecl = $jp instanceof DeclStmt ? $jp.decls[0] as TagDecl : $jp as TagDecl;
|
|
68
|
+
if (hasTypeDefDecl(tagJp)) {
|
|
69
|
+
(tagJp).setName('');
|
|
56
70
|
return new MISRATransformationReport(MISRATransformationType.DescendantChange);
|
|
57
71
|
}
|
|
58
72
|
$jp.detach();
|
|
@@ -1,44 +1,57 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FunctionJp, Joinpoint } from "@specs-feup/clava/api/Joinpoints.js";
|
|
2
2
|
import MISRARule from "../../MISRARule.js";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import { MISRATransformationReport, MISRATransformationType } from "../../MISRA.js";
|
|
3
|
+
import { AnalysisType, MISRATransformationReport, MISRATransformationType } from "../../MISRA.js";
|
|
4
|
+
import { getUnusedLabels } from "../../utils/FunctionUtils.js";
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
|
-
* Rule 2.6:
|
|
9
|
-
*
|
|
7
|
+
* MISRA-C Rule 2.6: A function should not contain unused label declarations.
|
|
8
|
+
*
|
|
10
9
|
*/
|
|
11
10
|
export default class Rule_2_6_UnusedLabels extends MISRARule {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
11
|
+
/**
|
|
12
|
+
* Scope of analysis
|
|
13
|
+
*/
|
|
14
|
+
readonly analysisType = AnalysisType.SINGLE_TRANSLATION_UNIT;
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
/**
|
|
17
|
+
* @returns Rule identifier according to MISRA-C:2012
|
|
18
|
+
*/
|
|
19
|
+
override get name(): string {
|
|
20
|
+
return "2.6";
|
|
22
21
|
}
|
|
23
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Checks if the given joinpoint represents a function with unused labels.
|
|
25
|
+
* A tag is considered unused if it is declared but not referenced by any goto statement.
|
|
26
|
+
*
|
|
27
|
+
* @param $jp - Joinpoint to analyze
|
|
28
|
+
* @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
|
|
29
|
+
* @returns Returns true if the joinpoint violates the rule, false otherwise
|
|
30
|
+
*/
|
|
24
31
|
match($jp: Joinpoint, logErrors: boolean = false): boolean {
|
|
25
32
|
if (!($jp instanceof FunctionJp))
|
|
26
33
|
return false;
|
|
27
34
|
|
|
28
|
-
const unusedLabels =
|
|
35
|
+
const unusedLabels = getUnusedLabels($jp);
|
|
29
36
|
if (logErrors) {
|
|
30
37
|
unusedLabels.forEach(label =>
|
|
31
|
-
this.logMISRAError(label, `Label ${label.decl.name} is unused in function ${$jp.name}.`)
|
|
38
|
+
this.logMISRAError(label, `Label '${label.decl.name}' is unused in function ${$jp.name}.`)
|
|
32
39
|
)
|
|
33
40
|
}
|
|
34
41
|
return unusedLabels.length > 0;
|
|
35
42
|
}
|
|
36
43
|
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Removes all unused labels if the provided joinpoint represents a function
|
|
46
|
+
*
|
|
47
|
+
* @param $jp - Joinpoint to transform
|
|
48
|
+
* @returns Report detailing the transformation result
|
|
49
|
+
*/
|
|
50
|
+
apply($jp: Joinpoint): MISRATransformationReport {
|
|
51
|
+
if (!this.match($jp))
|
|
39
52
|
return new MISRATransformationReport(MISRATransformationType.NoChange);
|
|
40
53
|
|
|
41
|
-
const unusedLabels =
|
|
54
|
+
const unusedLabels = getUnusedLabels($jp as FunctionJp);
|
|
42
55
|
for (const label of unusedLabels) {
|
|
43
56
|
label.detach();
|
|
44
57
|
}
|
|
@@ -1,67 +1,112 @@
|
|
|
1
|
-
import { FunctionJp, Joinpoint, Param, Varref, Call } from "@specs-feup/clava/api/Joinpoints.js";
|
|
1
|
+
import { FunctionJp, Joinpoint, Param, Varref, Call, Program } from "@specs-feup/clava/api/Joinpoints.js";
|
|
2
2
|
import MISRARule from "../../MISRARule.js";
|
|
3
|
-
import MISRAContext from "../../MISRAContext.js";
|
|
4
3
|
import Query from "@specs-feup/lara/api/weaver/Query.js";
|
|
5
|
-
import { MISRATransformationReport, MISRATransformationType } from "../../MISRA.js";
|
|
6
|
-
import { getParamReferences } from "../../utils/
|
|
7
|
-
import ClavaJoinPoints from "@specs-feup/clava/api/clava/ClavaJoinPoints.js";
|
|
4
|
+
import { AnalysisType, MISRATransformationReport, MISRATransformationType } from "../../MISRA.js";
|
|
5
|
+
import { getDirectParamReferences, getParamReferences, getVLAFieldParamReferences } from "../../utils/FunctionUtils.js";
|
|
8
6
|
|
|
7
|
+
/**
|
|
8
|
+
* MISRA-C Rule 2.7: There should be no unused parameters in functions.
|
|
9
|
+
*/
|
|
9
10
|
export default class Rule_2_7_UnusedParameters extends MISRARule {
|
|
10
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Scope of analysis
|
|
13
|
+
*/
|
|
14
|
+
readonly analysisType = AnalysisType.SINGLE_TRANSLATION_UNIT;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @returns Rule identifier according to MISRA-C:2012
|
|
18
|
+
*/
|
|
19
|
+
override get name(): string {
|
|
20
|
+
return "2.7";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
#unusedParams: Param[] = [];
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Checks if the program contains function with unused parameters.
|
|
27
|
+
* A parameter is considered unused if it is never referenced anywhere in the function.
|
|
28
|
+
*
|
|
29
|
+
* @param $jp - Joinpoint to analyze
|
|
30
|
+
* @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
|
|
31
|
+
* @returns Returns true if the joinpoint violates the rule, false otherwise
|
|
32
|
+
*/
|
|
33
|
+
match($jp: Joinpoint, logErrors: boolean = false): boolean {
|
|
34
|
+
if (!($jp instanceof FunctionJp && $jp.isImplementation))
|
|
35
|
+
return false;
|
|
36
|
+
|
|
37
|
+
const nonCompliant = $jp.params.some((param) => getParamReferences(param, $jp).length === 0);
|
|
38
|
+
if (logErrors && nonCompliant) {
|
|
39
|
+
this.#unusedParams = this.getUnusedParams($jp);
|
|
40
|
+
this.#unusedParams.forEach(param => this.logMISRAError(param, `Parameter '${param.name}' is unused in function '${$jp.name}'.`));
|
|
41
|
+
}
|
|
42
|
+
return nonCompliant;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Removes all unused parameters from functions in the program
|
|
47
|
+
*
|
|
48
|
+
* @param $jp - Joinpoint to transform
|
|
49
|
+
* @returns Report detailing the transformation result
|
|
50
|
+
*/
|
|
51
|
+
apply($jp: Joinpoint): MISRATransformationReport {
|
|
52
|
+
if (!this.match($jp))
|
|
53
|
+
return new MISRATransformationReport(MISRATransformationType.NoChange);
|
|
54
|
+
|
|
55
|
+
const funcJp = $jp as FunctionJp;
|
|
56
|
+
const usedParams = this.getUsedParams(funcJp);
|
|
57
|
+
const unusedParamsPosition = this.getUnusedParamsPositions(funcJp);
|
|
58
|
+
const calls = Query.search(Call, {function: jp => jp?.astId === funcJp.astId}).get();
|
|
59
|
+
|
|
60
|
+
funcJp.setParams(usedParams);
|
|
11
61
|
|
|
12
|
-
|
|
13
|
-
|
|
62
|
+
for (const call of calls) {
|
|
63
|
+
const unusedArgs = unusedParamsPosition.map(i => call.args[i]);
|
|
64
|
+
unusedArgs.forEach(arg => arg.detach());
|
|
65
|
+
}
|
|
66
|
+
return new MISRATransformationReport(MISRATransformationType.DescendantChange);
|
|
14
67
|
}
|
|
15
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Gets all unused parameters from a function joinpoint
|
|
71
|
+
*
|
|
72
|
+
* @param func - Function joinpoint to analyze
|
|
73
|
+
* @returns Returns a list of all unused parameters from a function.
|
|
74
|
+
*/
|
|
16
75
|
private getUnusedParams(func: FunctionJp): Param[] {
|
|
17
|
-
return func.params.filter(
|
|
76
|
+
return func.params.filter((param) => {
|
|
77
|
+
if (getDirectParamReferences(param, func).length > 0) return false;
|
|
78
|
+
return getVLAFieldParamReferences(param, func).length === 0;
|
|
79
|
+
});
|
|
18
80
|
}
|
|
19
81
|
|
|
82
|
+
/**
|
|
83
|
+
* Gets all used parameters from a function joinpoint
|
|
84
|
+
*
|
|
85
|
+
* @param func - Function joinpoint to analyze
|
|
86
|
+
* @returns Returns a list of parameters that are used within a function.
|
|
87
|
+
*/
|
|
20
88
|
private getUsedParams(func: FunctionJp): Param[] {
|
|
21
|
-
return func.params.filter(
|
|
89
|
+
return func.params.filter((param) => {
|
|
90
|
+
if (getDirectParamReferences(param, func).length > 0) return true;
|
|
91
|
+
return getVLAFieldParamReferences(param, func).length > 0;
|
|
92
|
+
});
|
|
22
93
|
}
|
|
23
94
|
|
|
24
|
-
|
|
95
|
+
/**
|
|
96
|
+
* Returns the positions (indexes) of parameters that are used in the given function joinpoint.
|
|
97
|
+
*
|
|
98
|
+
* @param func - Function joinpoint to analyze
|
|
99
|
+
* @returns returns a list of numbers representing the indexes of used parameters.
|
|
100
|
+
*/
|
|
101
|
+
private getUnusedParamsPositions(func: FunctionJp): number[] {
|
|
25
102
|
let result = [];
|
|
26
103
|
for (let i = 0; i < func.params.length; i++) {
|
|
27
104
|
const param = func.params[i];
|
|
28
|
-
|
|
105
|
+
const varRefs = Query.searchFrom(func, Varref, { decl: jp => jp?.astId === param.astId }).get();
|
|
106
|
+
if (varRefs.length === 0) {
|
|
29
107
|
result.push(i);
|
|
30
108
|
}
|
|
31
109
|
}
|
|
32
110
|
return result;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
match($jp: Joinpoint, logErrors: boolean = false): boolean {
|
|
36
|
-
if (!($jp instanceof FunctionJp && $jp.isImplementation)) return false;
|
|
37
|
-
|
|
38
|
-
const unusedParams = this.getUnusedParams($jp);
|
|
39
|
-
if (logErrors) {
|
|
40
|
-
unusedParams.forEach(param =>
|
|
41
|
-
this.logMISRAError(param, `Parameter '${param.name}' is unused in function ${$jp.name}.`)
|
|
42
|
-
)
|
|
43
|
-
}
|
|
44
|
-
return unusedParams.length > 0;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
transform($jp: Joinpoint): MISRATransformationReport {
|
|
48
|
-
if(!this.match($jp)) return new MISRATransformationReport(MISRATransformationType.NoChange);
|
|
49
|
-
|
|
50
|
-
const functionJp = $jp as FunctionJp;
|
|
51
|
-
const usedParams = this.getUsedParams(functionJp);
|
|
52
|
-
const usedParamsPositions = this.getUsedParamsPositions(functionJp);
|
|
53
|
-
const calls = Query.search(Call, {function: jp => jp.astId === $jp.astId}).get();
|
|
54
|
-
|
|
55
|
-
functionJp.setParams(usedParams);
|
|
56
|
-
for (const funcDecl of functionJp.declarationJps) {
|
|
57
|
-
funcDecl.setParams(usedParams);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
for (const call of calls) {
|
|
61
|
-
const newArgs = usedParamsPositions.map(i => call.args[i]);
|
|
62
|
-
const newCall = functionJp.newCall(newArgs)
|
|
63
|
-
call.replaceWith(newCall);
|
|
64
|
-
}
|
|
65
|
-
return new MISRATransformationReport(MISRATransformationType.DescendantChange);
|
|
66
111
|
}
|
|
67
112
|
}
|
|
@@ -1,18 +1,31 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Joinpoint } from "@specs-feup/clava/api/Joinpoints.js";
|
|
2
2
|
import MISRARule from "../../MISRARule.js";
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import { MISRATransformationReport, MISRATransformationType } from "../../MISRA.js";
|
|
3
|
+
import { isInlineComment, getComments } from "../../utils/CommentUtils.js";
|
|
4
|
+
import { AnalysisType, MISRATransformationReport, MISRATransformationType } from "../../MISRA.js";
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
|
-
* MISRA Rule 3.1:
|
|
7
|
+
* MISRA-C Rule 3.1: The character sequences /* an d // shall not be used within a comment.
|
|
9
8
|
*/
|
|
10
9
|
export default class Rule_3_1_CommentSequences extends MISRARule {
|
|
10
|
+
/**
|
|
11
|
+
* Scope of analysis
|
|
12
|
+
*/
|
|
13
|
+
readonly analysisType = AnalysisType.SINGLE_TRANSLATION_UNIT;
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
/**
|
|
16
|
+
* @returns Rule identifier according to MISRA-C:2012
|
|
17
|
+
*/
|
|
18
|
+
override get name(): string {
|
|
19
|
+
return "3.1";
|
|
14
20
|
}
|
|
15
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Checks if given joinpoint contains disallowed character sequences in comments.
|
|
24
|
+
*
|
|
25
|
+
* @param $jp - Joinpoint to analyze
|
|
26
|
+
* @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
|
|
27
|
+
* @returns Returns true if the joinpoint violates the rule, false otherwise
|
|
28
|
+
*/
|
|
16
29
|
match($jp: Joinpoint, logErrors: boolean = false): boolean {
|
|
17
30
|
const invalidComments = getComments($jp).filter(comment =>
|
|
18
31
|
(isInlineComment(comment) && /(\/\*)/g.test(comment.text)) ||
|
|
@@ -26,7 +39,13 @@ export default class Rule_3_1_CommentSequences extends MISRARule {
|
|
|
26
39
|
return invalidComments.length > 0;
|
|
27
40
|
}
|
|
28
41
|
|
|
29
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Transforms the given joinpoint if it represents a joinpoint containing disallowed character sequences in comments.
|
|
44
|
+
*
|
|
45
|
+
* @param $jp - Joinpoint to transform
|
|
46
|
+
* @returns Report detailing the transformation result
|
|
47
|
+
*/
|
|
48
|
+
apply($jp: Joinpoint): MISRATransformationReport {
|
|
30
49
|
if (!this.match($jp))
|
|
31
50
|
return new MISRATransformationReport(MISRATransformationType.NoChange);
|
|
32
51
|
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import {Joinpoint, Program} from "@specs-feup/clava/api/Joinpoints.js";
|
|
2
|
+
import MISRARule from "../../MISRARule.js";
|
|
3
|
+
import { AnalysisType, MISRATransformationReport, MISRATransformationType } from "../../MISRA.js";
|
|
4
|
+
import { renameIdentifier } from "../../utils/IdentifierUtils.js";
|
|
5
|
+
import Query from "@specs-feup/lara/api/weaver/Query.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Abstract base class for MISRA-C rules that enforce constraints on identifier uniqueness where renaming may be required.
|
|
9
|
+
*
|
|
10
|
+
* Need to implement:
|
|
11
|
+
* - analysisType
|
|
12
|
+
* - name()
|
|
13
|
+
* - match($jp, logErrors)
|
|
14
|
+
*/
|
|
15
|
+
export default abstract class IdentifierRenameRule extends MISRARule {
|
|
16
|
+
/**
|
|
17
|
+
* A positive integer starting from 1 that indicates the rule's priority, determining the order in which rules are applied.
|
|
18
|
+
*/
|
|
19
|
+
readonly priority = 2;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Specifies the scope of analysis: single unit or entire system.
|
|
23
|
+
*/
|
|
24
|
+
abstract readonly analysisType: AnalysisType;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @returns Rule identifier according to MISRA-C:2012
|
|
28
|
+
*/
|
|
29
|
+
abstract override get name(): string;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Identifiers with invalid names that require renaming.
|
|
33
|
+
*/
|
|
34
|
+
protected invalidIdentifiers: any[] = [];
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Checks if the joinpoint violates the rule
|
|
38
|
+
*
|
|
39
|
+
* @param $jp - Joinpoint to analyze
|
|
40
|
+
* @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
|
|
41
|
+
* @returns Returns true if the joinpoint violates the rule, false otherwise
|
|
42
|
+
*/
|
|
43
|
+
abstract match($jp: Joinpoint, logErrors: boolean): boolean;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Renames all invalid identifiers found in the program.
|
|
47
|
+
* After renaming, the program is rebuilt to ensure proper linking of functions, variables, and their external declarations.
|
|
48
|
+
*
|
|
49
|
+
* @param $jp - Joinpoint to transform
|
|
50
|
+
* @returns Report detailing the transformation result
|
|
51
|
+
*/
|
|
52
|
+
apply($jp: Joinpoint): MISRATransformationReport {
|
|
53
|
+
if (!this.match($jp, false)) {
|
|
54
|
+
return new MISRATransformationReport(MISRATransformationType.NoChange);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
for (const identifierJp of this.invalidIdentifiers) {
|
|
58
|
+
const newName = this.context.generateIdentifierName(identifierJp)!;
|
|
59
|
+
renameIdentifier(identifierJp, newName);
|
|
60
|
+
}
|
|
61
|
+
return new MISRATransformationReport(MISRATransformationType.Replacement, Query.root() as Program);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {Joinpoint, Program } from "@specs-feup/clava/api/Joinpoints.js";
|
|
2
|
+
import { areDistinctIdentifiers, getIdentifierName } from "../../utils/IdentifierUtils.js";
|
|
3
|
+
import { getExternalLinkageIdentifiers } from "../../utils/ProgramUtils.js";
|
|
4
|
+
import { compareLocation } from "../../utils/JoinpointUtils.js";
|
|
5
|
+
import { isSameVarDecl } from "../../utils/VarUtils.js";
|
|
6
|
+
import IdentifierRenameRule from "./IdentifierRenameRule.js";
|
|
7
|
+
import { AnalysisType } from "../../MISRA.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* MISRA-C Rule 5.1 External identifiers shall be distinct.
|
|
11
|
+
*/
|
|
12
|
+
export default class Rule_5_1_DistinctExternalIdentifiers extends IdentifierRenameRule {
|
|
13
|
+
/**
|
|
14
|
+
* Scope of analysis
|
|
15
|
+
*/
|
|
16
|
+
readonly analysisType = AnalysisType.SYSTEM;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @returns Rule identifier according to MISRA-C:2012
|
|
20
|
+
*/
|
|
21
|
+
override get name(): string {
|
|
22
|
+
return "5.1";
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Checks if the given joinpoint is an external identifier distinct from other external identifiers.
|
|
27
|
+
*
|
|
28
|
+
* @param $jp - Joinpoint to analyze
|
|
29
|
+
* @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
|
|
30
|
+
* @returns Returns true if the joinpoint violates the rule, false otherwise
|
|
31
|
+
*/
|
|
32
|
+
match($jp: Joinpoint, logErrors: boolean = false): boolean {
|
|
33
|
+
if (!($jp instanceof Program)) return false;
|
|
34
|
+
|
|
35
|
+
const externalIdentifiers = getExternalLinkageIdentifiers();
|
|
36
|
+
this.invalidIdentifiers =
|
|
37
|
+
externalIdentifiers.filter(identifier1 =>
|
|
38
|
+
externalIdentifiers.some(identifier2 =>
|
|
39
|
+
!isSameVarDecl(identifier1, identifier2) &&
|
|
40
|
+
!areDistinctIdentifiers(identifier1, identifier2) &&
|
|
41
|
+
compareLocation(identifier2, identifier1) < 0
|
|
42
|
+
)
|
|
43
|
+
);
|
|
44
|
+
const nonCompliant = this.invalidIdentifiers.length > 0;
|
|
45
|
+
if (nonCompliant && logErrors) {
|
|
46
|
+
this.invalidIdentifiers.forEach(identifierJp => {
|
|
47
|
+
this.logMISRAError(identifierJp, `Identifier '${getIdentifierName(identifierJp)}' is not distinct from other external identifier within the first 31 characters.`)
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return nonCompliant;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Joinpoint, Program, TypedefDecl } from "@specs-feup/clava/api/Joinpoints.js";
|
|
2
|
+
import { getIdentifierName, isIdentifierDuplicated, isIdentifierNameDeclaredBefore } from "../../utils/IdentifierUtils.js";
|
|
3
|
+
import { getTypeDefDecl } from "../../utils/TypeDeclUtils.js";
|
|
4
|
+
import Query from "@specs-feup/lara/api/weaver/Query.js";
|
|
5
|
+
import { isTagDecl } from "../../utils/JoinpointUtils.js";
|
|
6
|
+
import { getIdentifierDecls } from "../../utils/ProgramUtils.js";
|
|
7
|
+
import IdentifierRenameRule from "./IdentifierRenameRule.js";
|
|
8
|
+
import { AnalysisType } from "../../MISRA.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* MISRA-C Rule 5.6: A typedef name shall be a unique identifier.
|
|
12
|
+
*
|
|
13
|
+
* Exception: The typedef name may be the same as the structure, union or enumeration tag name associated with the typedef.
|
|
14
|
+
*/
|
|
15
|
+
export default class Rule_5_6_UniqueTypedefNames extends IdentifierRenameRule {
|
|
16
|
+
/**
|
|
17
|
+
* Scope of analysis
|
|
18
|
+
*/
|
|
19
|
+
readonly analysisType = AnalysisType.SYSTEM;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @returns Rule identifier according to MISRA-C:2012
|
|
23
|
+
*/
|
|
24
|
+
override get name(): string {
|
|
25
|
+
return "5.6";
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
* @param $jp - Joinpoint to analyze
|
|
31
|
+
* @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
|
|
32
|
+
* @returns Returns true if the joinpoint violates the rule, false otherwise
|
|
33
|
+
*/
|
|
34
|
+
match($jp: Joinpoint, logErrors: boolean = false): boolean {
|
|
35
|
+
if (!($jp instanceof Program)) return false;
|
|
36
|
+
|
|
37
|
+
const typedefDecls = Query.search(TypedefDecl).get();
|
|
38
|
+
|
|
39
|
+
this.invalidIdentifiers = getIdentifierDecls().filter((identifierJp) =>
|
|
40
|
+
{
|
|
41
|
+
if (isTagDecl(identifierJp)) {
|
|
42
|
+
return typedefDecls.filter((decl) =>
|
|
43
|
+
getIdentifierName(identifierJp) === getIdentifierName(decl) &&
|
|
44
|
+
getTypeDefDecl(identifierJp)?.astId !== decl.astId
|
|
45
|
+
).length > 0
|
|
46
|
+
}
|
|
47
|
+
else if (identifierJp instanceof TypedefDecl) {
|
|
48
|
+
return isIdentifierNameDeclaredBefore(identifierJp, typedefDecls);
|
|
49
|
+
}
|
|
50
|
+
return isIdentifierDuplicated(identifierJp, typedefDecls);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const nonCompliant = this.invalidIdentifiers.length > 0;
|
|
54
|
+
|
|
55
|
+
if (nonCompliant && logErrors) {
|
|
56
|
+
this.invalidIdentifiers.forEach(identifierJp => {
|
|
57
|
+
this.logMISRAError(identifierJp, `Identifier '${getIdentifierName(identifierJp)}' is also the name of a typedef. Typedef identifiers must not be reused.`);
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
return nonCompliant;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Joinpoint, Program, TypedefDecl } from "@specs-feup/clava/api/Joinpoints.js";
|
|
2
|
+
import { getIdentifierName, isIdentifierDuplicated, isIdentifierNameDeclaredBefore } from "../../utils/IdentifierUtils.js";
|
|
3
|
+
import { getTypeDefDecl } from "../../utils/TypeDeclUtils.js";
|
|
4
|
+
import Query from "@specs-feup/lara/api/weaver/Query.js";
|
|
5
|
+
import { isTagDecl } from "../../utils/JoinpointUtils.js";
|
|
6
|
+
import { getIdentifierDecls } from "../../utils/ProgramUtils.js";
|
|
7
|
+
import IdentifierRenameRule from "./IdentifierRenameRule.js";
|
|
8
|
+
import { AnalysisType } from "../../MISRA.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* MISRA-C Rule 5.7: A tag name shall be a unique identifier.
|
|
12
|
+
*
|
|
13
|
+
* Exception: The tag name may be the same as the typedef name with which it is associated.
|
|
14
|
+
*/
|
|
15
|
+
export default class Rule_5_7_UniqueTagNames extends IdentifierRenameRule {
|
|
16
|
+
/**
|
|
17
|
+
* Scope of analysis
|
|
18
|
+
*/
|
|
19
|
+
readonly analysisType = AnalysisType.SYSTEM;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @returns Rule identifier according to MISRA-C:2012
|
|
23
|
+
*/
|
|
24
|
+
override get name(): string {
|
|
25
|
+
return "5.7";
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Checks whether the given joinpoint represents an identifier that has the same name as any tag (i.e., enum, union or struct)
|
|
30
|
+
*
|
|
31
|
+
* @param $jp - Joinpoint to analyze
|
|
32
|
+
* @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
|
|
33
|
+
* @returns Returns true if the joinpoint violates the rule, false otherwise
|
|
34
|
+
*/
|
|
35
|
+
match($jp: Joinpoint, logErrors: boolean = false): boolean {
|
|
36
|
+
if (!($jp instanceof Program)) return false;
|
|
37
|
+
|
|
38
|
+
const tagDecls = Query.search(Joinpoint, (jp => {return isTagDecl(jp)})).get();
|
|
39
|
+
this.invalidIdentifiers = getIdentifierDecls().filter((identifierJp) =>
|
|
40
|
+
{
|
|
41
|
+
if (identifierJp instanceof TypedefDecl) {
|
|
42
|
+
return tagDecls.filter((tag) =>
|
|
43
|
+
getIdentifierName(identifierJp) === getIdentifierName(tag) &&
|
|
44
|
+
getTypeDefDecl(tag)?.ast !== identifierJp.ast
|
|
45
|
+
).length > 0;
|
|
46
|
+
}
|
|
47
|
+
else if (isTagDecl(identifierJp)) {
|
|
48
|
+
return isIdentifierNameDeclaredBefore(identifierJp, tagDecls);
|
|
49
|
+
}
|
|
50
|
+
return isIdentifierDuplicated(identifierJp, tagDecls);
|
|
51
|
+
});
|
|
52
|
+
const nonCompliant = this.invalidIdentifiers.length > 0;
|
|
53
|
+
|
|
54
|
+
if (nonCompliant && logErrors) {
|
|
55
|
+
this.invalidIdentifiers.forEach(identifierJp => {
|
|
56
|
+
this.logMISRAError(identifierJp, `Identifier '${getIdentifierName(identifierJp)}' is also the name of a tag. Tag identifiers must not be reused.`);
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
return nonCompliant;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Joinpoint, Program } from "@specs-feup/clava/api/Joinpoints.js";
|
|
2
|
+
import { getIdentifierName, isExternalLinkageIdentifier, isIdentifierDuplicated, isIdentifierNameDeclaredBefore } from "../../utils/IdentifierUtils.js";
|
|
3
|
+
import { getExternalLinkageIdentifiers, getIdentifierDecls } from "../../utils/ProgramUtils.js";
|
|
4
|
+
import IdentifierRenameRule from "./IdentifierRenameRule.js";
|
|
5
|
+
import { AnalysisType } from "../../MISRA.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* MISRA-C Rule 5.8: Identifiers that define objects or functions with external linkage shall be unique
|
|
9
|
+
*/
|
|
10
|
+
export default class Rule_5_8_UniqueExternalLinkIdentifiers extends IdentifierRenameRule {
|
|
11
|
+
/**
|
|
12
|
+
* Scope of analysis
|
|
13
|
+
*/
|
|
14
|
+
readonly analysisType = AnalysisType.SYSTEM;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @returns Rule identifier according to MISRA-C:2012
|
|
18
|
+
*/
|
|
19
|
+
override get name(): string {
|
|
20
|
+
return "5.8";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* @param $jp - Joinpoint to analyze
|
|
26
|
+
* @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
|
|
27
|
+
* @returns Returns true if the joinpoint violates the rule, false otherwise
|
|
28
|
+
*/
|
|
29
|
+
match($jp: Joinpoint, logErrors: boolean = false): boolean {
|
|
30
|
+
if (!($jp instanceof Program)) return false;
|
|
31
|
+
|
|
32
|
+
const externalLinkageIdentifiers = getExternalLinkageIdentifiers();
|
|
33
|
+
this.invalidIdentifiers = getIdentifierDecls().filter((identifierJp) =>
|
|
34
|
+
isExternalLinkageIdentifier(identifierJp) ?
|
|
35
|
+
isIdentifierNameDeclaredBefore(identifierJp, externalLinkageIdentifiers) :
|
|
36
|
+
isIdentifierDuplicated(identifierJp, externalLinkageIdentifiers)
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const nonCompliant = this.invalidIdentifiers.length > 0;
|
|
40
|
+
if (nonCompliant && logErrors) {
|
|
41
|
+
this.invalidIdentifiers.forEach(identifierJp => {
|
|
42
|
+
this.logMISRAError(identifierJp, `Identifier '${getIdentifierName(identifierJp)}' is already defined with external linkage in this or other file.`);
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
return nonCompliant;
|
|
46
|
+
}
|
|
47
|
+
}
|