@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,107 @@
|
|
|
1
|
+
import { Vardecl, FunctionJp, LabelStmt, NamedDecl, StorageClass } from "@specs-feup/clava/api/Joinpoints.js";
|
|
2
|
+
import Query from "@specs-feup/lara/api/weaver/Query.js";
|
|
3
|
+
import { isExternalLinkageIdentifier, isIdentifierDecl, isInternalLinkageIdentifier } from "./IdentifierUtils.js";
|
|
4
|
+
|
|
5
|
+
let cachedInternalLinkageIdentifiers: (FunctionJp | Vardecl)[] | null = null;
|
|
6
|
+
let cachedExternalLinkageIdentifiers: (FunctionJp | Vardecl)[] | null = null;
|
|
7
|
+
let cachedExternalLinkageVars: (Vardecl)[] | null = null;
|
|
8
|
+
let cachedExternalVarRefs: (Vardecl)[] | null = null;
|
|
9
|
+
let cachedIdentifierDecls: any[] | null = null;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Clears all cached identifiers and variable references
|
|
13
|
+
*/
|
|
14
|
+
export function resetCaches() {
|
|
15
|
+
cachedInternalLinkageIdentifiers = null;
|
|
16
|
+
cachedExternalLinkageIdentifiers = null;
|
|
17
|
+
cachedExternalLinkageVars = null;
|
|
18
|
+
cachedExternalVarRefs = null;
|
|
19
|
+
cachedIdentifierDecls = null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Clears the cache of external variable references
|
|
24
|
+
*/
|
|
25
|
+
export function resetExternalVarRefs() {
|
|
26
|
+
cachedExternalVarRefs = null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Retrieves all variables and functions that are eligible for `extern` linkage, i.e.,
|
|
31
|
+
* elements with storage classes that are not `STATIC` or `EXTERN`
|
|
32
|
+
*
|
|
33
|
+
* @returns Array of functions and variables that can be declared as external
|
|
34
|
+
*/
|
|
35
|
+
export function getExternalLinkageIdentifiers(): (FunctionJp | Vardecl)[] {
|
|
36
|
+
if (cachedExternalLinkageIdentifiers !== null) {
|
|
37
|
+
return cachedExternalLinkageIdentifiers;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const externalLinkageVarDecls = getExternalLinkageVars();
|
|
41
|
+
const externalLinkageFunctions = Query.search(FunctionJp, (varDeclJp) => isExternalLinkageIdentifier(varDeclJp)).get();
|
|
42
|
+
|
|
43
|
+
cachedExternalLinkageIdentifiers = [
|
|
44
|
+
...externalLinkageFunctions,
|
|
45
|
+
...externalLinkageVarDecls
|
|
46
|
+
];
|
|
47
|
+
return cachedExternalLinkageIdentifiers;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Gets identifiers with internal linkage
|
|
52
|
+
*
|
|
53
|
+
* @returns List of functions and variable declarations with internal linkage
|
|
54
|
+
*/
|
|
55
|
+
export function getInternalLinkageIdentifiers(): (FunctionJp | Vardecl)[] {
|
|
56
|
+
if (cachedInternalLinkageIdentifiers !== null) {
|
|
57
|
+
return cachedInternalLinkageIdentifiers;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const internalLinkageVarsDecls = Query.search(Vardecl, (decl) => isInternalLinkageIdentifier(decl)).get();
|
|
61
|
+
const internalLinkageFunctions = Query.search(FunctionJp, (decl) => isInternalLinkageIdentifier(decl)).get();
|
|
62
|
+
cachedInternalLinkageIdentifiers = [
|
|
63
|
+
...internalLinkageFunctions,
|
|
64
|
+
...internalLinkageVarsDecls
|
|
65
|
+
];
|
|
66
|
+
return cachedInternalLinkageIdentifiers;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Gets identifiers with external linkage
|
|
71
|
+
*
|
|
72
|
+
* @returns List of functions and variable declarations with external linkage
|
|
73
|
+
*/
|
|
74
|
+
export function getExternalLinkageVars(): Vardecl[] {
|
|
75
|
+
if (cachedExternalLinkageVars != null) {
|
|
76
|
+
return cachedExternalLinkageVars;
|
|
77
|
+
}
|
|
78
|
+
cachedExternalLinkageVars = Query.search(Vardecl, (varDeclJp) => isExternalLinkageIdentifier(varDeclJp)).get();
|
|
79
|
+
return cachedExternalLinkageVars;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Gets all variable declared with 'extern'
|
|
84
|
+
*
|
|
85
|
+
* @returns List of variable declarations with extern storage class
|
|
86
|
+
*/
|
|
87
|
+
export function getExternalVarRefs(): Vardecl[] {
|
|
88
|
+
if (cachedExternalVarRefs !== null) {
|
|
89
|
+
return cachedExternalVarRefs;
|
|
90
|
+
}
|
|
91
|
+
cachedExternalVarRefs = Query.search(Vardecl, {storageClass: StorageClass.EXTERN}).get();
|
|
92
|
+
return cachedExternalVarRefs;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Gets all named declarations and labels
|
|
97
|
+
*/
|
|
98
|
+
export function getIdentifierDecls(): any[] {
|
|
99
|
+
if (cachedIdentifierDecls !== null) {
|
|
100
|
+
return cachedIdentifierDecls;
|
|
101
|
+
}
|
|
102
|
+
cachedIdentifierDecls = [
|
|
103
|
+
...Query.search(NamedDecl).get(),
|
|
104
|
+
...Query.search(LabelStmt).get(),
|
|
105
|
+
].filter((jp) => isIdentifierDecl(jp));
|
|
106
|
+
return cachedIdentifierDecls;
|
|
107
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { BinaryOp, Break, BuiltinType, Case, Joinpoint, Switch, UnaryOp } from "@specs-feup/clava/api/Joinpoints.js";
|
|
2
|
+
import Query from "@specs-feup/lara/api/weaver/Query.js";
|
|
3
|
+
import { hasDefinedType } from "./JoinpointUtils.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Retrieves the last statement of the given case
|
|
7
|
+
* @param $jp - The case to retrieve the last statement from
|
|
8
|
+
* @returns The last statement of the case or undefined if there are no statements or it has a consecutive case.
|
|
9
|
+
*/
|
|
10
|
+
export function getLastStmtOfCase($jp: Case): Joinpoint | undefined {
|
|
11
|
+
if ($jp.instructions.length === 0) { // Has a consecutive case
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let caseScopeStmts: Joinpoint[] = [];
|
|
16
|
+
for (const stmt of $jp.siblingsRight) {
|
|
17
|
+
if (stmt instanceof Case) {
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
caseScopeStmts.push(stmt);
|
|
21
|
+
}
|
|
22
|
+
return !caseScopeStmts.some(stmt => stmt instanceof Break) ?
|
|
23
|
+
caseScopeStmts[caseScopeStmts.length - 1] :
|
|
24
|
+
caseScopeStmts.find(stmt => stmt instanceof Break);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Retrieves the number of switch clauses with instructions in the provided switch statement
|
|
29
|
+
* @param $jp - The switch statement to analyze
|
|
30
|
+
* @returns The number of switch clauses with instructions
|
|
31
|
+
*/
|
|
32
|
+
export function countSwitchClauses($jp: Switch): number {
|
|
33
|
+
let firstStatements = []
|
|
34
|
+
|
|
35
|
+
for (const caseLabel of $jp.cases) {
|
|
36
|
+
if (caseLabel.instructions.length === 0) { // Has a consecutive case
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
firstStatements.push(caseLabel.instructions[0])
|
|
40
|
+
}
|
|
41
|
+
return firstStatements.length;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Checks if the provided switch statement contains any conditional break
|
|
46
|
+
*
|
|
47
|
+
* @param switchStmt - The switch statement to analyze
|
|
48
|
+
* @returns Returns true if the switch statement contains a conditional break, otherwise false
|
|
49
|
+
*/
|
|
50
|
+
export function hasConditionalBreak(switchStmt: Switch): boolean {
|
|
51
|
+
return Query.searchFrom(switchStmt, Break, { currentRegion: region => region.astId !== switchStmt.astId, enclosingStmt: jp => jp.astId === switchStmt.astId }).get().length > 0;
|
|
52
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Joinpoint, TypedefDecl, DeclStmt, TypedefType, ElaboratedType, TagType, FileJp, EnumDecl, EnumeratorDecl, Varref } from "@specs-feup/clava/api/Joinpoints.js";
|
|
2
|
+
import Query from "@specs-feup/lara/api/weaver/Query.js";
|
|
3
|
+
import { getBaseType } from "./JoinpointUtils.js";
|
|
4
|
+
import { isTagDecl, TagDecl } from "./JoinpointUtils.js";
|
|
5
|
+
import { findFilesReferencingHeader, getIncludesOfFile } from "./FileUtils.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Retrieves the typedef declaration for the provided joinpoint, if available
|
|
9
|
+
* @param $jp The joinpoint to analyze
|
|
10
|
+
* @returns The typedef declaration if found, or undefined if not
|
|
11
|
+
*/
|
|
12
|
+
export function getTypeDefDecl($jp: Joinpoint): TypedefDecl | undefined {
|
|
13
|
+
if ($jp instanceof DeclStmt && $jp.children.length === 1 && $jp.children[0] instanceof TypedefDecl)
|
|
14
|
+
return $jp.children[0];
|
|
15
|
+
|
|
16
|
+
if (isTagDecl($jp)) {
|
|
17
|
+
const typeDecls = Query.searchFrom($jp, TypedefDecl).get();
|
|
18
|
+
if (typeDecls.length === 1)
|
|
19
|
+
return typeDecls[0];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Checks if the provided joinpoint declares a type (typedef)
|
|
25
|
+
* @param $jp The joinpoint to check
|
|
26
|
+
* @returns Returns true if the joinpoint declares a typedef, otherwise false
|
|
27
|
+
*/
|
|
28
|
+
export function hasTypeDefDecl($jp: Joinpoint): boolean {
|
|
29
|
+
return getTypeDefDecl($jp) !== undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Checks if a given joinpoint uses the specified typedef declaration.
|
|
34
|
+
* @param jp - The joinpoint to check
|
|
35
|
+
* @param typeDecl - The typedef declaration to check against
|
|
36
|
+
* @returns Returns true if the joinpoint uses the given typedef declaration, false otherwise
|
|
37
|
+
*/
|
|
38
|
+
export function jpUsesTypedef(jp: Joinpoint, typeDecl: TypedefDecl): boolean {
|
|
39
|
+
const jpType = getBaseType(jp);
|
|
40
|
+
|
|
41
|
+
return !jpType?.isBuiltin && (
|
|
42
|
+
(jpType instanceof TypedefType &&jpType.decl.astId === typeDecl.astId) ||
|
|
43
|
+
(jpType instanceof ElaboratedType && jpType.namedType instanceof TypedefType &&jpType.namedType.decl.astId === typeDecl.astId)
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Checks if a given joinpoint uses the specified tag declaration
|
|
49
|
+
* @param $jp The joinpoint to analyze
|
|
50
|
+
* @param tag The tag to check against
|
|
51
|
+
* @returns Returns true if the joinpoint uses the given tag, false otherwise
|
|
52
|
+
*/
|
|
53
|
+
export function jpUsesTag($jp: Joinpoint, tag: TagDecl): boolean {
|
|
54
|
+
if (tag instanceof EnumDecl && $jp instanceof Varref && getTypeDefDecl(tag) === undefined) {
|
|
55
|
+
const enumeratorsIDs = tag.enumerators.map(enumerator => enumerator.astId);
|
|
56
|
+
const decl = $jp.getValue("decl");
|
|
57
|
+
if (decl instanceof EnumeratorDecl && enumeratorsIDs.includes(decl.astId)) {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const jpType = getBaseType($jp);
|
|
63
|
+
return jpType instanceof ElaboratedType &&
|
|
64
|
+
jpType.namedType instanceof TagType &&
|
|
65
|
+
jpType.namedType.decl.astId === tag.astId &&
|
|
66
|
+
$jp.astId !== getTypeDefDecl(tag)?.astId
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Checks if the provided typedef or tag declaration is used in any part of the program
|
|
71
|
+
* @param decl - typedef or tag declaration to verify
|
|
72
|
+
* @returns Returns true if the declaration is used, false otherwise
|
|
73
|
+
*/
|
|
74
|
+
export function isTypeDeclUsed(decl: TypedefDecl | TagDecl): boolean {
|
|
75
|
+
const fileJp = decl.getAncestor("file") as FileJp;
|
|
76
|
+
let jps: Joinpoint[] = [];
|
|
77
|
+
|
|
78
|
+
if (fileJp.isHeader) {
|
|
79
|
+
const referencingFiles = findFilesReferencingHeader(fileJp.name);
|
|
80
|
+
jps = [...fileJp.descendants, ...referencingFiles.flatMap(file => file.descendants)];
|
|
81
|
+
} else {
|
|
82
|
+
jps = fileJp.descendants;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return decl instanceof TypedefDecl ?
|
|
86
|
+
jps.some(jp => jpUsesTypedef(jp, decl)) :
|
|
87
|
+
jps.some(jp => jpUsesTag(jp, decl));
|
|
88
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { FileJp, FunctionJp, Joinpoint, QualType, StorageClass, Vardecl, Varref } from "@specs-feup/clava/api/Joinpoints.js";
|
|
2
|
+
import Query from "@specs-feup/lara/api/weaver/Query.js";
|
|
3
|
+
import { getIdentifierName, isExternalLinkageIdentifier } from "./IdentifierUtils.js";
|
|
4
|
+
import { getExternalLinkageIdentifiers, getExternalLinkageVars, getExternalVarRefs } from "./ProgramUtils.js";
|
|
5
|
+
import { findFilesReferencingHeader } from "./FileUtils.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Retrieves all variable references qualified as "volatile" starting from the given joinpoint
|
|
9
|
+
* @param $jp Starting joinpoint
|
|
10
|
+
* @returns Array of variable references qualified as volatile
|
|
11
|
+
*/
|
|
12
|
+
export function getVolatileVarRefs($jp: Joinpoint): Varref[] {
|
|
13
|
+
return Query.searchFromInclusive($jp, Varref, (ref) => {
|
|
14
|
+
try {
|
|
15
|
+
return ref.type instanceof QualType && ref.type.qualifiers?.includes("volatile")
|
|
16
|
+
} catch (error) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}).get();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Retrieves all external references of the given variable
|
|
24
|
+
*
|
|
25
|
+
* @param $varDecl variable to match by name.
|
|
26
|
+
* @returns Array of external references with the same name as the given variable.
|
|
27
|
+
*/
|
|
28
|
+
export function findExternalVarRefs($varDecl: Vardecl): Vardecl[] {
|
|
29
|
+
return getExternalVarRefs().filter(ref => ref.name === $varDecl.name);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Identifies functions in the same file that reference the specified variable declaration
|
|
34
|
+
*
|
|
35
|
+
* @param $jp The variable declaration
|
|
36
|
+
* @returns An array of functions that reference the variable
|
|
37
|
+
*/
|
|
38
|
+
export function findReferencingFunctions($jp: Vardecl): FunctionJp[] {
|
|
39
|
+
const fileJp = $jp.getAncestor("file");
|
|
40
|
+
const functionsJp = Query.searchFrom(fileJp, FunctionJp).get();
|
|
41
|
+
|
|
42
|
+
return functionsJp
|
|
43
|
+
.filter(funcJp =>
|
|
44
|
+
Query.searchFrom(funcJp, Varref, {decl: (declJp) => declJp?.astId === $jp.astId}).get().length > 0
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Finds duplicate definitions of the given variable declaration among external linkage variables
|
|
50
|
+
*
|
|
51
|
+
* @param $jp The variable declaration to evaluate
|
|
52
|
+
* @returns An array of variable declarations representing duplicates
|
|
53
|
+
*/
|
|
54
|
+
export function findDuplicateVarDefinition($jp: Vardecl): Vardecl[] {
|
|
55
|
+
return getExternalLinkageVars().filter((varDeclJp) => varDeclJp.astId !== $jp.astId && isSameVarDecl(varDeclJp, $jp));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Checks whether two joinpoints represent the same variable declaration by comparing identifier name, type, and external linkage
|
|
60
|
+
*
|
|
61
|
+
* @param $jp1 The first join point
|
|
62
|
+
* @param $jp2 The second join point
|
|
63
|
+
* @returns True if both are equivalent external variable declarations, false otherwise
|
|
64
|
+
*/
|
|
65
|
+
export function isSameVarDecl($jp1: Joinpoint, $jp2: Joinpoint): boolean {
|
|
66
|
+
return $jp1 instanceof Vardecl && $jp2 instanceof Vardecl &&
|
|
67
|
+
isExternalLinkageIdentifier($jp1) && isExternalLinkageIdentifier($jp2) &&
|
|
68
|
+
getIdentifierName($jp1) === getIdentifierName($jp2) &&
|
|
69
|
+
$jp1.type.code === $jp2.type.code
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Checks if the given variable has multiple external linkage declarations across different files
|
|
74
|
+
*
|
|
75
|
+
* @param $jp The variable declaration to evaluate
|
|
76
|
+
* @returns True if multiple external declarations exist, false otherwise
|
|
77
|
+
*/
|
|
78
|
+
|
|
79
|
+
export function hasMultipleExternalLinkDeclarations($jp: Vardecl): boolean {
|
|
80
|
+
return getExternalLinkageIdentifiers().some(identifier =>
|
|
81
|
+
isSameVarDecl(identifier, $jp) && identifier.getAncestor("file").ast !== $jp.getAncestor("file").ast
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Checks whether the given variable declaration is used in its file or in files that include its header.
|
|
87
|
+
*
|
|
88
|
+
* @param varDecl The variable declaration to check
|
|
89
|
+
* @returns True if the variable is referenced, false otherwise
|
|
90
|
+
*/
|
|
91
|
+
export function isVarUsed(varDecl: Vardecl): boolean {
|
|
92
|
+
const fileJp = varDecl.getAncestor("file") as FileJp;
|
|
93
|
+
let referencingFiles: FileJp[];
|
|
94
|
+
|
|
95
|
+
if (fileJp.isHeader) {
|
|
96
|
+
const filesWithInclude = findFilesReferencingHeader(fileJp.name);
|
|
97
|
+
referencingFiles = [fileJp, ...filesWithInclude];
|
|
98
|
+
} else {
|
|
99
|
+
referencingFiles = [fileJp];
|
|
100
|
+
}
|
|
101
|
+
return referencingFiles.some(fileJp => Query.searchFrom(fileJp, Varref, {name: varDecl.name, decl: (declJp) => declJp?.astId === varDecl.astId}).get().length > 0)
|
|
102
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { FileJp, Include, Joinpoint } from "@specs-feup/clava/api/Joinpoints.js";
|
|
2
|
-
import MISRARule from "../../MISRARule.js";
|
|
3
|
-
import MISRAContext from "../../MISRAContext.js";
|
|
4
|
-
import { MISRATransformationReport, MISRATransformationType } from "../../MISRA.js";
|
|
5
|
-
import Query from "@specs-feup/lara/api/weaver/Query.js";
|
|
6
|
-
import * as path from 'path';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* MISRA Rule 20.2: The ', " or \ characters and the /* or // character sequences shall not occur in a header filename
|
|
10
|
-
*/
|
|
11
|
-
export default class Rule_20_2_InvalidHeaderFileName extends MISRARule {
|
|
12
|
-
constructor(context: MISRAContext) {
|
|
13
|
-
super("20.2", context);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Checks if the given joinpoint is a header file whose name includes invalid characters.
|
|
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 = false): boolean {
|
|
24
|
-
if (!($jp instanceof FileJp && $jp.isHeader)) return false;
|
|
25
|
-
|
|
26
|
-
const isNonCompliant = /.*('|"|\\|\/\*|\/\/).*/.test($jp.name);
|
|
27
|
-
if (isNonCompliant && logErrors) {
|
|
28
|
-
this.logMISRAError($jp, `Invalid characters in header filename. Invalid characters are ', ", \\, and the sequences /* and //.`)
|
|
29
|
-
}
|
|
30
|
-
return isNonCompliant;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Renames a header file to ensure it contains only valid characters and updates all related includes accordingly.
|
|
35
|
-
*
|
|
36
|
-
* @param $jp - Joinpoint to transform
|
|
37
|
-
* @returns Report detailing the transformation result
|
|
38
|
-
*/
|
|
39
|
-
transform($jp: Joinpoint): MISRATransformationReport {
|
|
40
|
-
if (!this.match($jp)) {
|
|
41
|
-
return new MISRATransformationReport(MISRATransformationType.NoChange);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const fileJp = $jp as FileJp;
|
|
45
|
-
const includesOfHeader = this.getMatchingIncludes(fileJp);
|
|
46
|
-
const newFilename = this.context.generateHeaderFilename();
|
|
47
|
-
|
|
48
|
-
fileJp.setName(newFilename);
|
|
49
|
-
this.updateIncludes(includesOfHeader, newFilename);
|
|
50
|
-
return new MISRATransformationReport(MISRATransformationType.DescendantChange);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Finds all include joinpoints that reference a specific header file
|
|
55
|
-
*
|
|
56
|
-
* @param headerFileJp - The header file joinpoint
|
|
57
|
-
* @returns List of matching include statements
|
|
58
|
-
*/
|
|
59
|
-
private getMatchingIncludes(headerFileJp: FileJp): Include[] {
|
|
60
|
-
return Query.search(Include).get().filter(includeJp =>
|
|
61
|
-
path.basename(includeJp.name) === headerFileJp.name &&
|
|
62
|
-
this.getHeaderFilePath(includeJp) === headerFileJp.path);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Computes the full path to the header file based on the include statement
|
|
67
|
-
*
|
|
68
|
-
* @param includeJp The include joinpoint
|
|
69
|
-
* @returns Resolved path to the header file
|
|
70
|
-
*/
|
|
71
|
-
private getHeaderFilePath(includeJp: Include): string {
|
|
72
|
-
try {
|
|
73
|
-
if (includeJp.name.startsWith("../")) {
|
|
74
|
-
return includeJp.relativeFolderpath;
|
|
75
|
-
} else {
|
|
76
|
-
const relativeDir = path.dirname(includeJp.name);
|
|
77
|
-
const fileJp = includeJp.getAncestor("file") as FileJp | undefined;
|
|
78
|
-
return path.resolve(fileJp!.path, relativeDir);
|
|
79
|
-
}
|
|
80
|
-
} catch (error) {
|
|
81
|
-
return "";
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Updates the provided include joinpoints to reference the new header file name
|
|
87
|
-
*
|
|
88
|
-
* @param includesOfHeader List of include joinpoints to update
|
|
89
|
-
* @param newFilename The new filename for the header file
|
|
90
|
-
*/
|
|
91
|
-
private updateIncludes(includesOfHeader: Include[], newFilename: string): void {
|
|
92
|
-
for (const includeJp of includesOfHeader) {
|
|
93
|
-
const fileJp = includeJp.getAncestor("file") as FileJp | undefined;
|
|
94
|
-
|
|
95
|
-
const newIncludeJpName = this.getNewIncludeName(includeJp, newFilename);
|
|
96
|
-
fileJp!.addInclude(newIncludeJpName);
|
|
97
|
-
|
|
98
|
-
const tempInclude = Query.searchFrom(fileJp!, Include, {name: includeName => path.normalize(includeName) === newIncludeJpName}).first();
|
|
99
|
-
|
|
100
|
-
if (tempInclude) {
|
|
101
|
-
includeJp.replaceWith(tempInclude.deepCopy());
|
|
102
|
-
tempInclude.detach();
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Computes the new include path with the updated header file name
|
|
109
|
-
*
|
|
110
|
-
* @param includeJp - Original include statement
|
|
111
|
-
* @param newHeaderFileName - New header file name
|
|
112
|
-
* @returns The updated include path
|
|
113
|
-
*/
|
|
114
|
-
private getNewIncludeName(includeJp: Include, newHeaderFileName: string): string {
|
|
115
|
-
const isFile = path.extname(includeJp.name) !== '';
|
|
116
|
-
const baseDir = isFile ? path.dirname(includeJp.name) : includeJp.name;
|
|
117
|
-
|
|
118
|
-
return path.join(baseDir, newHeaderFileName);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { Joinpoint } from "@specs-feup/clava/api/Joinpoints.js";
|
|
2
|
-
import MISRARule from "../../MISRARule.js";
|
|
3
|
-
import MISRAContext from "../../MISRAContext.js";
|
|
4
|
-
import { isInlineComment, getComments } from "../../utils/utils.js";
|
|
5
|
-
import { MISRATransformationReport, MISRATransformationType } from "../../MISRA.js";
|
|
6
|
-
|
|
7
|
-
export default class Rule_3_2_LineSplicing extends MISRARule {
|
|
8
|
-
|
|
9
|
-
constructor(context: MISRAContext) {
|
|
10
|
-
super("3.2", context);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
match($jp: Joinpoint, logErrors: boolean = false): boolean {
|
|
14
|
-
const invalidComments = getComments($jp).filter(comment =>
|
|
15
|
-
(isInlineComment(comment) && /\/\n/g.test(comment.text)));
|
|
16
|
-
|
|
17
|
-
if (logErrors) {
|
|
18
|
-
invalidComments.forEach(comment =>
|
|
19
|
-
this.logMISRAError(comment, `Comment ${comment.text} contains invalid character sequences.`)
|
|
20
|
-
)
|
|
21
|
-
}
|
|
22
|
-
return invalidComments.length > 0;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
transform($jp: Joinpoint): MISRATransformationReport {
|
|
26
|
-
if (!this.match($jp))
|
|
27
|
-
return new MISRATransformationReport(MISRATransformationType.NoChange);
|
|
28
|
-
|
|
29
|
-
const comments = getComments($jp);
|
|
30
|
-
for (const comment of comments) {
|
|
31
|
-
const newText = comment.text.replace(/\/\n/g, '');
|
|
32
|
-
comment.setText(newText);
|
|
33
|
-
}
|
|
34
|
-
return new MISRATransformationReport(MISRATransformationType.DescendantChange);
|
|
35
|
-
}
|
|
36
|
-
}
|