@specs-feup/clava-misra 1.0.0 → 1.0.2
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 +117 -0
- package/README.md +70 -15
- package/dist/MISRA.d.ts +129 -0
- package/dist/MISRA.d.ts.map +1 -0
- package/dist/MISRA.js +245 -0
- package/dist/MISRA.js.map +1 -0
- package/dist/MISRAContext.d.ts +21 -0
- package/dist/MISRAContext.d.ts.map +1 -0
- package/dist/MISRAContext.js +75 -0
- package/dist/MISRAContext.js.map +1 -0
- package/dist/MISRARule.d.ts +56 -0
- package/dist/MISRARule.d.ts.map +1 -0
- package/dist/MISRARule.js +45 -0
- package/dist/MISRARule.js.map +1 -0
- package/dist/MISRATool.d.ts +12 -0
- package/dist/MISRATool.d.ts.map +1 -0
- package/dist/MISRATool.js +84 -0
- package/dist/MISRATool.js.map +1 -0
- package/dist/foo.d.ts +2 -0
- package/dist/foo.d.ts.map +1 -0
- package/{src/foo.ts → dist/foo.js} +3 -2
- package/dist/foo.js.map +1 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +5 -0
- package/dist/main.js.map +1 -0
- package/dist/misra/MISRAAnalyser.d.ts +14 -0
- package/dist/misra/MISRAAnalyser.d.ts.map +1 -0
- package/{src/misra/MISRAAnalyser.ts → dist/misra/MISRAAnalyser.js} +13 -23
- package/dist/misra/MISRAAnalyser.js.map +1 -0
- package/dist/misra/MISRAPass.d.ts +27 -0
- package/dist/misra/MISRAPass.d.ts.map +1 -0
- package/dist/misra/MISRAPass.js +60 -0
- package/dist/misra/MISRAPass.js.map +1 -0
- package/dist/misra/MISRAPassResult.d.ts +13 -0
- package/dist/misra/MISRAPassResult.d.ts.map +1 -0
- package/dist/misra/MISRAPassResult.js +11 -0
- package/dist/misra/MISRAPassResult.js.map +1 -0
- package/dist/misra/MISRAReporter.d.ts +20 -0
- package/dist/misra/MISRAReporter.d.ts.map +1 -0
- package/dist/misra/MISRAReporter.js +43 -0
- package/dist/misra/MISRAReporter.js.map +1 -0
- package/dist/misra/passes/S10_EssentialTypePass.d.ts +42 -0
- package/dist/misra/passes/S10_EssentialTypePass.d.ts.map +1 -0
- package/dist/misra/passes/S10_EssentialTypePass.js +370 -0
- package/dist/misra/passes/S10_EssentialTypePass.js.map +1 -0
- package/dist/misra/passes/S12_ExpressionPass.d.ts +18 -0
- package/dist/misra/passes/S12_ExpressionPass.d.ts.map +1 -0
- package/dist/misra/passes/S12_ExpressionPass.js +72 -0
- package/dist/misra/passes/S12_ExpressionPass.js.map +1 -0
- package/dist/misra/passes/S13_SideEffectPass.d.ts +18 -0
- package/dist/misra/passes/S13_SideEffectPass.d.ts.map +1 -0
- package/dist/misra/passes/S13_SideEffectPass.js +105 -0
- package/dist/misra/passes/S13_SideEffectPass.js.map +1 -0
- package/dist/misra/passes/S15_ControlFlowPass.d.ts +19 -0
- package/dist/misra/passes/S15_ControlFlowPass.d.ts.map +1 -0
- package/dist/misra/passes/S15_ControlFlowPass.js +94 -0
- package/dist/misra/passes/S15_ControlFlowPass.js.map +1 -0
- package/dist/misra/passes/S16_SwitchStatementPass.d.ts +17 -0
- package/dist/misra/passes/S16_SwitchStatementPass.d.ts.map +1 -0
- package/dist/misra/passes/S16_SwitchStatementPass.js +152 -0
- package/dist/misra/passes/S16_SwitchStatementPass.js.map +1 -0
- package/dist/misra/passes/S17_FunctionPass.d.ts +12 -0
- package/dist/misra/passes/S17_FunctionPass.d.ts.map +1 -0
- package/dist/misra/passes/S17_FunctionPass.js +38 -0
- package/dist/misra/passes/S17_FunctionPass.js.map +1 -0
- package/dist/misra/passes/S18_PointersArraysPass.d.ts +17 -0
- package/dist/misra/passes/S18_PointersArraysPass.d.ts.map +1 -0
- package/dist/misra/passes/S18_PointersArraysPass.js +115 -0
- package/dist/misra/passes/S18_PointersArraysPass.js.map +1 -0
- package/dist/misra/passes/S19_OverlappingStoragePass.d.ts +11 -0
- package/dist/misra/passes/S19_OverlappingStoragePass.d.ts.map +1 -0
- package/dist/misra/passes/S19_OverlappingStoragePass.js +20 -0
- package/dist/misra/passes/S19_OverlappingStoragePass.js.map +1 -0
- package/dist/misra/passes/S21_StandardLibPass.d.ts +20 -0
- package/dist/misra/passes/S21_StandardLibPass.d.ts.map +1 -0
- package/dist/misra/passes/S21_StandardLibPass.js +77 -0
- package/dist/misra/passes/S21_StandardLibPass.js.map +1 -0
- package/dist/misra/passes/S3_CommentPass.d.ts +12 -0
- package/dist/misra/passes/S3_CommentPass.d.ts.map +1 -0
- package/dist/misra/passes/S3_CommentPass.js +27 -0
- package/dist/misra/passes/S3_CommentPass.js.map +1 -0
- package/dist/misra/passes/S5_IdentifierPass.d.ts +13 -0
- package/dist/misra/passes/S5_IdentifierPass.d.ts.map +1 -0
- package/dist/misra/passes/S5_IdentifierPass.js +60 -0
- package/dist/misra/passes/S5_IdentifierPass.js.map +1 -0
- package/dist/misra/passes/S6_TypePass.d.ts +11 -0
- package/dist/misra/passes/S6_TypePass.d.ts.map +1 -0
- package/dist/misra/passes/S6_TypePass.js +25 -0
- package/dist/misra/passes/S6_TypePass.js.map +1 -0
- package/dist/misra/passes/S7_LiteralsConstantsPass.d.ts +14 -0
- package/dist/misra/passes/S7_LiteralsConstantsPass.d.ts.map +1 -0
- package/dist/misra/passes/S7_LiteralsConstantsPass.js +71 -0
- package/dist/misra/passes/S7_LiteralsConstantsPass.js.map +1 -0
- package/dist/misra/passes/S8_DeclDefPass.d.ts +18 -0
- package/dist/misra/passes/S8_DeclDefPass.d.ts.map +1 -0
- package/dist/misra/passes/S8_DeclDefPass.js +127 -0
- package/dist/misra/passes/S8_DeclDefPass.js.map +1 -0
- package/dist/misra/sections/Section10_EssentialTypeModel.d.ts +33 -0
- package/dist/misra/sections/Section10_EssentialTypeModel.d.ts.map +1 -0
- package/{src/misra/sections/Section10_EssentialTypeModel.ts → dist/misra/sections/Section10_EssentialTypeModel.js} +58 -73
- package/dist/misra/sections/Section10_EssentialTypeModel.js.map +1 -0
- package/dist/misra/sections/Section11_PointerTypeConversions.d.ts +12 -0
- package/dist/misra/sections/Section11_PointerTypeConversions.d.ts.map +1 -0
- package/{src/misra/sections/Section11_PointerTypeConversions.ts → dist/misra/sections/Section11_PointerTypeConversions.js} +16 -27
- package/dist/misra/sections/Section11_PointerTypeConversions.js.map +1 -0
- package/dist/misra/sections/Section12_Expressions.d.ts +15 -0
- package/dist/misra/sections/Section12_Expressions.d.ts.map +1 -0
- package/dist/misra/sections/Section12_Expressions.js +70 -0
- package/dist/misra/sections/Section12_Expressions.js.map +1 -0
- package/dist/misra/sections/Section13_SideEffects.d.ts +14 -0
- package/dist/misra/sections/Section13_SideEffects.d.ts.map +1 -0
- package/dist/misra/sections/Section13_SideEffects.js +90 -0
- package/dist/misra/sections/Section13_SideEffects.js.map +1 -0
- package/dist/misra/sections/Section14_ControlStmtExprs.d.ts +8 -0
- package/dist/misra/sections/Section14_ControlStmtExprs.d.ts.map +1 -0
- package/{src/misra/sections/Section14_ControlStmtExprs.ts → dist/misra/sections/Section14_ControlStmtExprs.js} +8 -10
- package/dist/misra/sections/Section14_ControlStmtExprs.js.map +1 -0
- package/dist/misra/sections/Section15_ControlFlow.d.ts +14 -0
- package/dist/misra/sections/Section15_ControlFlow.d.ts.map +1 -0
- package/dist/misra/sections/Section15_ControlFlow.js +97 -0
- package/dist/misra/sections/Section15_ControlFlow.js.map +1 -0
- package/dist/misra/sections/Section16_SwitchStatements.d.ts +13 -0
- package/dist/misra/sections/Section16_SwitchStatements.d.ts.map +1 -0
- package/{src/misra/sections/Section16_SwitchStatements.ts → dist/misra/sections/Section16_SwitchStatements.js} +49 -74
- package/dist/misra/sections/Section16_SwitchStatements.js.map +1 -0
- package/dist/misra/sections/Section17_Functions.d.ts +9 -0
- package/dist/misra/sections/Section17_Functions.d.ts.map +1 -0
- package/{src/misra/sections/Section17_Functions.ts → dist/misra/sections/Section17_Functions.js} +10 -13
- package/dist/misra/sections/Section17_Functions.js.map +1 -0
- package/dist/misra/sections/Section18_PointersAndArrays.d.ts +13 -0
- package/dist/misra/sections/Section18_PointersAndArrays.d.ts.map +1 -0
- package/{src/misra/sections/Section18_PointersAndArrays.ts → dist/misra/sections/Section18_PointersAndArrays.js} +36 -40
- package/dist/misra/sections/Section18_PointersAndArrays.js.map +1 -0
- package/dist/misra/sections/Section19_OverlappingStorage.d.ts +8 -0
- package/dist/misra/sections/Section19_OverlappingStorage.d.ts.map +1 -0
- package/dist/misra/sections/Section19_OverlappingStorage.js +16 -0
- package/dist/misra/sections/Section19_OverlappingStorage.js.map +1 -0
- package/dist/misra/sections/Section20_PreprocessingDirectives.d.ts +8 -0
- package/dist/misra/sections/Section20_PreprocessingDirectives.d.ts.map +1 -0
- package/{src/misra/sections/Section20_PreprocessingDirectives.ts → dist/misra/sections/Section20_PreprocessingDirectives.js} +7 -9
- package/dist/misra/sections/Section20_PreprocessingDirectives.js.map +1 -0
- package/dist/misra/sections/Section21_StandardLibraries.d.ts +17 -0
- package/dist/misra/sections/Section21_StandardLibraries.d.ts.map +1 -0
- package/dist/misra/sections/Section21_StandardLibraries.js +54 -0
- package/dist/misra/sections/Section21_StandardLibraries.js.map +1 -0
- package/dist/misra/sections/Section2_UnusedCode.d.ts +9 -0
- package/dist/misra/sections/Section2_UnusedCode.d.ts.map +1 -0
- package/{src/misra/sections/Section2_UnusedCode.ts → dist/misra/sections/Section2_UnusedCode.js} +11 -16
- package/dist/misra/sections/Section2_UnusedCode.js.map +1 -0
- package/dist/misra/sections/Section3_Comments.d.ts +9 -0
- package/dist/misra/sections/Section3_Comments.d.ts.map +1 -0
- package/{src/misra/sections/Section3_Comments.ts → dist/misra/sections/Section3_Comments.js} +7 -10
- package/dist/misra/sections/Section3_Comments.js.map +1 -0
- package/dist/misra/sections/Section5_Identifiers.d.ts +12 -0
- package/dist/misra/sections/Section5_Identifiers.d.ts.map +1 -0
- package/dist/misra/sections/Section5_Identifiers.js +139 -0
- package/dist/misra/sections/Section5_Identifiers.js.map +1 -0
- package/dist/misra/sections/Section6_Types.d.ts +8 -0
- package/dist/misra/sections/Section6_Types.d.ts.map +1 -0
- package/dist/misra/sections/Section6_Types.js +23 -0
- package/dist/misra/sections/Section6_Types.js.map +1 -0
- package/dist/misra/sections/Section7_LiteralsConstants.d.ts +11 -0
- package/dist/misra/sections/Section7_LiteralsConstants.d.ts.map +1 -0
- package/{src/misra/sections/Section7_LiteralsConstants.ts → dist/misra/sections/Section7_LiteralsConstants.js} +18 -25
- package/dist/misra/sections/Section7_LiteralsConstants.js.map +1 -0
- package/dist/misra/sections/Section8_DeclarationsDefinitions.d.ts +15 -0
- package/dist/misra/sections/Section8_DeclarationsDefinitions.d.ts.map +1 -0
- package/{src/misra/sections/Section8_DeclarationsDefinitions.ts → dist/misra/sections/Section8_DeclarationsDefinitions.js} +18 -33
- package/dist/misra/sections/Section8_DeclarationsDefinitions.js.map +1 -0
- package/dist/misra/tests/utils.d.ts +10 -0
- package/dist/misra/tests/utils.d.ts.map +1 -0
- package/dist/misra/tests/utils.js +33 -0
- package/dist/misra/tests/utils.js.map +1 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.d.ts +15 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.d.ts.map +1 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.js +33 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.js.map +1 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.d.ts +16 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.d.ts.map +1 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.js +60 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.js.map +1 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.d.ts +19 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.d.ts.map +1 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.js +42 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.js.map +1 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.d.ts +43 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.d.ts.map +1 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.js +103 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.js.map +1 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.d.ts +26 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.d.ts.map +1 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.js +49 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.js.map +1 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.d.ts +26 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.d.ts.map +1 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.js +49 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.js.map +1 -0
- package/dist/rules/Section17_Functions/Rule_17_4_NonVoidReturn.d.ts +31 -0
- package/dist/rules/Section17_Functions/Rule_17_4_NonVoidReturn.d.ts.map +1 -0
- package/dist/rules/Section17_Functions/Rule_17_4_NonVoidReturn.js +71 -0
- package/dist/rules/Section17_Functions/Rule_17_4_NonVoidReturn.js.map +1 -0
- package/dist/rules/Section17_Functions/Rule_17_6_StaticArraySizeParam.d.ts +27 -0
- package/dist/rules/Section17_Functions/Rule_17_6_StaticArraySizeParam.d.ts.map +1 -0
- package/dist/rules/Section17_Functions/Rule_17_6_StaticArraySizeParam.js +58 -0
- package/dist/rules/Section17_Functions/Rule_17_6_StaticArraySizeParam.js.map +1 -0
- package/dist/rules/Section17_Functions/Rule_17_7_UnusedReturnValue.d.ts +28 -0
- package/dist/rules/Section17_Functions/Rule_17_7_UnusedReturnValue.d.ts.map +1 -0
- package/dist/rules/Section17_Functions/Rule_17_7_UnusedReturnValue.js +44 -0
- package/dist/rules/Section17_Functions/Rule_17_7_UnusedReturnValue.js.map +1 -0
- package/dist/rules/Section20-PreprocessingDirectives/Rule_20_2_InvalidHeaderFileName.d.ts +55 -0
- package/dist/rules/Section20-PreprocessingDirectives/Rule_20_2_InvalidHeaderFileName.d.ts.map +1 -0
- package/dist/rules/Section20-PreprocessingDirectives/Rule_20_2_InvalidHeaderFileName.js +108 -0
- package/dist/rules/Section20-PreprocessingDirectives/Rule_20_2_InvalidHeaderFileName.js.map +1 -0
- package/dist/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.d.ts +43 -0
- package/dist/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.d.ts.map +1 -0
- package/dist/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.js +68 -0
- package/dist/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.js.map +1 -0
- package/dist/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.d.ts +29 -0
- package/dist/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.d.ts.map +1 -0
- package/dist/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.js +53 -0
- package/dist/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.js.map +1 -0
- package/dist/rules/Section2_UnusedCode/Rule_2_6_UnusedLabels.d.ts +15 -0
- package/dist/rules/Section2_UnusedCode/Rule_2_6_UnusedLabels.d.ts.map +1 -0
- package/dist/rules/Section2_UnusedCode/Rule_2_6_UnusedLabels.js +35 -0
- package/dist/rules/Section2_UnusedCode/Rule_2_6_UnusedLabels.js.map +1 -0
- package/dist/rules/Section2_UnusedCode/Rule_2_7_UnusedParameters.d.ts +13 -0
- package/dist/rules/Section2_UnusedCode/Rule_2_7_UnusedParameters.d.ts.map +1 -0
- package/dist/rules/Section2_UnusedCode/Rule_2_7_UnusedParameters.js +53 -0
- package/dist/rules/Section2_UnusedCode/Rule_2_7_UnusedParameters.js.map +1 -0
- package/dist/rules/Section3_Comments/Rule_3_1_CommentSequences.d.ts +13 -0
- package/dist/rules/Section3_Comments/Rule_3_1_CommentSequences.d.ts.map +1 -0
- package/dist/rules/Section3_Comments/Rule_3_1_CommentSequences.js +32 -0
- package/dist/rules/Section3_Comments/Rule_3_1_CommentSequences.js.map +1 -0
- package/dist/rules/Section3_Comments/Rule_3_2_LineSplicing.d.ts +10 -0
- package/dist/rules/Section3_Comments/Rule_3_2_LineSplicing.d.ts.map +1 -0
- package/dist/rules/Section3_Comments/Rule_3_2_LineSplicing.js +26 -0
- package/dist/rules/Section3_Comments/Rule_3_2_LineSplicing.js.map +1 -0
- package/dist/rules/index.d.ts +20 -0
- package/dist/rules/index.d.ts.map +1 -0
- package/dist/rules/index.js +38 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/tests/Section17_Functions/misra_config.json +10 -0
- package/dist/tests/utils.d.ts +10 -0
- package/dist/tests/utils.d.ts.map +1 -0
- package/dist/tests/utils.js +29 -0
- package/dist/tests/utils.js.map +1 -0
- package/dist/utils/utils.d.ts +102 -0
- package/dist/utils/utils.d.ts.map +1 -0
- package/dist/utils/utils.js +202 -0
- package/dist/utils/utils.js.map +1 -0
- package/jest.config.js +6 -6
- package/package.json +44 -8
- package/src/MISRA.ts +276 -0
- package/src/MISRAContext.ts +84 -0
- package/src/MISRARule.ts +64 -0
- package/src/MISRATool.ts +95 -0
- package/src/main.ts +4 -33
- package/src/misra-old/MISRAAnalyser.ts +60 -0
- package/src/misra-old/MISRAAnalyserResult.ts +16 -0
- package/src/misra-old/sections/Section10_EssentialTypeModel.ts +377 -0
- package/src/misra-old/sections/Section11_PointerTypeConversions.ts +104 -0
- package/src/{misra → misra-old}/sections/Section12_Expressions.ts +7 -7
- package/src/{misra → misra-old}/sections/Section13_SideEffects.ts +15 -15
- package/src/misra-old/sections/Section14_ControlStmtExprs.ts +27 -0
- package/src/{misra → misra-old}/sections/Section15_ControlFlow.ts +10 -10
- package/src/misra-old/sections/Section18_PointersAndArrays.ts +108 -0
- package/src/{misra → misra-old}/sections/Section19_OverlappingStorage.ts +4 -4
- package/src/misra-old/sections/Section20_PreprocessingDirectives.ts +22 -0
- package/src/misra-old/sections/Section21_StandardLibraries.ts +99 -0
- package/src/{misra → misra-old}/sections/Section5_Identifiers.ts +16 -15
- package/src/{misra → misra-old}/sections/Section6_Types.ts +4 -4
- package/src/misra-old/sections/Section7_LiteralsConstants.ts +76 -0
- package/src/misra-old/sections/Section8_DeclarationsDefinitions.ts +133 -0
- package/src/rules/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.ts +41 -0
- package/src/rules/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.ts +70 -0
- package/src/rules/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.ts +41 -0
- package/src/rules/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.ts +113 -0
- package/src/rules/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.ts +61 -0
- package/src/rules/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.ts +57 -0
- package/src/rules/Section17_Functions/Rule_17_3_ImplicitFunction.ts +180 -0
- package/src/rules/Section17_Functions/Rule_17_4_NonVoidReturn.ts +91 -0
- package/src/rules/Section17_Functions/Rule_17_6_StaticArraySizeParam.ts +68 -0
- package/src/rules/Section17_Functions/Rule_17_7_UnusedReturnValue.ts +49 -0
- package/src/rules/Section20-PreprocessingDirectives/Rule_20_2_InvalidHeaderFileName.ts +120 -0
- package/src/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.ts +78 -0
- package/src/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.ts +61 -0
- package/src/rules/Section2_UnusedCode/Rule_2_6_UnusedLabels.ts +47 -0
- package/src/rules/Section2_UnusedCode/Rule_2_7_UnusedParameters.ts +67 -0
- package/src/rules/Section3_Comments/Rule_3_1_CommentSequences.ts +41 -0
- package/src/rules/Section3_Comments/Rule_3_2_LineSplicing.ts +36 -0
- package/src/rules/index.ts +44 -0
- package/src/tests/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.test.ts +55 -0
- package/src/tests/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.test.ts +70 -0
- package/src/tests/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.test.ts +128 -0
- package/src/tests/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.test.ts +132 -0
- package/src/tests/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.test.ts +146 -0
- package/src/tests/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.test.ts +102 -0
- package/src/tests/Section17_Functions/Rule_17_3_ImplicitFunctions.test.ts +79 -0
- package/src/tests/Section17_Functions/Rule_17_4_NonVoidReturn.test.ts +98 -0
- package/src/tests/Section17_Functions/Rule_17_4_NonVoidReturn_MissingConfig.test.ts +77 -0
- package/src/tests/Section17_Functions/Rule_17_6_StaticArraySizeParam.test.ts +36 -0
- package/src/tests/Section17_Functions/Rule_17_7_UnusedReturnValue.test.ts +44 -0
- package/src/tests/Section17_Functions/misra_config.json +19 -0
- package/src/tests/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.test.ts +175 -0
- package/src/tests/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.test.ts +219 -0
- package/src/tests/Section2_UnusedCode/Rule_2_6_UnusedLabels.test.ts +49 -0
- package/src/tests/Section2_UnusedCode/Rule_2_7_UnusedParameters.test.ts +55 -0
- package/src/tests/Section3_Comments/Rule_3_1_CommentSequences.test.ts +37 -0
- package/src/tests/utils.ts +51 -0
- package/src/utils/utils.ts +280 -0
- package/tsconfig.json +4 -3
- package/typedoc.config.js +1 -1
- package/CxxSources/lib.cpp +0 -3
- package/CxxSources/lib.h +0 -8
- package/CxxSources/main.cpp +0 -40
- package/TODO.md +0 -1
- package/consumer_order.txt +0 -2
- package/enum_integer_type.txt +0 -0
- package/is_temporary.txt +0 -0
- package/omp.txt +0 -0
- package/src/misra/passes/S16_SwitchStatementPass.ts +0 -168
- package/src/misra/passes/S3_CommentPass.ts +0 -40
- package/src/misra/sections/Section21_StandardLibraries.ts +0 -65
- package/src/misra/tests/S10_EssentialTypes.test.ts +0 -253
- package/src/misra/tests/S12_Expressions.test.ts +0 -43
- package/src/misra/tests/S13_SideEffects.test.ts +0 -77
- package/src/misra/tests/S15_ControlFlow.test.ts +0 -144
- package/src/misra/tests/S16_SwitchStatements.test.ts +0 -164
- package/src/misra/tests/S17_Functions.test.ts +0 -46
- package/src/misra/tests/S18_PointersArrays.test.ts +0 -167
- package/src/misra/tests/S19_OverlappingStorage.test.ts +0 -38
- package/src/misra/tests/S3_Comments.test.ts +0 -36
- package/src/misra/tests/S6_Types.test.ts +0 -36
- package/src/misra/tests/S7_LiteralsConstants.test.ts +0 -48
- package/src/misra/tests/utils.ts +0 -47
- package/types_with_templates.txt +0 -0
- /package/src/{misra → misra-old}/MISRAPass.ts +0 -0
- /package/src/{misra → misra-old}/MISRAPassResult.ts +0 -0
- /package/src/{misra → misra-old}/MISRAReporter.ts +0 -0
- /package/src/{misra → misra-old}/passes/S10_EssentialTypePass.ts +0 -0
- /package/src/{misra → misra-old}/passes/S12_ExpressionPass.ts +0 -0
- /package/src/{misra → misra-old}/passes/S13_SideEffectPass.ts +0 -0
- /package/src/{misra → misra-old}/passes/S15_ControlFlowPass.ts +0 -0
- /package/src/{misra → misra-old}/passes/S17_FunctionPass.ts +0 -0
- /package/src/{misra → misra-old}/passes/S18_PointersArraysPass.ts +0 -0
- /package/src/{misra → misra-old}/passes/S19_OverlappingStoragePass.ts +0 -0
- /package/src/{misra → misra-old}/passes/S21_StandardLibPass.ts +0 -0
- /package/src/{misra → misra-old}/passes/S5_IdentifierPass.ts +0 -0
- /package/src/{misra → misra-old}/passes/S6_TypePass.ts +0 -0
- /package/src/{misra → misra-old}/passes/S7_LiteralsConstantsPass.ts +0 -0
- /package/src/{misra → misra-old}/passes/S8_DeclDefPass.ts +0 -0
@@ -3,20 +3,20 @@ import { Program, FileJp, GotoStmt, Joinpoint, LabelStmt, Break } from "@specs-f
|
|
3
3
|
import MISRAAnalyser from "../MISRAAnalyser.js";
|
4
4
|
|
5
5
|
export default class Section15_ControlFlow extends MISRAAnalyser {
|
6
|
-
ruleMapper: Map<
|
6
|
+
ruleMapper: Map<string, (jp: Program | FileJp) => void>;
|
7
7
|
|
8
|
-
constructor(rules
|
8
|
+
constructor(rules?: string[]) {
|
9
9
|
super(rules);
|
10
10
|
this.ruleMapper = new Map([
|
11
|
-
[1, this.r15_1_noGoto.bind(this)],
|
12
|
-
[2, this.r15_2_noBackJumps.bind(this)],
|
13
|
-
[3, this.r15_3_gotoBlockEnclosed.bind(this)],
|
14
|
-
[4, this.r15_4_loopSingleBreak.bind(this)]
|
11
|
+
["15.1", this.r15_1_noGoto.bind(this)],
|
12
|
+
["15.2", this.r15_2_noBackJumps.bind(this)],
|
13
|
+
["15.3", this.r15_3_gotoBlockEnclosed.bind(this)],
|
14
|
+
["15.4", this.r15_4_loopSingleBreak.bind(this)]
|
15
15
|
]);
|
16
16
|
}
|
17
17
|
|
18
18
|
private r15_1_noGoto($startNode: Joinpoint) {
|
19
|
-
Query.searchFrom($startNode, GotoStmt).get().forEach(goto => this.logMISRAError(goto, "goto statements should not be used."), this);
|
19
|
+
Query.searchFrom($startNode, GotoStmt).get().forEach(goto => this.logMISRAError(this.currentRule, goto, "goto statements should not be used."), this);
|
20
20
|
|
21
21
|
return [];
|
22
22
|
}
|
@@ -29,7 +29,7 @@ export default class Section15_ControlFlow extends MISRAAnalyser {
|
|
29
29
|
private r15_2_noBackJumps($startNode: Joinpoint) {
|
30
30
|
for (const gotoStmt of Query.searchFrom($startNode, GotoStmt)) {
|
31
31
|
if (!Section15_ControlFlow.isBeforeInCode(gotoStmt.line, gotoStmt.column, gotoStmt.label.line, gotoStmt.label.column)) {
|
32
|
-
this.logMISRAError(gotoStmt, "Back jumps using goto statements are not allowed.");
|
32
|
+
this.logMISRAError(this.currentRule, gotoStmt, "Back jumps using goto statements are not allowed.");
|
33
33
|
} //maybe there is a better way?
|
34
34
|
}
|
35
35
|
}
|
@@ -55,7 +55,7 @@ export default class Section15_ControlFlow extends MISRAAnalyser {
|
|
55
55
|
} while (temp.parent.astId !== ancestor.astId);
|
56
56
|
|
57
57
|
if (error) {
|
58
|
-
this.logMISRAError(gotoStmt, `Label ${gotoStmt.label.name} is not declared in a block enclosing the goto statement.`);
|
58
|
+
this.logMISRAError(this.currentRule, gotoStmt, `Label ${gotoStmt.label.name} is not declared in a block enclosing the goto statement.`);
|
59
59
|
}
|
60
60
|
}
|
61
61
|
}
|
@@ -107,7 +107,7 @@ export default class Section15_ControlFlow extends MISRAAnalyser {
|
|
107
107
|
|
108
108
|
exits.forEach((v, k, m) => {
|
109
109
|
if (v > 1) {
|
110
|
-
this.logMISRAError(nodes.get(k) as Joinpoint, "Loops should have at most one break/goto statement.")
|
110
|
+
this.logMISRAError(this.currentRule, nodes.get(k) as Joinpoint, "Loops should have at most one break/goto statement.")
|
111
111
|
}
|
112
112
|
}, this);
|
113
113
|
}
|
@@ -0,0 +1,108 @@
|
|
1
|
+
import Query from "@specs-feup/lara/api/weaver/Query.js";
|
2
|
+
import { Program, FileJp, Joinpoint, BinaryOp, Field, Param, Vardecl, FunctionJp, Type, PointerType, QualType, FunctionType } from "@specs-feup/clava/api/Joinpoints.js";
|
3
|
+
import MISRAAnalyser from "../MISRAAnalyser.js";
|
4
|
+
|
5
|
+
export default class Section18_PointersAndArrays extends MISRAAnalyser {
|
6
|
+
ruleMapper: Map<string, (jp: Program | FileJp) => void>;
|
7
|
+
|
8
|
+
constructor(rules?: string[]) {
|
9
|
+
super(rules);
|
10
|
+
this.ruleMapper = new Map([
|
11
|
+
["18.4", this.r18_4_noPointerArithmetic.bind(this)],
|
12
|
+
["18.5", this.r18_5_noExcessivePointerNesting.bind(this)],
|
13
|
+
["18.7", this.r18_7_noFlexibleArrayMembers.bind(this)],
|
14
|
+
["18.8", this.r18_8_noVariableLengthArrays.bind(this)]
|
15
|
+
]);
|
16
|
+
}
|
17
|
+
|
18
|
+
private r18_4_noPointerArithmetic($startNode: Joinpoint) {
|
19
|
+
for (const bOp of Query.searchFrom($startNode, BinaryOp, {operator: /(\+=)|(-=)|(\+)|(-)/})) {
|
20
|
+
if (!bOp.type.isPointer) continue;
|
21
|
+
this.logMISRAError(this.currentRule, bOp, "Pointer arithmetic is not allowed. The only exception is if two pointers to elements of the same array are subtracted.")
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
private static getDepth(type: Type) {
|
26
|
+
let depth = 0;
|
27
|
+
let curr = type.desugarAll;
|
28
|
+
while (curr.isPointer === true) {
|
29
|
+
depth++;
|
30
|
+
|
31
|
+
if(curr instanceof PointerType) {
|
32
|
+
curr = curr.pointee.desugarAll;
|
33
|
+
} else if(curr instanceof QualType) {
|
34
|
+
curr = (curr.unqualifiedType as PointerType).pointee.desugarAll;
|
35
|
+
} else {
|
36
|
+
throw new Error(`Not supported for type ${curr.joinPointType}.`);
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
return depth;
|
41
|
+
}
|
42
|
+
|
43
|
+
private static getUnderlyingType(type: Type) {
|
44
|
+
let curr = type.desugarAll;
|
45
|
+
while (curr.isPointer === true) {
|
46
|
+
|
47
|
+
if(curr instanceof PointerType) {
|
48
|
+
curr = curr.pointee.desugarAll;
|
49
|
+
} else if(curr instanceof QualType) {
|
50
|
+
curr = (curr.unqualifiedType as PointerType).pointee.desugarAll;
|
51
|
+
} else {
|
52
|
+
throw new Error(`Not supported for type ${curr.joinPointType}.`);
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
return curr;
|
57
|
+
}
|
58
|
+
|
59
|
+
private r18_5_noExcessivePointerNesting($startNode: Joinpoint) { //must apply to fields as well
|
60
|
+
Query.searchFrom($startNode, Vardecl).get().forEach(decl => {
|
61
|
+
if (decl instanceof Param) return;
|
62
|
+
const depth = Section18_PointersAndArrays.getDepth(decl.type);
|
63
|
+
const underlyingType = Section18_PointersAndArrays.getUnderlyingType(decl.type);
|
64
|
+
if (underlyingType instanceof FunctionType) {
|
65
|
+
const retDepth = Section18_PointersAndArrays.getDepth(underlyingType.returnType);
|
66
|
+
const paramDepths = underlyingType.paramTypes.map(type => Section18_PointersAndArrays.getDepth(type)).filter(d => d > 2);
|
67
|
+
if (retDepth > 2) {
|
68
|
+
this.logMISRAError(this.currentRule, decl, `Return type of function pointer ${decl.code} has more than two levels of indirection.`);
|
69
|
+
}
|
70
|
+
if (paramDepths.length > 0) {
|
71
|
+
this.logMISRAError(this.currentRule, decl, `One or more parameters of function pointer ${decl.code} have more than two levels of indirection.`);
|
72
|
+
}
|
73
|
+
}
|
74
|
+
if (depth > 2) {
|
75
|
+
this.logMISRAError(this.currentRule, decl, `Type ${decl.type.code} has more than two levels of indirection.`)
|
76
|
+
}
|
77
|
+
}, this);
|
78
|
+
|
79
|
+
Query.searchFrom($startNode, FunctionJp).get().forEach(fun => {
|
80
|
+
const retDepth = Section18_PointersAndArrays.getDepth(fun.functionType.returnType);
|
81
|
+
const paramDepths = fun.functionType.paramTypes.map(type => Section18_PointersAndArrays.getDepth(type)).filter(d => d > 2);
|
82
|
+
if (retDepth > 2) {
|
83
|
+
this.logMISRAError(this.currentRule, fun, `Return type of function ${fun.signature} has more than two levels of indirection.`);
|
84
|
+
}
|
85
|
+
if (paramDepths.length > 0) {
|
86
|
+
this.logMISRAError(this.currentRule, fun, `One or more parameters of function ${fun.signature} have more than two levels of indirection.`);
|
87
|
+
}
|
88
|
+
}, this);
|
89
|
+
}
|
90
|
+
|
91
|
+
private r18_7_noFlexibleArrayMembers($startNode: Joinpoint) {
|
92
|
+
for (const varDecl of Query.searchFrom($startNode, Field)) {
|
93
|
+
if (!varDecl.type.isArray || varDecl instanceof Param) continue;
|
94
|
+
if (varDecl.type.arraySize === -1) {
|
95
|
+
this.logMISRAError(this.currentRule, varDecl, `Array ${varDecl.name} has variable or undefined size.`);
|
96
|
+
}
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
private r18_8_noVariableLengthArrays($startNode: Joinpoint) {
|
101
|
+
for (const varDecl of Query.searchFrom($startNode, Vardecl)) {
|
102
|
+
if (!varDecl.type.isArray || varDecl.instanceOf("param")) continue;
|
103
|
+
if (varDecl.type.arraySize === -1) {
|
104
|
+
this.logMISRAError(this.currentRule, varDecl, `Array ${varDecl.name} has variable or undefined size.`);
|
105
|
+
}
|
106
|
+
}
|
107
|
+
}
|
108
|
+
}
|
@@ -3,16 +3,16 @@ import { Program, FileJp, Joinpoint, Class } from "@specs-feup/clava/api/Joinpoi
|
|
3
3
|
import MISRAAnalyser from "../MISRAAnalyser.js";
|
4
4
|
|
5
5
|
export default class Section19_OverlappingStorage extends MISRAAnalyser {
|
6
|
-
ruleMapper: Map<
|
6
|
+
ruleMapper: Map<string, (jp: Program | FileJp) => void>;
|
7
7
|
|
8
|
-
constructor(rules
|
8
|
+
constructor(rules?: string[]) {
|
9
9
|
super(rules);
|
10
10
|
this.ruleMapper = new Map([
|
11
|
-
[2, this.r19_2_noUnion.bind(this)]
|
11
|
+
["19.2", this.r19_2_noUnion.bind(this)]
|
12
12
|
]);
|
13
13
|
}
|
14
14
|
|
15
15
|
private r19_2_noUnion($startNode: Joinpoint) {
|
16
|
-
Query.searchFrom($startNode, Class, {kind: "union"}).get().forEach(union => this.logMISRAError(union, "The union keyword should not be used."), this);
|
16
|
+
Query.searchFrom($startNode, Class, {kind: "union"}).get().forEach(union => this.logMISRAError(this.currentRule, union, "The union keyword should not be used."), this);
|
17
17
|
}
|
18
18
|
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import Query from "@specs-feup/lara/api/weaver/Query.js";
|
2
|
+
import { Program, FileJp, Joinpoint, Include } from "@specs-feup/clava/api/Joinpoints.js";
|
3
|
+
import MISRAAnalyser from "../MISRAAnalyser.js";
|
4
|
+
|
5
|
+
export default class Section20_PreprocessingDirectives extends MISRAAnalyser {
|
6
|
+
ruleMapper: Map<string, (jp: Program | FileJp) => void>;
|
7
|
+
|
8
|
+
constructor(rules?: string[]) {
|
9
|
+
super(rules);
|
10
|
+
this.ruleMapper = new Map([
|
11
|
+
["20.2", this.r20_2_noInvalidCharsInInclude.bind(this)]
|
12
|
+
]);
|
13
|
+
}
|
14
|
+
|
15
|
+
private r20_2_noInvalidCharsInInclude($startNode: Joinpoint) {
|
16
|
+
Query.searchFrom($startNode, Include).get().forEach(include => {
|
17
|
+
if (/.*('|"|\\|\/\*|\/\/).*/.test(include.name)) {
|
18
|
+
this.logMISRAError(this.currentRule, include, `Invalid characters in include for ${include.name}. Invalid characters are ', ", \\, and the sequences /* and //.`)
|
19
|
+
}
|
20
|
+
}, this);
|
21
|
+
}
|
22
|
+
}
|
@@ -0,0 +1,99 @@
|
|
1
|
+
import Query from "@specs-feup/lara/api/weaver/Query.js";
|
2
|
+
import { Call, FileJp, Include, Joinpoint, Program } from "@specs-feup/clava/api/Joinpoints.js";
|
3
|
+
import MISRAAnalyser from "../MISRAAnalyser.js";
|
4
|
+
|
5
|
+
export default class Section21_StandardLibraries extends MISRAAnalyser {
|
6
|
+
ruleMapper: Map<string, (jp: FileJp | Program) => void>;
|
7
|
+
|
8
|
+
constructor(rules?: string[]) {
|
9
|
+
super(rules);
|
10
|
+
this.ruleMapper = new Map([
|
11
|
+
["21.3", this.r21_3_noDynamicAllocation.bind(this)],
|
12
|
+
["21.4", this.r21_4_noSetjmpUsage.bind(this)],
|
13
|
+
["21.5", this.r21_5_noSignalUsage.bind(this)],
|
14
|
+
["21.6", this.r21_6_noStandardIO.bind(this)],
|
15
|
+
["21.7", this.r21_7_noStringFunctions.bind(this)],
|
16
|
+
["21.8", this.r21_8_noSysFunctions.bind(this)],
|
17
|
+
["21.9", this.r21_9_noStdAlgos.bind(this)],
|
18
|
+
["21.10", this.r21_10_noDateUsage.bind(this)],
|
19
|
+
["21.11", this.r21_11_noTgmathUsage.bind(this)],
|
20
|
+
["21.12", this.r21_12_noFenvExceptions.bind(this)]
|
21
|
+
]);
|
22
|
+
}
|
23
|
+
|
24
|
+
private r21_3_noDynamicAllocation($startNode: Joinpoint) {
|
25
|
+
const calls = Query.searchFrom($startNode, Call, {name: /(malloc|realloc|calloc|free)/}).get();
|
26
|
+
for (const call of calls) {
|
27
|
+
this.logMISRAError(this.currentRule, call, "Use of memory allocation functions provided by <stdlib.h> is not allowed.");
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
private r21_4_noSetjmpUsage($startNode: Joinpoint) {
|
32
|
+
const includes = Query.searchFrom($startNode, Include, {name: "setjmp.h", isAngled: true}).get();
|
33
|
+
for (const include of includes) {
|
34
|
+
this.logMISRAError(this.currentRule, include, "Use of <setjmp.h> is not allowed.");
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
private r21_5_noSignalUsage($startNode: Joinpoint) {
|
39
|
+
const includes = Query.searchFrom($startNode, Include, {name: "signal.h", isAngled: true}).get();
|
40
|
+
for (const include of includes) {
|
41
|
+
this.logMISRAError(this.currentRule, include, "Use of <signal.h> is not allowed.");
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
private r21_6_noStandardIO($startNode: Joinpoint) {
|
46
|
+
const includes = Query.searchFrom($startNode, Include, {name: /(stdio.h|wchar.h)/}).get();
|
47
|
+
for (const include of includes) {
|
48
|
+
this.logMISRAError(this.currentRule, include, "Use of the standard library I/O functions provided by <stdio.h> and <wchar.h> is not allowed.");
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
private r21_7_noStringFunctions($startNode: Joinpoint) {
|
53
|
+
const calls = Query.searchFrom($startNode, Call, {name: /(atoi|atof|atol|atoll)/}).get();
|
54
|
+
for (const call of calls) {
|
55
|
+
this.logMISRAError(this.currentRule, call, `Use of function ${call.signature} is not allowed.`);
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
private r21_8_noSysFunctions($startNode: Joinpoint) {
|
60
|
+
const calls = Query.searchFrom($startNode, Call, {name: /(system|abort|exit|getenv)/}).get();
|
61
|
+
for (const call of calls) {
|
62
|
+
this.logMISRAError(this.currentRule, call, `Use of function ${call.signature} is not allowed.`);
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
private r21_9_noStdAlgos($startNode: Joinpoint) {
|
67
|
+
const calls = Query.searchFrom($startNode, Call, {name: /(qsort|bsearch)/}).get();
|
68
|
+
for (const call of calls) {
|
69
|
+
this.logMISRAError(this.currentRule, call, `Use of function ${call.signature} is not allowed.`);
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
private r21_10_noDateUsage($startNode: Joinpoint) {
|
74
|
+
const includes = Query.searchFrom($startNode, Include, {name: "time.h", isAngled: true}).get();
|
75
|
+
for (const include of includes) {
|
76
|
+
this.logMISRAError(this.currentRule, include, "Use of <time.h> is not allowed.");
|
77
|
+
}
|
78
|
+
const calls = Query.searchFrom($startNode, Call, {name: "wcsftime"}).get();
|
79
|
+
for (const call of calls) {
|
80
|
+
this.logMISRAError(this.currentRule, call, "Identifier 'wcsftime' shall not be used.");
|
81
|
+
}
|
82
|
+
}
|
83
|
+
|
84
|
+
private r21_11_noTgmathUsage($startNode: Joinpoint) {
|
85
|
+
const includes = Query.searchFrom($startNode, Include, {name: "tgmath.h", isAngled: true}).get();
|
86
|
+
for (const include of includes) {
|
87
|
+
this.logMISRAError(this.currentRule, include, "Use of <tgmath.h> is not allowed.");
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
private r21_12_noFenvExceptions($startNode: Joinpoint) {
|
92
|
+
const calls = Query.searchFrom($startNode, Call, {name: /(feclearexcept|fegetexceptflag|feraiseexcept|fesetexceptflag|fetestexcept)/}).get();
|
93
|
+
for (const call of calls) {
|
94
|
+
this.logMISRAError(this.currentRule, call, `Use of function ${call.signature} is not allowed.`);
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
|
99
|
+
}
|
@@ -4,15 +4,15 @@ import Query from "@specs-feup/lara/api/weaver/Query.js";
|
|
4
4
|
import Fix from "@specs-feup/clava/api/clava/analysis/Fix.js";
|
5
5
|
|
6
6
|
export default class Section5_Identifiers extends MISRAAnalyser {
|
7
|
-
ruleMapper: Map<
|
7
|
+
ruleMapper: Map<string, (jp: Program | FileJp) => void>;
|
8
8
|
|
9
|
-
constructor(rules
|
9
|
+
constructor(rules?: string[]) {
|
10
10
|
super(rules);
|
11
11
|
this.ruleMapper = new Map([
|
12
|
-
[1, this.r5_1_externalIdentifierLength.bind(this)],
|
13
|
-
[6, this.r5_6_uniqueTypedefs.bind(this)],
|
14
|
-
[7, this.r5_7_uniqueTags.bind(this)],
|
15
|
-
[8, this.r5_8_uniqueExternalIds.bind(this)]
|
12
|
+
["5.1", this.r5_1_externalIdentifierLength.bind(this)],
|
13
|
+
["5.6", this.r5_6_uniqueTypedefs.bind(this)],
|
14
|
+
["5.7", this.r5_7_uniqueTags.bind(this)],
|
15
|
+
["5.8", this.r5_8_uniqueExternalIds.bind(this)]
|
16
16
|
]);
|
17
17
|
}
|
18
18
|
|
@@ -25,7 +25,7 @@ export default class Section5_Identifiers extends MISRAAnalyser {
|
|
25
25
|
for (const vardecl of Query.searchFrom($startNode, Vardecl, {storageClass: (sC: StorageClass) => Section5_Identifiers.hasExternalLinkage(sC)})) {
|
26
26
|
if (vardecl.name.length >= 31) {
|
27
27
|
if (prefixes.has(vardecl.name.substring(0, 32))) {
|
28
|
-
this.logMISRAError(vardecl, `External identifier ${vardecl.name} is not distinct.`, new Fix(vardecl, ($jp) => {
|
28
|
+
this.logMISRAError(this.currentRule, vardecl, `External identifier ${vardecl.name} is not distinct.`, new Fix(vardecl, ($jp) => {
|
29
29
|
($jp as Vardecl).name = "a_" + ($jp as Vardecl).name;
|
30
30
|
}));
|
31
31
|
}
|
@@ -38,7 +38,7 @@ export default class Section5_Identifiers extends MISRAAnalyser {
|
|
38
38
|
for (const fun of Query.searchFrom($startNode, FunctionJp, {storageClass: (sC: StorageClass) => Section5_Identifiers.hasExternalLinkage(sC)})) {
|
39
39
|
if (fun.name.length >= 31) {
|
40
40
|
if (prefixes.has(fun.name.substring(0, 32))) {
|
41
|
-
this.logMISRAError(fun, `External identifier ${fun.name} is not distinct.`, new Fix(fun, ($jp) => {
|
41
|
+
this.logMISRAError(this.currentRule, fun, `External identifier ${fun.name} is not distinct.`, new Fix(fun, ($jp) => {
|
42
42
|
($jp as FunctionJp).name = "a_" + ($jp as FunctionJp).name;
|
43
43
|
}));
|
44
44
|
}
|
@@ -54,7 +54,7 @@ export default class Section5_Identifiers extends MISRAAnalyser {
|
|
54
54
|
|
55
55
|
for (const typedef of Query.searchFrom($startNode, TypedefDecl)) {
|
56
56
|
if (typedefs.has(typedef.name)) {
|
57
|
-
this.logMISRAError(typedef, "Typedef names must be unique across all translation units.", new Fix(typedef, jp => {
|
57
|
+
this.logMISRAError(this.currentRule, typedef, "Typedef names must be unique across all translation units.", new Fix(typedef, jp => {
|
58
58
|
const typedefJp = jp as TypedefDecl;
|
59
59
|
typedefJp.name = typedef.name + "_" + typedefJp.astId;
|
60
60
|
}));
|
@@ -72,7 +72,7 @@ export default class Section5_Identifiers extends MISRAAnalyser {
|
|
72
72
|
}
|
73
73
|
}
|
74
74
|
if (typedefs.has(decl.name)) {
|
75
|
-
this.logMISRAError(decl, `${decl.name} is also the name of a typedef. Typedef identifiers must not be reused.`, new Fix(decl, jp => {
|
75
|
+
this.logMISRAError(this.currentRule, decl, `${decl.name} is also the name of a typedef. Typedef identifiers must not be reused.`, new Fix(decl, jp => {
|
76
76
|
const declJp = jp as NamedDecl;
|
77
77
|
declJp.name = declJp.name + "_" + declJp.astId;
|
78
78
|
}));
|
@@ -86,7 +86,7 @@ export default class Section5_Identifiers extends MISRAAnalyser {
|
|
86
86
|
for (const classJp of Query.searchFrom($startNode, Class)) {
|
87
87
|
if (classJp.type instanceof TagType) {
|
88
88
|
if (tags.has(classJp.type.name)) {
|
89
|
-
this.logMISRAError(classJp, "Tag names must be unique across all translation units.");
|
89
|
+
this.logMISRAError(this.currentRule, classJp, "Tag names must be unique across all translation units.");
|
90
90
|
}
|
91
91
|
else {
|
92
92
|
tags.add(classJp.type.name);
|
@@ -97,7 +97,7 @@ export default class Section5_Identifiers extends MISRAAnalyser {
|
|
97
97
|
for (const enumDecl of Query.searchFrom($startNode, EnumDecl)) {
|
98
98
|
if (enumDecl.type instanceof TagType) {
|
99
99
|
if (tags.has(enumDecl.type.name)) {
|
100
|
-
this.logMISRAError(enumDecl, "Tag names must be unique across all translation units.");
|
100
|
+
this.logMISRAError(this.currentRule, enumDecl, "Tag names must be unique across all translation units.");
|
101
101
|
}
|
102
102
|
else {
|
103
103
|
tags.add(enumDecl.type.name);
|
@@ -114,7 +114,7 @@ export default class Section5_Identifiers extends MISRAAnalyser {
|
|
114
114
|
}
|
115
115
|
if (decl.type instanceof TagType) return;
|
116
116
|
if (tags.has(decl.name)) {
|
117
|
-
this.logMISRAError(decl, `${decl.name} is also the name of a tag. Tag identifiers must not be reused.`, new Fix(decl, jp => {
|
117
|
+
this.logMISRAError(this.currentRule, decl, `${decl.name} is also the name of a tag. Tag identifiers must not be reused.`, new Fix(decl, jp => {
|
118
118
|
const declJp = jp as NamedDecl;
|
119
119
|
declJp.name = declJp.name + "_" + declJp.astId;
|
120
120
|
}));
|
@@ -124,9 +124,10 @@ export default class Section5_Identifiers extends MISRAAnalyser {
|
|
124
124
|
|
125
125
|
private r5_8_uniqueExternalIds($startNode: Joinpoint) {
|
126
126
|
const ids: Set<string> = new Set();
|
127
|
+
|
127
128
|
for (const vardecl of Query.searchFrom($startNode, Vardecl, {storageClass: (sC: StorageClass) => Section5_Identifiers.hasExternalLinkage(sC)})) {
|
128
129
|
if (ids.has(vardecl.name)) {
|
129
|
-
this.logMISRAError(vardecl, `External identifier ${vardecl.name} must be unique across all translation units.`, new Fix(vardecl, ($jp) => {
|
130
|
+
this.logMISRAError(this.currentRule, vardecl, `External identifier ${vardecl.name} must be unique across all translation units.`, new Fix(vardecl, ($jp) => {
|
130
131
|
($jp as Vardecl).name = "a_" + ($jp as Vardecl).name;
|
131
132
|
}));
|
132
133
|
}
|
@@ -137,7 +138,7 @@ export default class Section5_Identifiers extends MISRAAnalyser {
|
|
137
138
|
|
138
139
|
for (const fun of Query.searchFrom($startNode, FunctionJp, {storageClass: (sC: StorageClass) => Section5_Identifiers.hasExternalLinkage(sC)})) {
|
139
140
|
if (ids.has(fun.name)) {
|
140
|
-
this.logMISRAError(fun, `External identifier ${fun.name} must be unique across all translation units.`, new Fix(fun, ($jp) => {
|
141
|
+
this.logMISRAError(this.currentRule, fun, `External identifier ${fun.name} must be unique across all translation units.`, new Fix(fun, ($jp) => {
|
141
142
|
($jp as FunctionJp).name = "a_" + ($jp as FunctionJp).name;
|
142
143
|
}));
|
143
144
|
}
|
@@ -3,12 +3,12 @@ import { Program, FileJp, Joinpoint, Field, IntLiteral, BuiltinType } from "@spe
|
|
3
3
|
import MISRAAnalyser from "../MISRAAnalyser.js";
|
4
4
|
|
5
5
|
export default class Section6_Types extends MISRAAnalyser {
|
6
|
-
ruleMapper: Map<
|
6
|
+
ruleMapper: Map<string, (jp: Program | FileJp) => void>;
|
7
7
|
|
8
|
-
constructor(rules
|
8
|
+
constructor(rules?: string[]) {
|
9
9
|
super(rules);
|
10
10
|
this.ruleMapper = new Map([
|
11
|
-
[2, this.r6_2_noSingleBitSignedFields.bind(this)],
|
11
|
+
["6.2", this.r6_2_noSingleBitSignedFields.bind(this)],
|
12
12
|
|
13
13
|
]);
|
14
14
|
}
|
@@ -18,7 +18,7 @@ export default class Section6_Types extends MISRAAnalyser {
|
|
18
18
|
if (field.children.length > 0 && field.name) {
|
19
19
|
const width = new Number((field.children[0].children[0] as IntLiteral).value);
|
20
20
|
if (width == 1 && (field.type as BuiltinType).isSigned) {
|
21
|
-
this.logMISRAError(field, `Single-bit named bit field ${field.name} must not have a signed type.`);
|
21
|
+
this.logMISRAError(this.currentRule, field, `Single-bit named bit field ${field.name} must not have a signed type.`);
|
22
22
|
}
|
23
23
|
}
|
24
24
|
}, this);
|
@@ -0,0 +1,76 @@
|
|
1
|
+
import Query from "@specs-feup/lara/api/weaver/Query.js";
|
2
|
+
import { Program, FileJp, IntLiteral, Type, PointerType, QualType, Vardecl, BinaryOp, ReturnStmt, FunctionJp, Call, Varref, ArrayAccess, Joinpoint } from "@specs-feup/clava/api/Joinpoints.js";
|
3
|
+
import MISRAAnalyser from "../MISRAAnalyser.js";
|
4
|
+
|
5
|
+
export default class Section7_LiteralsConstants extends MISRAAnalyser {
|
6
|
+
ruleMapper: Map<string, (jp: Program | FileJp) => void>;
|
7
|
+
|
8
|
+
constructor(rules?: string[]) {
|
9
|
+
super(rules);
|
10
|
+
this.ruleMapper = new Map([
|
11
|
+
["7.1", this.r7_1_noOctalConstants.bind(this)],
|
12
|
+
["7.3", this.r7_3_noLowercaseLSuffix.bind(this)],
|
13
|
+
["7.4", this.r7_4_constStringLiterals.bind(this)]
|
14
|
+
]);
|
15
|
+
}
|
16
|
+
|
17
|
+
private r7_1_noOctalConstants($startNode: Joinpoint) {
|
18
|
+
for (const intLit of Query.searchFrom($startNode, IntLiteral)) {
|
19
|
+
if (intLit.code.match(/0[0-9]+/g)) {
|
20
|
+
this.logMISRAError(this.currentRule, intLit, `The octal constant ${intLit.code} was used. Its decimal value is ${intLit.value}`);
|
21
|
+
}
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
private r7_3_noLowercaseLSuffix($startNode: Joinpoint) {
|
26
|
+
for (const intLit of Query.searchFrom($startNode, IntLiteral)) {
|
27
|
+
if (intLit.code.includes('l')) {
|
28
|
+
this.logMISRAError(this.currentRule, intLit, `A lowercase 'l' was used as a suffix in ${intLit.code}.`);
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
private static checkPointerConst(type: Type) {
|
34
|
+
if (type instanceof PointerType) {
|
35
|
+
return type.pointee.constant;
|
36
|
+
}
|
37
|
+
else if (type instanceof QualType && type.unqualifiedType instanceof PointerType) {
|
38
|
+
return type.unqualifiedType.pointee.constant;
|
39
|
+
}
|
40
|
+
else return undefined;
|
41
|
+
}
|
42
|
+
|
43
|
+
private r7_4_constStringLiterals($startNode: Joinpoint) {
|
44
|
+
for (const varDecl of Query.searchFrom($startNode, Vardecl)) {
|
45
|
+
if (!varDecl.type.isPointer) continue;
|
46
|
+
|
47
|
+
if (varDecl.children.length > 0 && varDecl.children[0].joinPointType === "literal"
|
48
|
+
&& !Section7_LiteralsConstants.checkPointerConst(varDecl.type)) {
|
49
|
+
this.logMISRAError(this.currentRule, varDecl, `String literal assigned to non-const qualified variable ${varDecl.name}`);
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
Query.searchFrom($startNode, BinaryOp, {isAssignment: true}).get().forEach(bOp => {
|
54
|
+
if (bOp.right.joinPointType === "literal" && !Section7_LiteralsConstants.checkPointerConst(bOp.left.type)) {
|
55
|
+
this.logMISRAError(this.currentRule, bOp, `String literal assigned to non-const qualified variable ${(bOp.left as Varref | ArrayAccess).name}`);
|
56
|
+
}
|
57
|
+
}, this);
|
58
|
+
|
59
|
+
for (const ret of Query.searchFrom($startNode, ReturnStmt)) {
|
60
|
+
const ancestor = ret.getAncestor("function") as FunctionJp;
|
61
|
+
const retType = ancestor.functionType.returnType;
|
62
|
+
if (ret.returnExpr?.joinPointType === "literal" && !Section7_LiteralsConstants.checkPointerConst(retType)) {
|
63
|
+
this.logMISRAError(this.currentRule, ret, `String literal returned in non-const qualified return value for function ${ancestor.name}`);
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
for (const call of Query.searchFrom($startNode, Call)) {
|
68
|
+
const paramTypes = call.function.functionType.paramTypes;
|
69
|
+
for (let i = 1; i < call.children.length; i++) {
|
70
|
+
if (call.children[i].joinPointType === "literal" && !Section7_LiteralsConstants.checkPointerConst(paramTypes[i-1])) {
|
71
|
+
this.logMISRAError(this.currentRule, call.children[i], `String literal passed as non-const qualified parameter in call of ${call.function.name}`);
|
72
|
+
}
|
73
|
+
}
|
74
|
+
}
|
75
|
+
}
|
76
|
+
}
|
@@ -0,0 +1,133 @@
|
|
1
|
+
import Query from "@specs-feup/lara/api/weaver/Query.js";
|
2
|
+
import { Program, FileJp, Param, FunctionJp, StorageClass, Vardecl, EnumDecl, IntLiteral, Joinpoint, DeclStmt, Varref } from "@specs-feup/clava/api/Joinpoints.js";
|
3
|
+
import MISRAAnalyser from "../MISRAAnalyser.js";
|
4
|
+
import Fix from "@specs-feup/clava/api/clava/analysis/Fix.js";
|
5
|
+
|
6
|
+
export default class Section8_DeclarationsDefinitions extends MISRAAnalyser {
|
7
|
+
ruleMapper: Map<string, (jp: Program | FileJp) => void>;
|
8
|
+
|
9
|
+
constructor(rules?: string[]) {
|
10
|
+
super(rules);
|
11
|
+
this.ruleMapper = new Map([
|
12
|
+
["8.2", this.r8_2_functionPrototype.bind(this)],
|
13
|
+
["8.3", this.r8_3_compatibleDefinitions.bind(this)],
|
14
|
+
["8.7", this.r8_7_noUnnecessaryExternalLinkage.bind(this)],
|
15
|
+
["8.10", this.r8_10_onlyStaticInline.bind(this)],
|
16
|
+
["8.11", this.r8_11_externArrayExplicitSize.bind(this)],
|
17
|
+
["8.12", this.r8_12_implicitExplicitEnumMatching.bind(this)]
|
18
|
+
]);
|
19
|
+
}
|
20
|
+
|
21
|
+
private r8_2_functionPrototype($startNode: Joinpoint) { //needs to apply to function pointers, void info lost
|
22
|
+
Query.searchFrom($startNode, Param).get().filter(param => !param.name)
|
23
|
+
.forEach(param => this.logMISRAError(this.currentRule, param, `Parameter of type ${param.type.code} lacks a name.`), this);
|
24
|
+
}
|
25
|
+
|
26
|
+
private r8_3_compatibleDefinitions($startNode: Joinpoint) { //what if no impl?
|
27
|
+
Query.searchFrom($startNode, FunctionJp, {isImplementation: true}).get().forEach(fun => {
|
28
|
+
fun.declarationJps.forEach(decl => {
|
29
|
+
for (let i = 0; i < fun.params.length; i++) {
|
30
|
+
if (fun.paramNames[i] !== decl.paramNames[i]) {
|
31
|
+
this.logMISRAError(this.currentRule, fun, `Mismatch in name of parameters with declaration on ${decl.filename}@${decl.line}:${decl.column}.`);
|
32
|
+
}
|
33
|
+
if (fun.params[i].type.code !== decl.params[i].type.code) {
|
34
|
+
this.logMISRAError(this.currentRule, fun, `Mismatch in parameter types with declaration on ${decl.filename}@${decl.line}:${decl.column}`);
|
35
|
+
}
|
36
|
+
}
|
37
|
+
}, this);
|
38
|
+
}, this);
|
39
|
+
}
|
40
|
+
|
41
|
+
private static hasExternalLinkage(jp: FunctionJp | Vardecl) {
|
42
|
+
return jp.storageClass !== StorageClass.STATIC && jp.storageClass !== StorageClass.EXTERN;
|
43
|
+
}
|
44
|
+
|
45
|
+
private r8_7_noUnnecessaryExternalLinkage($startNode: Joinpoint) { //finish
|
46
|
+
const globals = new Map();
|
47
|
+
|
48
|
+
Query.searchFrom($startNode, FileJp).get().forEach(file => {
|
49
|
+
file.children.forEach(jp => {
|
50
|
+
if (jp instanceof FunctionJp && jp.name !== "main" && Section8_DeclarationsDefinitions.hasExternalLinkage(jp)) {
|
51
|
+
let hasExternals = false;
|
52
|
+
jp.calls.forEach(call => {
|
53
|
+
if (call.filename !== jp.filename) {
|
54
|
+
hasExternals = true;
|
55
|
+
}
|
56
|
+
}, this);
|
57
|
+
if (!hasExternals) {
|
58
|
+
this.logMISRAError(this.currentRule, jp, `Function ${jp.name} has external linkage but it is only referenced in its file.`);
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
if (jp instanceof DeclStmt) {
|
63
|
+
jp.decls.filter(decl => decl instanceof Vardecl && Section8_DeclarationsDefinitions.hasExternalLinkage(decl)).forEach(decl => {
|
64
|
+
//globals.push({decl: decl as Vardecl, file: decl.filename});
|
65
|
+
globals.set(decl.astId, {decl: decl as Vardecl, file: decl.filename});
|
66
|
+
}, this);
|
67
|
+
}
|
68
|
+
});
|
69
|
+
}, this);
|
70
|
+
|
71
|
+
Query.searchFrom($startNode, Varref).get().forEach(ref => {
|
72
|
+
if (globals.has(ref.astId)) {
|
73
|
+
const declFile = globals.get(ref.astId).file;
|
74
|
+
if (declFile !== ref.filename) {
|
75
|
+
globals.delete(ref.astId);
|
76
|
+
}
|
77
|
+
}
|
78
|
+
}, this);
|
79
|
+
|
80
|
+
globals.forEach((v, k, m) => {
|
81
|
+
this.logMISRAError(this.currentRule, v.decl, `Variable ${v.decl.name} is declared with external linkage but is not referenced outside its file.`);
|
82
|
+
}, this);
|
83
|
+
}
|
84
|
+
|
85
|
+
private r8_10_onlyStaticInline($startNode: Joinpoint) {
|
86
|
+
Query.searchFrom($startNode, FunctionJp, {isInline: true}).get().forEach(fun => {
|
87
|
+
if (fun.storageClass !== StorageClass.STATIC) {
|
88
|
+
this.logMISRAError(this.currentRule, fun, "Inline functions must always be declared static.");
|
89
|
+
}
|
90
|
+
});
|
91
|
+
}
|
92
|
+
|
93
|
+
private r8_11_externArrayExplicitSize($startNode: Joinpoint) {
|
94
|
+
for (const varDecl of Query.searchFrom($startNode, Vardecl, {storageClass: StorageClass.EXTERN})) {
|
95
|
+
if (varDecl.type.isArray && varDecl.type.arraySize === -1) {
|
96
|
+
this.logMISRAError(this.currentRule, varDecl, `Size of external array ${varDecl.name} is not explicit.`)
|
97
|
+
}
|
98
|
+
}
|
99
|
+
}
|
100
|
+
|
101
|
+
private setEnumMap(map: Map<number, boolean>, newValue: number, isExplicit: boolean, jp: EnumDecl) {
|
102
|
+
if (map.has(newValue) && !(isExplicit && map.get(newValue))) {
|
103
|
+
this.logMISRAError(this.currentRule, jp, `An implicitly numbered identifier in enum ${jp.name} shares a value with another identifier.`, new Fix(jp, jp => {
|
104
|
+
|
105
|
+
}));
|
106
|
+
}
|
107
|
+
map.set(newValue, isExplicit);
|
108
|
+
}
|
109
|
+
|
110
|
+
private r8_12_implicitExplicitEnumMatching($startNode: Joinpoint) {
|
111
|
+
for (const enumDecl of Query.searchFrom($startNode, EnumDecl)) {
|
112
|
+
const map = new Map();
|
113
|
+
|
114
|
+
let index = 0;
|
115
|
+
for (const enumerator of enumDecl.enumerators) {
|
116
|
+
if (enumerator.children.length > 0) {
|
117
|
+
if (enumerator.children[0].children[0] instanceof IntLiteral) {
|
118
|
+
index = Number(enumerator.children[0].children[0].value);
|
119
|
+
this.setEnumMap(map, index, true, enumDecl);
|
120
|
+
}
|
121
|
+
else {
|
122
|
+
console.log(`Warning! Could not analyse the entirety of enum ${enumDecl.name} due to non-constant expressions`);
|
123
|
+
return;
|
124
|
+
}
|
125
|
+
}
|
126
|
+
else {
|
127
|
+
this.setEnumMap(map, index, false, enumDecl);
|
128
|
+
}
|
129
|
+
index++;
|
130
|
+
}
|
131
|
+
}
|
132
|
+
}
|
133
|
+
}
|