@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,317 @@
|
|
|
1
|
+
import { Call, Joinpoint, Program, FileJp, Include } from "@specs-feup/clava/api/Joinpoints.js";
|
|
2
|
+
import { AnalysisType, MISRATransformationReport, MISRATransformationType } from "../../MISRA.js";
|
|
3
|
+
import Query from "@specs-feup/lara/api/weaver/Query.js";
|
|
4
|
+
import { addExternFunctionDecl, findFilesReferencingHeader, getCallsToLibrary, getExternFunctionDecls, getIncludesOfFile, isValidFile } from "../../utils/FileUtils.js";
|
|
5
|
+
import { findFunctionDef } from "../../utils/FunctionUtils.js";
|
|
6
|
+
import UserConfigurableRule from "../UserConfigurableRule.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* Abstract base class for MISRA-C rules that prohibit the use of function of a standard library.
|
|
11
|
+
*
|
|
12
|
+
* Need to implement/define:
|
|
13
|
+
* - analysisType
|
|
14
|
+
* - standardLibrary
|
|
15
|
+
* - invalidFunctions
|
|
16
|
+
* - name()
|
|
17
|
+
*/
|
|
18
|
+
export default abstract class DisallowedStdLibFunctionRule extends UserConfigurableRule {
|
|
19
|
+
/**
|
|
20
|
+
* A positive integer starting from 1 that indicates the rule's priority, determining the order in which rules are applied.
|
|
21
|
+
*/
|
|
22
|
+
readonly priority = 1;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A map that keeps track of invalid usages found in each file.
|
|
26
|
+
*/
|
|
27
|
+
protected invalidFiles = new Map<FileJp, Call[]>();
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The name of the standard library
|
|
31
|
+
*/
|
|
32
|
+
protected abstract standardLibrary: string;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Names of functions from {@link standardLibrary} that are forbidden.
|
|
36
|
+
* If the set is empty, all functions from {@link standardLibrary} are forbidden.
|
|
37
|
+
*/
|
|
38
|
+
protected abstract invalidFunctions: Set<string>;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Calls that could not be resolved and their respective error message, stored to prevent repeated attempts of correction after rebuild.
|
|
42
|
+
*/
|
|
43
|
+
protected unresolvedCalls: Map<string, string> = new Map<string, string>();
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Files where headers were kept because other library features are still used.
|
|
47
|
+
*/
|
|
48
|
+
protected filesWithRetainedHeaders: Set<string> = new Set<string>();
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Specifies the scope of analysis: single unit or entire system.
|
|
52
|
+
*/
|
|
53
|
+
abstract readonly analysisType: AnalysisType;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @returns Rule identifier according to MISRA-C:2012
|
|
57
|
+
*/
|
|
58
|
+
abstract override get name(): string;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Checks if all functions of the library are forbidden
|
|
62
|
+
*/
|
|
63
|
+
private isLibraryFullyDisallowed(): boolean {
|
|
64
|
+
return this.invalidFunctions.size === 0;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Logs a MISRA error when the entire library is disallowed and
|
|
69
|
+
* records the file to track headers that must be retained.
|
|
70
|
+
*
|
|
71
|
+
* @param fileJp - The file in which the disallowed include was found.
|
|
72
|
+
*/
|
|
73
|
+
private logDisallowedInclude(fileJp: FileJp) {
|
|
74
|
+
if (!this.isLibraryFullyDisallowed()) { // Only specific functions are forbidden
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const includeJp = Query.searchFrom(fileJp, Include, {name: this.standardLibrary}).get()[0];
|
|
78
|
+
this.logMISRAError(includeJp, `The system header file <${includeJp.name}> shall not be used.`);
|
|
79
|
+
this.context.addRuleResult(this.ruleID, includeJp, MISRATransformationType.NoChange);
|
|
80
|
+
|
|
81
|
+
if (!this.filesWithRetainedHeaders.has(fileJp.name)) {
|
|
82
|
+
this.filesWithRetainedHeaders.add(fileJp.name);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Logs a MISRA error for a disallowed function call and records
|
|
88
|
+
* the call along with its error message to avoid repeated attempts
|
|
89
|
+
*
|
|
90
|
+
* @param callJp - The disallowed function call
|
|
91
|
+
* @param msg - Description of the violation
|
|
92
|
+
*/
|
|
93
|
+
private logDisallowedCall(callJp: Call, msg: string) {
|
|
94
|
+
this.logMISRAError(callJp, msg);
|
|
95
|
+
this.context.addRuleResult(this.ruleID, callJp, MISRATransformationType.NoChange);
|
|
96
|
+
if (!this.unresolvedCalls.has(callJp.name)) {
|
|
97
|
+
this.unresolvedCalls.set(callJp.name, msg);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Returns the prefix to be used for error messages related to the given joinpoint
|
|
103
|
+
*
|
|
104
|
+
* @param $jp - Joinpoint where the violation was detected
|
|
105
|
+
* @returns Returns a prefix to prepend to error messages if no configuration is specified or if the configuration does not contain a fix for this violation
|
|
106
|
+
*/
|
|
107
|
+
protected getErrorMsgPrefix(callJp: Call): string {
|
|
108
|
+
return `Function '${callJp.name}' of <${this.standardLibrary}> shall not be used.`
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Retrieves a fix for the given joinpoint using the provided configuration file
|
|
113
|
+
* @param $jp - Joinpoint where the violation was detected
|
|
114
|
+
* @return The fix retrieved from the configuration for the violation, or `undefined` if no applicable fix is found.
|
|
115
|
+
*/
|
|
116
|
+
protected getFixFromConfig(callJp: Call): Map<string, string> | undefined {
|
|
117
|
+
const errorMsgPrefix = this.getErrorMsgPrefix(callJp);
|
|
118
|
+
|
|
119
|
+
if (!this.context.config) {
|
|
120
|
+
this.logDisallowedCall(callJp, `${errorMsgPrefix} Extern not added due to missing config file.`);
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
let configFix = this.context.config.get("disallowedFunctions");
|
|
125
|
+
if (!configFix) {
|
|
126
|
+
this.logDisallowedCall(callJp, `${errorMsgPrefix} Extern was not added as \'disallowedFunctions\' is not defined in the configuration file.`);
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (!configFix[this.standardLibrary]) {
|
|
131
|
+
this.logDisallowedCall(callJp, `${errorMsgPrefix} Couldn't add extern due to missing configuration for standard library <${this.standardLibrary}>.`);
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (!configFix[this.standardLibrary][callJp.name]) {
|
|
136
|
+
this.logDisallowedCall(callJp, `${errorMsgPrefix} Couldn't add extern due to missing configuration for function \'${callJp.name}\' of standard library <${this.standardLibrary}>.`);
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const location = configFix[this.standardLibrary][callJp.name]["location"];
|
|
141
|
+
const replacement_func = configFix[this.standardLibrary][callJp.name]["replacement"];
|
|
142
|
+
|
|
143
|
+
if (location === undefined || replacement_func === undefined) {
|
|
144
|
+
this.logDisallowedCall(callJp, `${errorMsgPrefix} Couldn't add extern due to incomplete configuration for function \'${callJp.name}\' of standard library <${this.standardLibrary}>.`);
|
|
145
|
+
return undefined;
|
|
146
|
+
}
|
|
147
|
+
return new Map([
|
|
148
|
+
["function", replacement_func],
|
|
149
|
+
["location", location]
|
|
150
|
+
]);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
*
|
|
155
|
+
* @param $jp - Joinpoint to analyze
|
|
156
|
+
* @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
|
|
157
|
+
* @returns Returns true if the joinpoint violates the rule, false otherwise
|
|
158
|
+
*/
|
|
159
|
+
match($jp: Joinpoint, logErrors: boolean = false): boolean {
|
|
160
|
+
if (!($jp instanceof Program && this.appliesToCurrentStandard())) return false;
|
|
161
|
+
|
|
162
|
+
this.invalidFiles = new Map<FileJp, Call[]>();
|
|
163
|
+
const referencingFiles = findFilesReferencingHeader(this.standardLibrary);
|
|
164
|
+
let nonCompliant = false;
|
|
165
|
+
|
|
166
|
+
for (const fileJp of referencingFiles) {
|
|
167
|
+
const invalidCalls = getCallsToLibrary(fileJp, this.standardLibrary, this.invalidFunctions);
|
|
168
|
+
|
|
169
|
+
if (invalidCalls.length > 0 || this.isLibraryFullyDisallowed()) {
|
|
170
|
+
this.invalidFiles.set(fileJp, invalidCalls);
|
|
171
|
+
nonCompliant = true;
|
|
172
|
+
}
|
|
173
|
+
if (logErrors) {
|
|
174
|
+
invalidCalls.forEach(callJp => this.logMISRAError(callJp, this.getErrorMsgPrefix(callJp)));
|
|
175
|
+
this.logDisallowedInclude(fileJp);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return nonCompliant;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
*
|
|
183
|
+
* @param $jp - Joinpoint to transform
|
|
184
|
+
* @returns Report detailing the transformation result
|
|
185
|
+
*/
|
|
186
|
+
apply($jp: Joinpoint): MISRATransformationReport {
|
|
187
|
+
if (!this.match($jp)) return new MISRATransformationReport(MISRATransformationType.NoChange);
|
|
188
|
+
|
|
189
|
+
let changedDescendant = false;
|
|
190
|
+
for (const [fileJp, invalidCalls] of this.invalidFiles) {
|
|
191
|
+
if (this.solveDisallowedFunctions(fileJp, invalidCalls)) {
|
|
192
|
+
changedDescendant = true;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Rebuild AST if any file changed
|
|
197
|
+
if (changedDescendant) {
|
|
198
|
+
this.rebuildProgram();
|
|
199
|
+
return new MISRATransformationReport(MISRATransformationType.Replacement, Query.root() as Program);
|
|
200
|
+
}
|
|
201
|
+
return new MISRATransformationReport(MISRATransformationType.NoChange);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
private solveDisallowedFunctions(fileJp: FileJp, invalidCalls: Call[]): boolean {
|
|
205
|
+
let externFunctions = this.getExternFunctionDeclIds(fileJp);
|
|
206
|
+
let changedFile = false;
|
|
207
|
+
let solvedCallsCount = 0;
|
|
208
|
+
let solvedCalls = new Map<string, string>();
|
|
209
|
+
|
|
210
|
+
for (const callJp of invalidCalls) {
|
|
211
|
+
if (this.solveDisallowedFunctionCall(callJp, fileJp, externFunctions, solvedCalls)) {
|
|
212
|
+
changedFile = true;
|
|
213
|
+
solvedCallsCount++;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Try to remove the include
|
|
218
|
+
const fixedAllCalls = solvedCallsCount === invalidCalls.length;
|
|
219
|
+
this.removeInclude(fileJp, fixedAllCalls);
|
|
220
|
+
|
|
221
|
+
return changedFile;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
private solveDisallowedFunctionCall(callJp: Call, fileJp: FileJp, externFunctions: Set<string>, solvedCalls: Map<string, string>): boolean {
|
|
225
|
+
if (solvedCalls.has(callJp.name)) {
|
|
226
|
+
callJp.setName(solvedCalls.get(callJp.name)!);
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Skip call if previous AST visit marked it as unfixable
|
|
231
|
+
if (this.context.getRuleResult(this.ruleID, callJp) === MISRATransformationType.NoChange) {
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// Skip call if previous visits, before rebuild, marked it as unfixable
|
|
236
|
+
if (this.unresolvedCalls.has(callJp.name)) {
|
|
237
|
+
this.logDisallowedCall(callJp, this.unresolvedCalls.get(callJp.name)!);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const errorMsgPrefix = this.getErrorMsgPrefix(callJp);
|
|
241
|
+
const configFix = this.getFixFromConfig(callJp);
|
|
242
|
+
|
|
243
|
+
// Skip if config file was not specified or provides an invalid fix
|
|
244
|
+
if (!configFix) {
|
|
245
|
+
return false;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const [location, replacement_func] = [configFix.get("location"), configFix.get("function")];
|
|
249
|
+
const functionDef = findFunctionDef(replacement_func!, location!);
|
|
250
|
+
|
|
251
|
+
// Skip if specified function doesn't exist
|
|
252
|
+
if (!functionDef) {
|
|
253
|
+
this.logDisallowedCall(callJp, `${errorMsgPrefix} Provided file \'${location}\' does not have function definition.`);
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// Skip if specified function doesn't have external linkage
|
|
258
|
+
let externDecl: Joinpoint | undefined;
|
|
259
|
+
if (!externFunctions.has(functionDef.astId)) {
|
|
260
|
+
externDecl = addExternFunctionDecl(fileJp, functionDef);
|
|
261
|
+
|
|
262
|
+
if (externDecl === undefined) {
|
|
263
|
+
this.logDisallowedCall(callJp, `${errorMsgPrefix} Provided definition at \'${location}\' does not have external linkage.`);
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const previousCallName = callJp.name;
|
|
269
|
+
callJp.setName(functionDef.name);
|
|
270
|
+
if (isValidFile(fileJp)) {
|
|
271
|
+
externFunctions.add(functionDef.astId);
|
|
272
|
+
solvedCalls.set(previousCallName, functionDef.name);
|
|
273
|
+
return true;
|
|
274
|
+
} else { // If file does not compile, remove added external declaration and mark call as unfixable
|
|
275
|
+
externDecl?.detach();
|
|
276
|
+
callJp.setName(previousCallName);
|
|
277
|
+
this.logDisallowedCall(callJp, `${errorMsgPrefix} Provided definition at \'${location}\' does not fix the violation.`);
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
private getExternFunctionDeclIds(fileJp: FileJp): Set<string> {
|
|
283
|
+
return new Set(
|
|
284
|
+
getExternFunctionDecls(fileJp)
|
|
285
|
+
.filter((funcJp) => funcJp.definitionJp !== undefined)
|
|
286
|
+
.map((funcJp) => funcJp.definitionJp.astId)
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Removes the standard library include if it is fully disallowed and all invalid calls were fixed.
|
|
292
|
+
* If the file is invalid after include removal because other library features are still being used (e.g.: typedefs), the include is re-added.
|
|
293
|
+
*
|
|
294
|
+
* @param fileJp The file to modify
|
|
295
|
+
* @param fixedAllCalls Flag to indicate whether all calls were fixed
|
|
296
|
+
*/
|
|
297
|
+
private removeInclude(fileJp: FileJp, fixedAllCalls: boolean) {
|
|
298
|
+
if (!this.isLibraryFullyDisallowed()) return;
|
|
299
|
+
|
|
300
|
+
const includeJp = Query.searchFrom(fileJp, Include, {name: this.standardLibrary}).get()[0];
|
|
301
|
+
const ruleResult = this.context.getRuleResult(this.ruleID, includeJp);
|
|
302
|
+
|
|
303
|
+
if (ruleResult !== undefined) return;
|
|
304
|
+
|
|
305
|
+
if (this.filesWithRetainedHeaders.has(fileJp.name) || !fixedAllCalls) { // Keep include and log MISRA error
|
|
306
|
+
this.logDisallowedInclude(fileJp);
|
|
307
|
+
} else {
|
|
308
|
+
includeJp.detach();
|
|
309
|
+
|
|
310
|
+
// Re-add include and log error if any other library features are still referenced
|
|
311
|
+
if (!isValidFile(fileJp)) {
|
|
312
|
+
fileJp.addInclude(this.standardLibrary, true);
|
|
313
|
+
this.logDisallowedInclude(fileJp);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { AnalysisType } from "../../MISRA.js";
|
|
2
|
+
import DisallowedStdLibFunctionRule from "./DisallowedStdLibFunctionRule.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* MISRA-C Rule 21.10: The Standard Library time and date functions shall not be used
|
|
6
|
+
*/
|
|
7
|
+
export default class Rule_21_10_NoTimeDateFunctions extends DisallowedStdLibFunctionRule {
|
|
8
|
+
/**
|
|
9
|
+
* The name of the standard library
|
|
10
|
+
*/
|
|
11
|
+
protected standardLibrary = "time.h";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Names of functions from {@link standardLibrary} that are forbidden.
|
|
15
|
+
* If the set is empty, all functions from {@link standardLibrary} are forbidden.
|
|
16
|
+
*/
|
|
17
|
+
protected invalidFunctions = new Set<string>();
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Scope of analysis
|
|
21
|
+
*/
|
|
22
|
+
readonly analysisType = AnalysisType.SINGLE_TRANSLATION_UNIT;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @returns Rule identifier according to MISRA-C:2012
|
|
26
|
+
*/
|
|
27
|
+
override get name(): string {
|
|
28
|
+
return "21.10";
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { AnalysisType } from "../../MISRA.js";
|
|
2
|
+
import DisallowedStdLibFunctionRule from "./DisallowedStdLibFunctionRule.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* MISRA-C Rule 21.11: The standard header file <tgmath.h> shall not be used
|
|
6
|
+
*/
|
|
7
|
+
export default class Rule_21_11_NoTgmathFunctions extends DisallowedStdLibFunctionRule {
|
|
8
|
+
/**
|
|
9
|
+
* The name of the standard library
|
|
10
|
+
*/
|
|
11
|
+
protected standardLibrary = "tgmath.h";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Names of functions from {@link standardLibrary} that are forbidden.
|
|
15
|
+
* If the set is empty, all functions from {@link standardLibrary} are forbidden.
|
|
16
|
+
*/
|
|
17
|
+
protected invalidFunctions = new Set<string>();
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Standards to which this rule applies to
|
|
21
|
+
*/
|
|
22
|
+
protected override readonly appliesTo = new Set(["c99", "c11"]);
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Scope of analysis
|
|
26
|
+
*/
|
|
27
|
+
readonly analysisType = AnalysisType.SINGLE_TRANSLATION_UNIT;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @returns Rule identifier according to MISRA-C:2012
|
|
31
|
+
*/
|
|
32
|
+
override get name(): string {
|
|
33
|
+
return "21.11";
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { AnalysisType } from "../../MISRA.js";
|
|
2
|
+
import DisallowedStdLibFunctionRule from "./DisallowedStdLibFunctionRule.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* MISRA-C Rule 21.3: The memory allocation and deallocation functions of <stdlib.h> shall not be used
|
|
6
|
+
*/
|
|
7
|
+
export default class Rule_21_3_NoDynamicMemory extends DisallowedStdLibFunctionRule {
|
|
8
|
+
/**
|
|
9
|
+
* The name of the standard library
|
|
10
|
+
*/
|
|
11
|
+
protected standardLibrary = "stdlib.h";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Names of functions from {@link standardLibrary} that are forbidden.
|
|
15
|
+
* If the set is empty, all functions from {@link standardLibrary} are forbidden.
|
|
16
|
+
*/
|
|
17
|
+
protected invalidFunctions = new Set(["calloc", "malloc", "aligned_alloc", "realloc", "free"]);
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Scope of analysis
|
|
21
|
+
*/
|
|
22
|
+
readonly analysisType = AnalysisType.SINGLE_TRANSLATION_UNIT;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @returns Rule identifier according to MISRA-C:2012
|
|
26
|
+
*/
|
|
27
|
+
override get name(): string {
|
|
28
|
+
return "21.3";
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { AnalysisType } from "../../MISRA.js";
|
|
2
|
+
import DisallowedStdLibFunctionRule from "./DisallowedStdLibFunctionRule.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* MISRA-C Rule 21.6: The Standard Library input/output functions shall not be used
|
|
6
|
+
*/
|
|
7
|
+
export default class Rule_21_6_NoStdIOFunctions extends DisallowedStdLibFunctionRule {
|
|
8
|
+
/**
|
|
9
|
+
* The name of the standard library
|
|
10
|
+
*/
|
|
11
|
+
protected standardLibrary = "stdio.h";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Names of functions from {@link standardLibrary} that are forbidden.
|
|
15
|
+
* If the set is empty, all functions from {@link standardLibrary} are forbidden.
|
|
16
|
+
*/
|
|
17
|
+
protected invalidFunctions = new Set<string>();
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Scope of analysis
|
|
21
|
+
*/
|
|
22
|
+
readonly analysisType = AnalysisType.SINGLE_TRANSLATION_UNIT;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @returns Rule identifier according to MISRA-C:2012
|
|
26
|
+
*/
|
|
27
|
+
override get name(): string {
|
|
28
|
+
return "21.6";
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { AnalysisType } from "../../MISRA.js";
|
|
2
|
+
import DisallowedStdLibFunctionRule from "./DisallowedStdLibFunctionRule.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* MISRA-C Rule 21.7: The atof, atoi, atol and atoll functions of <stdlib.h> shall not be used.
|
|
6
|
+
*/
|
|
7
|
+
export default class Rule_21_7_NoNumericStringConversions extends DisallowedStdLibFunctionRule {
|
|
8
|
+
/**
|
|
9
|
+
* The name of the standard library
|
|
10
|
+
*/
|
|
11
|
+
protected standardLibrary = "stdlib.h";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Names of functions from {@link standardLibrary} that are forbidden.
|
|
15
|
+
* If the set is empty, all functions from {@link standardLibrary} are forbidden.
|
|
16
|
+
*/
|
|
17
|
+
protected invalidFunctions = new Set(["atof", "atoi", "atol", "atoll"]);
|
|
18
|
+
/**
|
|
19
|
+
* Scope of analysis
|
|
20
|
+
*/
|
|
21
|
+
readonly analysisType = AnalysisType.SINGLE_TRANSLATION_UNIT;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @returns Rule identifier according to MISRA-C:2012
|
|
25
|
+
*/
|
|
26
|
+
override get name(): string {
|
|
27
|
+
return "21.7";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { AnalysisType } from "../../MISRA.js";
|
|
2
|
+
import DisallowedStdLibFunctionRule from "./DisallowedStdLibFunctionRule.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* MISRA-C Rule 21.8: The library functions abort, exit, getenv and system of <stdlib.h>
|
|
6
|
+
* shall not be used
|
|
7
|
+
*/
|
|
8
|
+
export default class Rule_21_8_NoProcessControlFunctions extends DisallowedStdLibFunctionRule {
|
|
9
|
+
/**
|
|
10
|
+
* Standards to which this rule applies to
|
|
11
|
+
*/
|
|
12
|
+
protected override readonly appliesTo = new Set(["c90", "c99"]);
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The name of the standard library
|
|
16
|
+
*/
|
|
17
|
+
protected standardLibrary = "stdlib.h";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Names of functions from {@link standardLibrary} that are forbidden.
|
|
21
|
+
* If the set is empty, all functions from {@link standardLibrary} are forbidden.
|
|
22
|
+
*/
|
|
23
|
+
protected invalidFunctions = new Set(["abort", "exit", "getenv", "system"]);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Scope of analysis
|
|
27
|
+
*/
|
|
28
|
+
readonly analysisType = AnalysisType.SINGLE_TRANSLATION_UNIT;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @returns Rule identifier according to MISRA-C:2012
|
|
32
|
+
*/
|
|
33
|
+
override get name(): string {
|
|
34
|
+
return "21.8";
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { AnalysisType } from "../../MISRA.js";
|
|
2
|
+
import DisallowedStdLibFunctionRule from "./DisallowedStdLibFunctionRule.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* MISRA-C Rule 21.9: The library functions bsearch and qsort of <stdlib.h> shall not be used.
|
|
6
|
+
*/
|
|
7
|
+
export default class Rule_21_9_NoGenericSearchOrSort extends DisallowedStdLibFunctionRule {
|
|
8
|
+
/**
|
|
9
|
+
* The name of the standard library
|
|
10
|
+
*/
|
|
11
|
+
protected standardLibrary = "stdlib.h";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Names of functions from {@link standardLibrary} that are forbidden.
|
|
15
|
+
* If the set is empty, all functions from {@link standardLibrary} are forbidden.
|
|
16
|
+
*/
|
|
17
|
+
protected invalidFunctions = new Set(["bsearch", "qsort"]);
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Scope of analysis
|
|
21
|
+
*/
|
|
22
|
+
readonly analysisType = AnalysisType.SINGLE_TRANSLATION_UNIT;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @returns Rule identifier according to MISRA-C:2012
|
|
26
|
+
*/
|
|
27
|
+
override get name(): string {
|
|
28
|
+
return "21.9";
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -1,38 +1,23 @@
|
|
|
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 {
|
|
3
|
+
import { AnalysisType, MISRATransformationReport, MISRATransformationType } from "../../MISRA.js";
|
|
4
|
+
import { getTypeDefDecl, isTypeDeclUsed } from "../../utils/TypeDeclUtils.js";
|
|
5
|
+
import { isTagDecl } from "../../utils/JoinpointUtils.js";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* MISRA-C Rule 2.3: A project should not contain unused type declarations.
|
|
9
9
|
*/
|
|
10
10
|
export default class Rule_2_3_UnusedTypeDecl extends MISRARule {
|
|
11
|
-
priority = 3;
|
|
12
|
-
|
|
13
|
-
constructor(context: MISRAContext) {
|
|
14
|
-
super("2.3", context);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
11
|
/**
|
|
18
|
-
*
|
|
19
|
-
* @param jp - The joinpoint to check
|
|
20
|
-
* @param typeDecl - The typedef declaration to check against
|
|
21
|
-
* @returns Returns true if the joinpoint uses the given typedef declaration, false otherwise
|
|
12
|
+
* Scope of analysis
|
|
22
13
|
*/
|
|
23
|
-
|
|
24
|
-
const jpType = getBaseType(jp);
|
|
25
|
-
return !jpType?.isBuiltin && jpType instanceof TypedefType && jpType.decl.astId === typeDecl.astId;
|
|
26
|
-
}
|
|
14
|
+
readonly analysisType = AnalysisType.SYSTEM;
|
|
27
15
|
|
|
28
16
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* @param typeDecl - The typedef declaration to search for in the joinpoints
|
|
32
|
-
* @returns Array of joinpoints that use the given typedef declaration
|
|
17
|
+
* @returns Rule identifier according to MISRA-C:2012
|
|
33
18
|
*/
|
|
34
|
-
|
|
35
|
-
return
|
|
19
|
+
override get name(): string {
|
|
20
|
+
return "2.3";
|
|
36
21
|
}
|
|
37
22
|
|
|
38
23
|
/**
|
|
@@ -42,12 +27,12 @@ export default class Rule_2_3_UnusedTypeDecl extends MISRARule {
|
|
|
42
27
|
* @returns Returns true if the joinpoint violates the rule, false otherwise
|
|
43
28
|
*/
|
|
44
29
|
match($jp: Joinpoint, logErrors: boolean = false): boolean {
|
|
45
|
-
const typeDecl =
|
|
30
|
+
const typeDecl = getTypeDefDecl($jp);
|
|
46
31
|
if (typeDecl === undefined) return false;
|
|
47
32
|
|
|
48
|
-
const isUnused =
|
|
33
|
+
const isUnused = !isTypeDeclUsed(typeDecl);
|
|
49
34
|
if (logErrors && isUnused) {
|
|
50
|
-
this.logMISRAError($jp, `Type declaration ${typeDecl.name} is declared but not used.`)
|
|
35
|
+
this.logMISRAError($jp, `Type declaration '${typeDecl.name}' is declared but not used.`)
|
|
51
36
|
}
|
|
52
37
|
return isUnused;
|
|
53
38
|
}
|
|
@@ -62,11 +47,11 @@ export default class Rule_2_3_UnusedTypeDecl extends MISRARule {
|
|
|
62
47
|
* @param $jp - Joinpoint to transform
|
|
63
48
|
* @returns Report detailing the transformation result
|
|
64
49
|
*/
|
|
65
|
-
|
|
50
|
+
apply($jp: Joinpoint): MISRATransformationReport {
|
|
66
51
|
if (!this.match($jp))
|
|
67
52
|
return new MISRATransformationReport(MISRATransformationType.NoChange);
|
|
68
53
|
|
|
69
|
-
if (($jp
|
|
54
|
+
if (isTagDecl($jp) && $jp.name && isTypeDeclUsed($jp)) {
|
|
70
55
|
$jp.lastChild.detach();
|
|
71
56
|
return new MISRATransformationReport(MISRATransformationType.DescendantChange);
|
|
72
57
|
} else {
|