@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
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { 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
|
+
* MISRA-C Rule 5.6: A typedef name shall be a unique identifier.
|
|
11
|
+
*
|
|
12
|
+
* Exception: The typedef name may be the same as the structure, union or enumeration tag name associated with the typedef.
|
|
13
|
+
*/
|
|
14
|
+
export default class Rule_5_6_UniqueTypedefNames extends IdentifierRenameRule {
|
|
15
|
+
/**
|
|
16
|
+
* Scope of analysis
|
|
17
|
+
*/
|
|
18
|
+
analysisType = AnalysisType.SYSTEM;
|
|
19
|
+
/**
|
|
20
|
+
* @returns Rule identifier according to MISRA-C:2012
|
|
21
|
+
*/
|
|
22
|
+
get name() {
|
|
23
|
+
return "5.6";
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
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
|
+
*/
|
|
31
|
+
match($jp, logErrors = false) {
|
|
32
|
+
if (!($jp instanceof Program))
|
|
33
|
+
return false;
|
|
34
|
+
const typedefDecls = Query.search(TypedefDecl).get();
|
|
35
|
+
this.invalidIdentifiers = getIdentifierDecls().filter((identifierJp) => {
|
|
36
|
+
if (isTagDecl(identifierJp)) {
|
|
37
|
+
return typedefDecls.filter((decl) => getIdentifierName(identifierJp) === getIdentifierName(decl) &&
|
|
38
|
+
getTypeDefDecl(identifierJp)?.astId !== decl.astId).length > 0;
|
|
39
|
+
}
|
|
40
|
+
else if (identifierJp instanceof TypedefDecl) {
|
|
41
|
+
return isIdentifierNameDeclaredBefore(identifierJp, typedefDecls);
|
|
42
|
+
}
|
|
43
|
+
return isIdentifierDuplicated(identifierJp, typedefDecls);
|
|
44
|
+
});
|
|
45
|
+
const nonCompliant = this.invalidIdentifiers.length > 0;
|
|
46
|
+
if (nonCompliant && logErrors) {
|
|
47
|
+
this.invalidIdentifiers.forEach(identifierJp => {
|
|
48
|
+
this.logMISRAError(identifierJp, `Identifier '${getIdentifierName(identifierJp)}' is also the name of a typedef. Typedef identifiers must not be reused.`);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return nonCompliant;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=Rule_5_6_UniqueTypedefNames.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Rule_5_6_UniqueTypedefNames.js","sourceRoot":"","sources":["../../../src/rules/Section5_Identifiers/Rule_5_6_UniqueTypedefNames.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AACtF,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,8BAA8B,EAAE,MAAM,gCAAgC,CAAC;AAC3H,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,KAAK,MAAM,sCAAsC,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,oBAAoB,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,2BAA4B,SAAQ,oBAAoB;IACzE;;OAEG;IACM,YAAY,GAAG,YAAY,CAAC,MAAM,CAAC;IAE5C;;OAEG;IACH,IAAa,IAAI;QACb,OAAO,KAAK,CAAC;IACjB,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,GAAc,EAAE,YAAqB,KAAK;QAC5C,IAAI,CAAC,CAAC,GAAG,YAAY,OAAO,CAAC;YAAE,OAAO,KAAK,CAAC;QAE5C,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,GAAG,EAAE,CAAC;QAErD,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,EAAE,CAAC,MAAM,CAAC,CAAC,YAAY,EAAE,EAAE;YAEnE,IAAI,SAAS,CAAC,YAAY,CAAC,EAAE,CAAC;gBAC1B,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAChC,iBAAiB,CAAC,YAAY,CAAC,KAAK,iBAAiB,CAAC,IAAI,CAAC;oBAC3D,cAAc,CAAC,YAAY,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC,KAAK,CACrD,CAAC,MAAM,GAAG,CAAC,CAAA;YAChB,CAAC;iBACI,IAAI,YAAY,YAAY,WAAW,EAAE,CAAC;gBAC3C,OAAO,8BAA8B,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;YACtE,CAAC;YACD,OAAO,sBAAsB,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;QAC9D,CAAC,CAAC,CAAC;QAEH,MAAM,YAAY,GAAG,IAAI,CAAC,kBAAkB,CAAC,MAAM,GAAG,CAAC,CAAC;QAExD,IAAI,YAAY,IAAI,SAAS,EAAE,CAAC;YAC5B,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE;gBAC3C,IAAI,CAAC,aAAa,CAAC,YAAY,EAAE,eAAe,iBAAiB,CAAC,YAAY,CAAC,0EAA0E,CAAC,CAAC;YAC/J,CAAC,CAAC,CAAA;QACN,CAAC;QACD,OAAO,YAAY,CAAC;IACxB,CAAC;CACJ"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Joinpoint } from "@specs-feup/clava/api/Joinpoints.js";
|
|
2
|
+
import IdentifierRenameRule from "./IdentifierRenameRule.js";
|
|
3
|
+
import { AnalysisType } from "../../MISRA.js";
|
|
4
|
+
/**
|
|
5
|
+
* MISRA-C Rule 5.7: A tag name shall be a unique identifier.
|
|
6
|
+
*
|
|
7
|
+
* Exception: The tag name may be the same as the typedef name with which it is associated.
|
|
8
|
+
*/
|
|
9
|
+
export default class Rule_5_7_UniqueTagNames extends IdentifierRenameRule {
|
|
10
|
+
/**
|
|
11
|
+
* Scope of analysis
|
|
12
|
+
*/
|
|
13
|
+
readonly analysisType = AnalysisType.SYSTEM;
|
|
14
|
+
/**
|
|
15
|
+
* @returns Rule identifier according to MISRA-C:2012
|
|
16
|
+
*/
|
|
17
|
+
get name(): string;
|
|
18
|
+
/**
|
|
19
|
+
* Checks whether the given joinpoint represents an identifier that has the same name as any tag (i.e., enum, union or struct)
|
|
20
|
+
*
|
|
21
|
+
* @param $jp - Joinpoint to analyze
|
|
22
|
+
* @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
|
|
23
|
+
* @returns Returns true if the joinpoint violates the rule, false otherwise
|
|
24
|
+
*/
|
|
25
|
+
match($jp: Joinpoint, logErrors?: boolean): boolean;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=Rule_5_7_UniqueTagNames.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Rule_5_7_UniqueTagNames.d.ts","sourceRoot":"","sources":["../../../src/rules/Section5_Identifiers/Rule_5_7_UniqueTagNames.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAwB,MAAM,qCAAqC,CAAC;AAMtF,OAAO,oBAAoB,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,uBAAwB,SAAQ,oBAAoB;IACrE;;OAEG;IACH,QAAQ,CAAC,YAAY,uBAAuB;IAE5C;;OAEG;IACH,IAAa,IAAI,IAAI,MAAM,CAE1B;IAED;;;;;;OAMG;IACH,KAAK,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,GAAE,OAAe,GAAG,OAAO;CA0B7D"}
|
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
* MISRA-C Rule 5.7: A tag name shall be a unique identifier.
|
|
11
|
+
*
|
|
12
|
+
* Exception: The tag name may be the same as the typedef name with which it is associated.
|
|
13
|
+
*/
|
|
14
|
+
export default class Rule_5_7_UniqueTagNames extends IdentifierRenameRule {
|
|
15
|
+
/**
|
|
16
|
+
* Scope of analysis
|
|
17
|
+
*/
|
|
18
|
+
analysisType = AnalysisType.SYSTEM;
|
|
19
|
+
/**
|
|
20
|
+
* @returns Rule identifier according to MISRA-C:2012
|
|
21
|
+
*/
|
|
22
|
+
get name() {
|
|
23
|
+
return "5.7";
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Checks whether the given joinpoint represents an identifier that has the same name as any tag (i.e., enum, union or struct)
|
|
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, logErrors = false) {
|
|
33
|
+
if (!($jp instanceof Program))
|
|
34
|
+
return false;
|
|
35
|
+
const tagDecls = Query.search(Joinpoint, (jp => { return isTagDecl(jp); })).get();
|
|
36
|
+
this.invalidIdentifiers = getIdentifierDecls().filter((identifierJp) => {
|
|
37
|
+
if (identifierJp instanceof TypedefDecl) {
|
|
38
|
+
return tagDecls.filter((tag) => getIdentifierName(identifierJp) === getIdentifierName(tag) &&
|
|
39
|
+
getTypeDefDecl(tag)?.ast !== identifierJp.ast).length > 0;
|
|
40
|
+
}
|
|
41
|
+
else if (isTagDecl(identifierJp)) {
|
|
42
|
+
return isIdentifierNameDeclaredBefore(identifierJp, tagDecls);
|
|
43
|
+
}
|
|
44
|
+
return isIdentifierDuplicated(identifierJp, tagDecls);
|
|
45
|
+
});
|
|
46
|
+
const nonCompliant = this.invalidIdentifiers.length > 0;
|
|
47
|
+
if (nonCompliant && logErrors) {
|
|
48
|
+
this.invalidIdentifiers.forEach(identifierJp => {
|
|
49
|
+
this.logMISRAError(identifierJp, `Identifier '${getIdentifierName(identifierJp)}' is also the name of a tag. Tag identifiers must not be reused.`);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return nonCompliant;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=Rule_5_7_UniqueTagNames.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Rule_5_7_UniqueTagNames.js","sourceRoot":"","sources":["../../../src/rules/Section5_Identifiers/Rule_5_7_UniqueTagNames.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AACtF,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,8BAA8B,EAAE,MAAM,gCAAgC,CAAC;AAC3H,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,KAAK,MAAM,sCAAsC,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,oBAAoB,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,uBAAwB,SAAQ,oBAAoB;IACrE;;OAEG;IACM,YAAY,GAAG,YAAY,CAAC,MAAM,CAAC;IAE5C;;OAEG;IACH,IAAa,IAAI;QACb,OAAO,KAAK,CAAC;IACjB,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,GAAc,EAAE,YAAqB,KAAK;Q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oint } from "@specs-feup/clava/api/Joinpoints.js";
|
|
2
|
+
import IdentifierRenameRule from "./IdentifierRenameRule.js";
|
|
3
|
+
import { AnalysisType } from "../../MISRA.js";
|
|
4
|
+
/**
|
|
5
|
+
* MISRA-C Rule 5.8: Identifiers that define objects or functions with external linkage shall be unique
|
|
6
|
+
*/
|
|
7
|
+
export default class Rule_5_8_UniqueExternalLinkIdentifiers extends IdentifierRenameRule {
|
|
8
|
+
/**
|
|
9
|
+
* Scope of analysis
|
|
10
|
+
*/
|
|
11
|
+
readonly analysisType = AnalysisType.SYSTEM;
|
|
12
|
+
/**
|
|
13
|
+
* @returns Rule identifier according to MISRA-C:2012
|
|
14
|
+
*/
|
|
15
|
+
get name(): string;
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
* @param $jp - Joinpoint to analyze
|
|
19
|
+
* @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
|
|
20
|
+
* @returns Returns true if the joinpoint violates the rule, false otherwise
|
|
21
|
+
*/
|
|
22
|
+
match($jp: Joinpoint, logErrors?: boolean): boolean;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=Rule_5_8_UniqueExternalLinkIdentifiers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Rule_5_8_UniqueExternalLinkIdentifiers.d.ts","sourceRoot":"","sources":["../../../src/rules/Section5_Identifiers/Rule_5_8_UniqueExternalLinkIdentifiers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAW,MAAM,qCAAqC,CAAC;AAGzE,OAAO,oBAAoB,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,sCAAuC,SAAQ,oBAAoB;IACpF;;OAEG;IACH,QAAQ,CAAC,YAAY,uBAAuB;IAE3C;;MAEE;IACH,IAAa,IAAI,IAAI,MAAM,CAE1B;IAED;;;;;OAKG;IACH,KAAK,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,GAAE,OAAe,GAAG,OAAO;CAkB7D"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { 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
|
+
* MISRA-C Rule 5.8: Identifiers that define objects or functions with external linkage shall be unique
|
|
8
|
+
*/
|
|
9
|
+
export default class Rule_5_8_UniqueExternalLinkIdentifiers extends IdentifierRenameRule {
|
|
10
|
+
/**
|
|
11
|
+
* Scope of analysis
|
|
12
|
+
*/
|
|
13
|
+
analysisType = AnalysisType.SYSTEM;
|
|
14
|
+
/**
|
|
15
|
+
* @returns Rule identifier according to MISRA-C:2012
|
|
16
|
+
*/
|
|
17
|
+
get name() {
|
|
18
|
+
return "5.8";
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* @param $jp - Joinpoint to analyze
|
|
23
|
+
* @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
|
|
24
|
+
* @returns Returns true if the joinpoint violates the rule, false otherwise
|
|
25
|
+
*/
|
|
26
|
+
match($jp, logErrors = false) {
|
|
27
|
+
if (!($jp instanceof Program))
|
|
28
|
+
return false;
|
|
29
|
+
const externalLinkageIdentifiers = getExternalLinkageIdentifiers();
|
|
30
|
+
this.invalidIdentifiers = getIdentifierDecls().filter((identifierJp) => isExternalLinkageIdentifier(identifierJp) ?
|
|
31
|
+
isIdentifierNameDeclaredBefore(identifierJp, externalLinkageIdentifiers) :
|
|
32
|
+
isIdentifierDuplicated(identifierJp, externalLinkageIdentifiers));
|
|
33
|
+
const nonCompliant = this.invalidIdentifiers.length > 0;
|
|
34
|
+
if (nonCompliant && logErrors) {
|
|
35
|
+
this.invalidIdentifiers.forEach(identifierJp => {
|
|
36
|
+
this.logMISRAError(identifierJp, `Identifier '${getIdentifierName(identifierJp)}' is already defined with external linkage in this or other file.`);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return nonCompliant;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=Rule_5_8_UniqueExternalLinkIdentifiers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Rule_5_8_UniqueExternalLinkIdentifiers.js","sourceRoot":"","sources":["../../../src/rules/Section5_Identifiers/Rule_5_8_UniqueExternalLinkIdentifiers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,OAAO,EAAE,MAAM,qCAAqC,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,2BAA2B,EAAE,sBAAsB,EAAE,8BAA8B,EAAE,MAAM,gCAAgC,CAAC;AACxJ,OAAO,EAAE,6BAA6B,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAChG,OAAO,oBAAoB,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,sCAAuC,SAAQ,oBAAoB;IACpF;;OAEG;IACM,YAAY,GAAG,YAAY,CAAC,MAAM,CAAC;IAE3C;;MAEE;IACH,IAAa,IAAI;QACb,OAAO,KAAK,CAAC;IACjB,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,GAAc,EAAE,YAAqB,KAAK;QAC5C,IAAI,CAAC,CAAC,GAAG,YAAY,OAAO,CAAC;YAAE,OAAO,KAAK,CAAC;QAE5C,MAAM,0BAA0B,GAAG,6BAA6B,EAAE,CAAC;QACnE,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,EAAE,CAAC,MAAM,CAAC,CAAC,YAAY,EAAE,EAAE,CACrE,2BAA2B,CAAC,YAAY,CAAC,CAAC,CAAC;YACzC,8BAA8B,CAAC,YAAY,EAAE,0BAA0B,CAAC,CAAC,CAAC;YAC1E,sBAAsB,CAAC,YAAY,EAAE,0BAA0B,CAAC,CACnE,CAAC;QAEF,MAAM,YAAY,GAAG,IAAI,CAAC,kBAAkB,CAAC,MAAM,GAAG,CAAC,CAAC;QACxD,IAAI,YAAY,IAAI,SAAS,EAAE,CAAC;YAC5B,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE;gBAC3C,IAAI,CAAC,aAAa,CAAC,YAAY,EAAE,eAAe,iBAAiB,CAAC,YAAY,CAAC,mEAAmE,CAAC,CAAC;YACxJ,CAAC,CAAC,CAAA;QACN,CAAC;QACD,OAAO,YAAY,CAAC;IACxB,CAAC;CACJ"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Joinpoint } from "@specs-feup/clava/api/Joinpoints.js";
|
|
2
|
+
import IdentifierRenameRule from "./IdentifierRenameRule.js";
|
|
3
|
+
import { AnalysisType } from "../../MISRA.js";
|
|
4
|
+
/**
|
|
5
|
+
* MISRA-C Rule 5.9: Identifiers that define objects or functions with internal linkage should be unique
|
|
6
|
+
*/
|
|
7
|
+
export default class Rule_5_9_UniqueInternalLinkIdentifiers extends IdentifierRenameRule {
|
|
8
|
+
/**
|
|
9
|
+
* Scope of analysis
|
|
10
|
+
*/
|
|
11
|
+
readonly analysisType = AnalysisType.SYSTEM;
|
|
12
|
+
/**
|
|
13
|
+
* @returns Rule identifier according to MISRA-C:2012
|
|
14
|
+
*/
|
|
15
|
+
get name(): string;
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
* @param $jp - Joinpoint to analyze
|
|
19
|
+
* @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
|
|
20
|
+
* @returns Returns true if the joinpoint violates the rule, false otherwise
|
|
21
|
+
*/
|
|
22
|
+
match($jp: Joinpoint, logErrors?: boolean): boolean;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=Rule_5_9_UniqueInternalLinkIdentifiers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Rule_5_9_UniqueInternalLinkIdentifiers.d.ts","sourceRoot":"","sources":["../../../src/rules/Section5_Identifiers/Rule_5_9_UniqueInternalLinkIdentifiers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAU,MAAM,qCAAqC,CAAC;AAGvE,OAAO,oBAAoB,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,sCAAuC,SAAQ,oBAAoB;IACpF;;OAEG;IACH,QAAQ,CAAC,YAAY,uBAAuB;IAE5C;;OAEG;IACH,IAAa,IAAI,IAAI,MAAM,CAE1B;IAED;;;;;OAKG;IACH,KAAK,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,GAAE,OAAe,GAAG,OAAO;CAkB7D"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Program } from "@specs-feup/clava/api/Joinpoints.js";
|
|
2
|
+
import { getIdentifierDecls, getInternalLinkageIdentifiers } from "../../utils/ProgramUtils.js";
|
|
3
|
+
import { getIdentifierName, isIdentifierDuplicated, isIdentifierNameDeclaredBefore, isInternalLinkageIdentifier } from "../../utils/IdentifierUtils.js";
|
|
4
|
+
import IdentifierRenameRule from "./IdentifierRenameRule.js";
|
|
5
|
+
import { AnalysisType } from "../../MISRA.js";
|
|
6
|
+
/**
|
|
7
|
+
* MISRA-C Rule 5.9: Identifiers that define objects or functions with internal linkage should be unique
|
|
8
|
+
*/
|
|
9
|
+
export default class Rule_5_9_UniqueInternalLinkIdentifiers extends IdentifierRenameRule {
|
|
10
|
+
/**
|
|
11
|
+
* Scope of analysis
|
|
12
|
+
*/
|
|
13
|
+
analysisType = AnalysisType.SYSTEM;
|
|
14
|
+
/**
|
|
15
|
+
* @returns Rule identifier according to MISRA-C:2012
|
|
16
|
+
*/
|
|
17
|
+
get name() {
|
|
18
|
+
return "5.9";
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* @param $jp - Joinpoint to analyze
|
|
23
|
+
* @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
|
|
24
|
+
* @returns Returns true if the joinpoint violates the rule, false otherwise
|
|
25
|
+
*/
|
|
26
|
+
match($jp, logErrors = false) {
|
|
27
|
+
if (!($jp instanceof Program))
|
|
28
|
+
return false;
|
|
29
|
+
const internalLinkageIdentifiers = getInternalLinkageIdentifiers();
|
|
30
|
+
this.invalidIdentifiers = getIdentifierDecls().filter((identifierJp) => isInternalLinkageIdentifier(identifierJp) ?
|
|
31
|
+
isIdentifierNameDeclaredBefore(identifierJp, internalLinkageIdentifiers) :
|
|
32
|
+
isIdentifierDuplicated(identifierJp, internalLinkageIdentifiers));
|
|
33
|
+
const nonCompliant = this.invalidIdentifiers.length > 0;
|
|
34
|
+
if (nonCompliant && logErrors) {
|
|
35
|
+
this.invalidIdentifiers.forEach(identifierJp => {
|
|
36
|
+
this.logMISRAError(identifierJp, `Identifier '${getIdentifierName(identifierJp)}' is already defined with internal linkage in this or other file.`);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return nonCompliant;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=Rule_5_9_UniqueInternalLinkIdentifiers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Rule_5_9_UniqueInternalLinkIdentifiers.js","sourceRoot":"","sources":["../../../src/rules/Section5_Identifiers/Rule_5_9_UniqueInternalLinkIdentifiers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,OAAO,EAAC,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAE,kBAAkB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
|
|
|
1
|
+
import { Joinpoint } from "@specs-feup/clava/api/Joinpoints.js";
|
|
2
|
+
import MISRARule from "../../MISRARule.js";
|
|
3
|
+
import { AnalysisType, MISRATransformationReport } from "../../MISRA.js";
|
|
4
|
+
/**
|
|
5
|
+
* MISRA-C Rule 8.6: An identifier with external linkage shall have exactly one external definition
|
|
6
|
+
*/
|
|
7
|
+
export default class Rule_8_6_SingleExternalDefinition extends MISRARule {
|
|
8
|
+
#private;
|
|
9
|
+
/**
|
|
10
|
+
* Scope of analysis
|
|
11
|
+
*/
|
|
12
|
+
readonly analysisType = AnalysisType.SYSTEM;
|
|
13
|
+
/**
|
|
14
|
+
* A positive integer starting from 1 that indicates the rule's priority, determining the order in which rules are applied.
|
|
15
|
+
*/
|
|
16
|
+
readonly priority = 2;
|
|
17
|
+
/**
|
|
18
|
+
* @returns Rule identifier according to MISRA-C:2012
|
|
19
|
+
*/
|
|
20
|
+
get name(): string;
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @param $jp - Joinpoint to analyze
|
|
24
|
+
* @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
|
|
25
|
+
* @returns Returns true if the joinpoint violates the rule, false otherwise
|
|
26
|
+
*/
|
|
27
|
+
match($jp: Joinpoint, logErrors?: boolean): boolean;
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
* @param $jp - Joinpoint to transform
|
|
31
|
+
* @returns Report detailing the transformation result
|
|
32
|
+
*/
|
|
33
|
+
apply($jp: Joinpoint): MISRATransformationReport;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=Rule_8_6_SingleExternalDefinition.d.ts.map
|
package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_6_SingleExternalDefinition.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Rule_8_6_SingleExternalDefinition.d.ts","sourceRoot":"","sources":["../../../src/rules/Section8_DeclarationsAndDefinitions/Rule_8_6_SingleExternalDefinition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,SAAS,EAAkC,MAAM,qCAAqC,CAAC;AACxG,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,yBAAyB,EAA2B,MAAM,gBAAgB,CAAC;AAOlG;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,iCAAkC,SAAQ,SAAS;;IACpE;;OAEG;IACH,QAAQ,CAAC,YAAY,uBAAuB;IAE5C;;OAEG;IACH,QAAQ,CAAC,QAAQ,KAAK;IAItB;;OAEG;IACH,IAAa,IAAI,IAAI,MAAM,CAE1B;IAED;;;;;OAKG;IACH,KAAK,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,GAAE,OAAe,GAAG,OAAO;IAuB1D;;;;OAIG;IACH,KAAK,CAAC,GAAG,EAAE,SAAS,GAAG,yBAAyB;CAmDnD"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { FileJp, Program, StorageClass } from "@specs-feup/clava/api/Joinpoints.js";
|
|
2
|
+
import MISRARule from "../../MISRARule.js";
|
|
3
|
+
import { AnalysisType, MISRATransformationReport, MISRATransformationType } from "../../MISRA.js";
|
|
4
|
+
import { getIdentifierName } from "../../utils/IdentifierUtils.js";
|
|
5
|
+
import { getExternalLinkageVars, resetCaches } from "../../utils/ProgramUtils.js";
|
|
6
|
+
import { compareLocation } from "../../utils/JoinpointUtils.js";
|
|
7
|
+
import Query from "@specs-feup/lara/api/weaver/Query.js";
|
|
8
|
+
import { isSameVarDecl } from "../../utils/VarUtils.js";
|
|
9
|
+
/**
|
|
10
|
+
* MISRA-C Rule 8.6: An identifier with external linkage shall have exactly one external definition
|
|
11
|
+
*/
|
|
12
|
+
export default class Rule_8_6_SingleExternalDefinition extends MISRARule {
|
|
13
|
+
/**
|
|
14
|
+
* Scope of analysis
|
|
15
|
+
*/
|
|
16
|
+
analysisType = AnalysisType.SYSTEM;
|
|
17
|
+
/**
|
|
18
|
+
* A positive integer starting from 1 that indicates the rule's priority, determining the order in which rules are applied.
|
|
19
|
+
*/
|
|
20
|
+
priority = 2;
|
|
21
|
+
#invalidDecls = [];
|
|
22
|
+
/**
|
|
23
|
+
* @returns Rule identifier according to MISRA-C:2012
|
|
24
|
+
*/
|
|
25
|
+
get name() {
|
|
26
|
+
return "8.6";
|
|
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, logErrors = false) {
|
|
35
|
+
if (!($jp instanceof Program)) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
const externalLinkageVars = getExternalLinkageVars();
|
|
39
|
+
this.#invalidDecls = externalLinkageVars.filter((decl1) => externalLinkageVars.some((decl2) => isSameVarDecl(decl1, decl2) &&
|
|
40
|
+
decl1.getAncestor("file").ast !== decl2.getAncestor("file").ast &&
|
|
41
|
+
compareLocation(decl2, decl1) < 0));
|
|
42
|
+
const nonCompliant = this.#invalidDecls.length > 0;
|
|
43
|
+
if (nonCompliant && logErrors) {
|
|
44
|
+
this.#invalidDecls.forEach(identifierJp => {
|
|
45
|
+
this.logMISRAError(identifierJp, `Identifier '${getIdentifierName(identifierJp)}' with external linkage is defined in multiple files.`);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return nonCompliant;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
*
|
|
52
|
+
* @param $jp - Joinpoint to transform
|
|
53
|
+
* @returns Report detailing the transformation result
|
|
54
|
+
*/
|
|
55
|
+
apply($jp) {
|
|
56
|
+
if (!this.match($jp)) {
|
|
57
|
+
return new MISRATransformationReport(MISRATransformationType.NoChange);
|
|
58
|
+
}
|
|
59
|
+
let solved = false;
|
|
60
|
+
const uniqueDecls = this.#invalidDecls.reduce((acc, decl1) => acc.some(decl2 => isSameVarDecl(decl1, decl2)) ? acc : [...acc, decl1], []);
|
|
61
|
+
for (const decl of uniqueDecls) {
|
|
62
|
+
if (this.context.getRuleResult(this.ruleID, decl) === MISRATransformationType.NoChange) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const filesWithInitialization = Query.search(FileJp, (fileJp) => {
|
|
66
|
+
return fileJp.descendants.some((jp) => isSameVarDecl(jp, decl) && jp.init !== undefined);
|
|
67
|
+
}).get();
|
|
68
|
+
if (filesWithInitialization.length > 1) {
|
|
69
|
+
const other = this.#invalidDecls.filter(identifier => isSameVarDecl(identifier, decl));
|
|
70
|
+
for (const varDecl of other) {
|
|
71
|
+
this.logMISRAError(varDecl, `Identifier '${getIdentifierName(varDecl)}' with external linkage has multiple definitions across files. Automatic correction cannot be applied due to multiple initializations.`);
|
|
72
|
+
this.context.addRuleResult(this.ruleID, varDecl, MISRATransformationType.NoChange);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else if (filesWithInitialization.length === 0) {
|
|
76
|
+
const other = this.#invalidDecls.filter(identifier => isSameVarDecl(decl, identifier));
|
|
77
|
+
other.forEach(varDecl => {
|
|
78
|
+
varDecl.setStorageClass(StorageClass.EXTERN);
|
|
79
|
+
});
|
|
80
|
+
solved = true;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
const other = getExternalLinkageVars().filter(identifierJp => isSameVarDecl(decl, identifierJp) &&
|
|
84
|
+
(identifierJp.getAncestor("file").ast !== filesWithInitialization[0].ast));
|
|
85
|
+
other.forEach(varDecl => {
|
|
86
|
+
varDecl.setStorageClass(StorageClass.EXTERN);
|
|
87
|
+
});
|
|
88
|
+
solved = true;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (solved) {
|
|
92
|
+
resetCaches();
|
|
93
|
+
return new MISRATransformationReport(MISRATransformationType.DescendantChange);
|
|
94
|
+
}
|
|
95
|
+
return new MISRATransformationReport(MISRATransformationType.NoChange);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=Rule_8_6_SingleExternalDefinition.js.map
|
package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_6_SingleExternalDefinition.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Rule_8_6_SingleExternalDefinition.js","sourceRoot":"","sources":["../../../src/rules/Section8_DeclarationsAndDefinitions/Rule_8_6_SingleExternalDefinition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAa,OAAO,EAAE,YAAY,EAAW,MAAM,qCAAqC,CAAC;AACxG,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,yBAAyB,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAClG,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAE,WAAW,EAAwB,MAAM,6BAA6B,CAAC;AACxG,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,MAAM,sCAAsC,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,iCAAkC,SAAQ,SAAS;IACpE;;OAEG;IACM,YAAY,GAAG,YAAY,CAAC,MAAM,CAAC;IAE5C;;OAEG;IACM,QAAQ,GAAG,CAAC,CAAC;IAEtB,aAAa,GAAc,EAAE,CAAC;IAE9B;;OAEG;IACH,IAAa,IAAI;QACb,OAAO,KAAK,CAAC;IACjB,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,GAAc,EAAE,YAAqB,KAAK;QAC5C,IAAI,CAAC,CAAC,GAAG,YAAY,OAAO,CAAC,EAAE,CAAC;YAC5B,OAAO,KAAK,CAAC;QACjB,CAAC;QAED,MAAM,mBAAmB,GAAG,sBAAsB,EAAE,CAAC;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AAC,MAAM,CAAC,CAAA;gBAChD,CAAC,CAAC,CAAC;gBACH,MAAM,GAAG,IAAI,CAAC;YAClB,CAAC;iBACI,CAAC;gBACF,MAAM,KAAK,GAAG,sBAAsB,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CACzD,aAAa,CAAC,IAAI,EAAE,YAAY,CAAC;oBACjC,CAAC,YAAY,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,uBAAuB,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAC5E,CAAC;gBACF,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;oBACpB,OAAO,CAAC,eAAe,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;gBACjD,CAAC,CAAC,CAAC;gBACH,MAAM,GAAG,IAAI,CAAC;YAClB,CAAC;QACL,CAAC;QACD,IAAI,MAAM,EAAE,CAAC;YACT,WAAW,EAAE,CAAC;YACd,OAAO,IAAI,yBAAyB,CAAC,uBAAuB,CAAC,gBAAgB,CAAC,CAAC;QACnF,CAAC;QACD,OAAO,IAAI,yBAAyB,CAAC,uBAAuB,CAAC,QAAQ,CAAC,CAAC;IAC3E,CAAC;CACJ"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Joinpoint } from "@specs-feup/clava/api/Joinpoints.js";
|
|
2
|
+
import MISRARule from "../../MISRARule.js";
|
|
3
|
+
import { AnalysisType, MISRATransformationReport } from "../../MISRA.js";
|
|
4
|
+
/**
|
|
5
|
+
* MISRA-C Rule 8.7: Functions and objects should not be defined with external linkage if they are referenced in only one translation unit
|
|
6
|
+
*/
|
|
7
|
+
export default class Rule_8_7_RestrictExternalLinkage extends MISRARule {
|
|
8
|
+
#private;
|
|
9
|
+
/**
|
|
10
|
+
* Scope of analysis
|
|
11
|
+
*/
|
|
12
|
+
readonly analysisType = AnalysisType.SYSTEM;
|
|
13
|
+
/**
|
|
14
|
+
* @returns Rule identifier according to MISRA-C:2012
|
|
15
|
+
*/
|
|
16
|
+
get name(): string;
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @param $jp - Joinpoint to analyze
|
|
20
|
+
* @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
|
|
21
|
+
* @returns Returns true if the joinpoint violates the rule, false otherwise
|
|
22
|
+
*/
|
|
23
|
+
match($jp: Joinpoint, logErrors?: boolean): boolean;
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
* @param $jp - Joinpoint to transform
|
|
27
|
+
* @returns Report detailing the transformation result
|
|
28
|
+
*/
|
|
29
|
+
apply($jp: Joinpoint): MISRATransformationReport;
|
|
30
|
+
/**
|
|
31
|
+
* Removes unused external declarations (`extern`) of the current identifier found in other source files.
|
|
32
|
+
*/
|
|
33
|
+
private removeExternalDeclarations;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=Rule_8_7_RestrictExternalLinkage.d.ts.map
|
package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_7_RestrictExternalLinkage.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Rule_8_7_RestrictExternalLinkage.d.ts","sourceRoot":"","sources":["../../../src/rules/Section8_DeclarationsAndDefinitions/Rule_8_7_RestrictExternalLinkage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,SAAS,EAA0C,MAAM,qCAAqC,CAAC;AACpH,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,yBAAyB,EAA2B,MAAM,gBAAgB,CAAC;AAMlG;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,gCAAiC,SAAQ,SAAS;;IACnE;;OAEG;IACH,QAAQ,CAAC,YAAY,uBAAuB;IAE5C;;OAEG;IACH,IAAa,IAAI,IAAI,MAAM,CAE1B;IAOD;;;;;OAKG;IACH,KAAK,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,GAAE,OAAe,GAAG,OAAO;IAkB1D;;;;OAIG;IACH,KAAK,CAAC,GAAG,EAAE,SAAS,GAAG,yBAAyB;IAqBhD;;OAEG;IACH,OAAO,CAAC,0BAA0B;CAMrC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { FunctionJp, StorageClass, Vardecl } from "@specs-feup/clava/api/Joinpoints.js";
|
|
2
|
+
import MISRARule from "../../MISRARule.js";
|
|
3
|
+
import { AnalysisType, MISRATransformationReport, MISRATransformationType } from "../../MISRA.js";
|
|
4
|
+
import { getIdentifierName, isExternalLinkageIdentifier } from "../../utils/IdentifierUtils.js";
|
|
5
|
+
import { findExternalVarRefs, hasMultipleExternalLinkDeclarations, isVarUsed } from "../../utils/VarUtils.js";
|
|
6
|
+
import { findExternalFunctionDecl, isFunctionUsed } from "../../utils/FunctionUtils.js";
|
|
7
|
+
import { resetCaches, resetExternalVarRefs } from "../../utils/ProgramUtils.js";
|
|
8
|
+
/**
|
|
9
|
+
* MISRA-C Rule 8.7: Functions and objects should not be defined with external linkage if they are referenced in only one translation unit
|
|
10
|
+
*/
|
|
11
|
+
export default class Rule_8_7_RestrictExternalLinkage extends MISRARule {
|
|
12
|
+
/**
|
|
13
|
+
* Scope of analysis
|
|
14
|
+
*/
|
|
15
|
+
analysisType = AnalysisType.SYSTEM;
|
|
16
|
+
/**
|
|
17
|
+
* @returns Rule identifier according to MISRA-C:2012
|
|
18
|
+
*/
|
|
19
|
+
get name() {
|
|
20
|
+
return "8.7";
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* External declarations (`extern`) of the current identifier found in other source files.
|
|
24
|
+
*/
|
|
25
|
+
#externalDecls = [];
|
|
26
|
+
/**
|
|
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, logErrors = false) {
|
|
33
|
+
if (!isExternalLinkageIdentifier($jp) || ($jp instanceof FunctionJp && $jp.name === "main")) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
this.#externalDecls = $jp instanceof Vardecl ? findExternalVarRefs($jp) : findExternalFunctionDecl($jp);
|
|
37
|
+
const isUsed = this.#externalDecls.some(decl => decl instanceof Vardecl ? isVarUsed(decl) : isFunctionUsed(decl));
|
|
38
|
+
const nonCompliant = this.#externalDecls.length === 0 || !isUsed;
|
|
39
|
+
if (nonCompliant && logErrors) {
|
|
40
|
+
this.logMISRAError($jp, `${$jp instanceof FunctionJp ? "Function" : "Object"} '${getIdentifierName($jp)}' has external linkage but is only referenced within a single translation unit. Consider using the 'static' keyword to give it internal linkage.`);
|
|
41
|
+
this.#externalDecls.forEach(decl => this.logMISRAError(decl, `'extern' declaration of '${getIdentifierName(decl)}' is unused. The corresponding definition is not referenced outside its translation unit and does not require external linkage.`));
|
|
42
|
+
}
|
|
43
|
+
return nonCompliant;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
*
|
|
47
|
+
* @param $jp - Joinpoint to transform
|
|
48
|
+
* @returns Report detailing the transformation result
|
|
49
|
+
*/
|
|
50
|
+
apply($jp) {
|
|
51
|
+
const previousResult = this.context.getRuleResult(this.ruleID, $jp);
|
|
52
|
+
if (previousResult === MISRATransformationType.NoChange || !this.match($jp)) {
|
|
53
|
+
return new MISRATransformationReport(MISRATransformationType.NoChange);
|
|
54
|
+
}
|
|
55
|
+
this.removeExternalDeclarations();
|
|
56
|
+
if ($jp instanceof Vardecl && hasMultipleExternalLinkDeclarations($jp)) {
|
|
57
|
+
this.logMISRAError($jp, `${$jp instanceof FunctionJp ? "Function" : "Object"} '${getIdentifierName($jp)}' has external linkage but is only referenced within a single translation unit. Couldn't give it internal linkage as it is defined in multiple files.`);
|
|
58
|
+
this.context.addRuleResult(this.ruleID, $jp, MISRATransformationType.NoChange);
|
|
59
|
+
return new MISRATransformationReport(MISRATransformationType.NoChange);
|
|
60
|
+
}
|
|
61
|
+
const identifierJp = $jp;
|
|
62
|
+
identifierJp.setStorageClass(StorageClass.STATIC);
|
|
63
|
+
resetCaches();
|
|
64
|
+
return new MISRATransformationReport(MISRATransformationType.DescendantChange);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Removes unused external declarations (`extern`) of the current identifier found in other source files.
|
|
68
|
+
*/
|
|
69
|
+
removeExternalDeclarations() {
|
|
70
|
+
if (this.#externalDecls.length > 0 && this.#externalDecls[0] instanceof Vardecl) {
|
|
71
|
+
resetExternalVarRefs();
|
|
72
|
+
}
|
|
73
|
+
this.#externalDecls.forEach(decl => decl instanceof FunctionJp ? decl.detach() : decl.parent.detach());
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=Rule_8_7_RestrictExternalLinkage.js.map
|
package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_7_RestrictExternalLinkage.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Rule_8_7_RestrictExternalLinkage.js","sourceRoot":"","sources":["../../../src/rules/Section8_DeclarationsAndDefinitions/Rule_8_7_RestrictExternalLinkage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAsB,YAAY,EAAE,OAAO,EAAU,MAAM,qCAAqC,CAAC;AACpH,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,yBAAyB,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAClG,OAAO,EAAE,iBAAiB,EAAE,2BAA2B,EAAE,MAAM,gCAAgC,CAAC;AAChG,OAAO,EAAE,mBAAmB,EAAE,mCAAmC,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAC9G,OAAO,EAAE,wBAAwB,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACxF,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAEhF;;GAEG;AACH,MA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CAAC;QACD,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,YAAY,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IAC3G,CAAC;CACJ"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Joinpoint } from "@specs-feup/clava/api/Joinpoints.js";
|
|
2
|
+
import MISRARule from "../../MISRARule.js";
|
|
3
|
+
import { AnalysisType, MISRATransformationReport } from "../../MISRA.js";
|
|
4
|
+
/**
|
|
5
|
+
* MISRA-C Rule 8.9: An object should be defined at block scope if its identifier only appears in a single function
|
|
6
|
+
*/
|
|
7
|
+
export default class Rule_8_9_BlockScopeDefinition extends MISRARule {
|
|
8
|
+
/**
|
|
9
|
+
* Scope of analysis
|
|
10
|
+
*/
|
|
11
|
+
readonly analysisType = AnalysisType.SYSTEM;
|
|
12
|
+
/**
|
|
13
|
+
* @returns Rule identifier according to MISRA-C:2012
|
|
14
|
+
*/
|
|
15
|
+
get name(): string;
|
|
16
|
+
/**
|
|
17
|
+
* Checks if the provided joinpoint represents an object definition with internal linkage, whose identifier only appears in a single function.
|
|
18
|
+
*
|
|
19
|
+
* @param $jp - Joinpoint to analyze
|
|
20
|
+
* @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
|
|
21
|
+
* @returns Returns true if the joinpoint violates the rule, false otherwise
|
|
22
|
+
*/
|
|
23
|
+
match($jp: Joinpoint, logErrors?: boolean): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* If the joinpoint represents the definition of an object with internal linkage used exclusively in one function, it is moved to that function's block scope.
|
|
26
|
+
*
|
|
27
|
+
* @param $jp - Joinpoint to transform
|
|
28
|
+
* @returns Report detailing the transformation result
|
|
29
|
+
*/
|
|
30
|
+
apply($jp: Joinpoint): MISRATransformationReport;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=Rule_8_9_BlockScopeDefinition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Rule_8_9_BlockScopeDefinition.d.ts","sourceRoot":"","sources":["../../../src/rules/Section8_DeclarationsAndDefinitions/Rule_8_9_BlockScopeDefinition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,SAAS,EAAW,MAAM,qCAAqC,CAAC;AAClF,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,yBAAyB,EAA2B,MAAM,gBAAgB,CAAC;AAMlG;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,6BAA8B,SAAQ,SAAS;IAChE;;OAEG;IACH,QAAQ,CAAC,YAAY,uBAAuB;IAE5C;;OAEG;IACH,IAAa,IAAI,IAAI,MAAM,CAE1B;IAED;;;;;;OAMG;IACH,KAAK,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,GAAE,OAAe,GAAG,OAAO;IAa1D;;;;;OAKG;IACH,KAAK,CAAC,GAAG,EAAE,SAAS,GAAG,yBAAyB;CAcnD"}
|