@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.
Files changed (352) hide show
  1. package/.gitignore +117 -0
  2. package/README.md +70 -15
  3. package/dist/MISRA.d.ts +129 -0
  4. package/dist/MISRA.d.ts.map +1 -0
  5. package/dist/MISRA.js +245 -0
  6. package/dist/MISRA.js.map +1 -0
  7. package/dist/MISRAContext.d.ts +21 -0
  8. package/dist/MISRAContext.d.ts.map +1 -0
  9. package/dist/MISRAContext.js +75 -0
  10. package/dist/MISRAContext.js.map +1 -0
  11. package/dist/MISRARule.d.ts +56 -0
  12. package/dist/MISRARule.d.ts.map +1 -0
  13. package/dist/MISRARule.js +45 -0
  14. package/dist/MISRARule.js.map +1 -0
  15. package/dist/MISRATool.d.ts +12 -0
  16. package/dist/MISRATool.d.ts.map +1 -0
  17. package/dist/MISRATool.js +84 -0
  18. package/dist/MISRATool.js.map +1 -0
  19. package/dist/foo.d.ts +2 -0
  20. package/dist/foo.d.ts.map +1 -0
  21. package/{src/foo.ts → dist/foo.js} +3 -2
  22. package/dist/foo.js.map +1 -0
  23. package/dist/main.d.ts +2 -0
  24. package/dist/main.d.ts.map +1 -0
  25. package/dist/main.js +5 -0
  26. package/dist/main.js.map +1 -0
  27. package/dist/misra/MISRAAnalyser.d.ts +14 -0
  28. package/dist/misra/MISRAAnalyser.d.ts.map +1 -0
  29. package/{src/misra/MISRAAnalyser.ts → dist/misra/MISRAAnalyser.js} +13 -23
  30. package/dist/misra/MISRAAnalyser.js.map +1 -0
  31. package/dist/misra/MISRAPass.d.ts +27 -0
  32. package/dist/misra/MISRAPass.d.ts.map +1 -0
  33. package/dist/misra/MISRAPass.js +60 -0
  34. package/dist/misra/MISRAPass.js.map +1 -0
  35. package/dist/misra/MISRAPassResult.d.ts +13 -0
  36. package/dist/misra/MISRAPassResult.d.ts.map +1 -0
  37. package/dist/misra/MISRAPassResult.js +11 -0
  38. package/dist/misra/MISRAPassResult.js.map +1 -0
  39. package/dist/misra/MISRAReporter.d.ts +20 -0
  40. package/dist/misra/MISRAReporter.d.ts.map +1 -0
  41. package/dist/misra/MISRAReporter.js +43 -0
  42. package/dist/misra/MISRAReporter.js.map +1 -0
  43. package/dist/misra/passes/S10_EssentialTypePass.d.ts +42 -0
  44. package/dist/misra/passes/S10_EssentialTypePass.d.ts.map +1 -0
  45. package/dist/misra/passes/S10_EssentialTypePass.js +370 -0
  46. package/dist/misra/passes/S10_EssentialTypePass.js.map +1 -0
  47. package/dist/misra/passes/S12_ExpressionPass.d.ts +18 -0
  48. package/dist/misra/passes/S12_ExpressionPass.d.ts.map +1 -0
  49. package/dist/misra/passes/S12_ExpressionPass.js +72 -0
  50. package/dist/misra/passes/S12_ExpressionPass.js.map +1 -0
  51. package/dist/misra/passes/S13_SideEffectPass.d.ts +18 -0
  52. package/dist/misra/passes/S13_SideEffectPass.d.ts.map +1 -0
  53. package/dist/misra/passes/S13_SideEffectPass.js +105 -0
  54. package/dist/misra/passes/S13_SideEffectPass.js.map +1 -0
  55. package/dist/misra/passes/S15_ControlFlowPass.d.ts +19 -0
  56. package/dist/misra/passes/S15_ControlFlowPass.d.ts.map +1 -0
  57. package/dist/misra/passes/S15_ControlFlowPass.js +94 -0
  58. package/dist/misra/passes/S15_ControlFlowPass.js.map +1 -0
  59. package/dist/misra/passes/S16_SwitchStatementPass.d.ts +17 -0
  60. package/dist/misra/passes/S16_SwitchStatementPass.d.ts.map +1 -0
  61. package/dist/misra/passes/S16_SwitchStatementPass.js +152 -0
  62. package/dist/misra/passes/S16_SwitchStatementPass.js.map +1 -0
  63. package/dist/misra/passes/S17_FunctionPass.d.ts +12 -0
  64. package/dist/misra/passes/S17_FunctionPass.d.ts.map +1 -0
  65. package/dist/misra/passes/S17_FunctionPass.js +38 -0
  66. package/dist/misra/passes/S17_FunctionPass.js.map +1 -0
  67. package/dist/misra/passes/S18_PointersArraysPass.d.ts +17 -0
  68. package/dist/misra/passes/S18_PointersArraysPass.d.ts.map +1 -0
  69. package/dist/misra/passes/S18_PointersArraysPass.js +115 -0
  70. package/dist/misra/passes/S18_PointersArraysPass.js.map +1 -0
  71. package/dist/misra/passes/S19_OverlappingStoragePass.d.ts +11 -0
  72. package/dist/misra/passes/S19_OverlappingStoragePass.d.ts.map +1 -0
  73. package/dist/misra/passes/S19_OverlappingStoragePass.js +20 -0
  74. package/dist/misra/passes/S19_OverlappingStoragePass.js.map +1 -0
  75. package/dist/misra/passes/S21_StandardLibPass.d.ts +20 -0
  76. package/dist/misra/passes/S21_StandardLibPass.d.ts.map +1 -0
  77. package/dist/misra/passes/S21_StandardLibPass.js +77 -0
  78. package/dist/misra/passes/S21_StandardLibPass.js.map +1 -0
  79. package/dist/misra/passes/S3_CommentPass.d.ts +12 -0
  80. package/dist/misra/passes/S3_CommentPass.d.ts.map +1 -0
  81. package/dist/misra/passes/S3_CommentPass.js +27 -0
  82. package/dist/misra/passes/S3_CommentPass.js.map +1 -0
  83. package/dist/misra/passes/S5_IdentifierPass.d.ts +13 -0
  84. package/dist/misra/passes/S5_IdentifierPass.d.ts.map +1 -0
  85. package/dist/misra/passes/S5_IdentifierPass.js +60 -0
  86. package/dist/misra/passes/S5_IdentifierPass.js.map +1 -0
  87. package/dist/misra/passes/S6_TypePass.d.ts +11 -0
  88. package/dist/misra/passes/S6_TypePass.d.ts.map +1 -0
  89. package/dist/misra/passes/S6_TypePass.js +25 -0
  90. package/dist/misra/passes/S6_TypePass.js.map +1 -0
  91. package/dist/misra/passes/S7_LiteralsConstantsPass.d.ts +14 -0
  92. package/dist/misra/passes/S7_LiteralsConstantsPass.d.ts.map +1 -0
  93. package/dist/misra/passes/S7_LiteralsConstantsPass.js +71 -0
  94. package/dist/misra/passes/S7_LiteralsConstantsPass.js.map +1 -0
  95. package/dist/misra/passes/S8_DeclDefPass.d.ts +18 -0
  96. package/dist/misra/passes/S8_DeclDefPass.d.ts.map +1 -0
  97. package/dist/misra/passes/S8_DeclDefPass.js +127 -0
  98. package/dist/misra/passes/S8_DeclDefPass.js.map +1 -0
  99. package/dist/misra/sections/Section10_EssentialTypeModel.d.ts +33 -0
  100. package/dist/misra/sections/Section10_EssentialTypeModel.d.ts.map +1 -0
  101. package/{src/misra/sections/Section10_EssentialTypeModel.ts → dist/misra/sections/Section10_EssentialTypeModel.js} +58 -73
  102. package/dist/misra/sections/Section10_EssentialTypeModel.js.map +1 -0
  103. package/dist/misra/sections/Section11_PointerTypeConversions.d.ts +12 -0
  104. package/dist/misra/sections/Section11_PointerTypeConversions.d.ts.map +1 -0
  105. package/{src/misra/sections/Section11_PointerTypeConversions.ts → dist/misra/sections/Section11_PointerTypeConversions.js} +16 -27
  106. package/dist/misra/sections/Section11_PointerTypeConversions.js.map +1 -0
  107. package/dist/misra/sections/Section12_Expressions.d.ts +15 -0
  108. package/dist/misra/sections/Section12_Expressions.d.ts.map +1 -0
  109. package/dist/misra/sections/Section12_Expressions.js +70 -0
  110. package/dist/misra/sections/Section12_Expressions.js.map +1 -0
  111. package/dist/misra/sections/Section13_SideEffects.d.ts +14 -0
  112. package/dist/misra/sections/Section13_SideEffects.d.ts.map +1 -0
  113. package/dist/misra/sections/Section13_SideEffects.js +90 -0
  114. package/dist/misra/sections/Section13_SideEffects.js.map +1 -0
  115. package/dist/misra/sections/Section14_ControlStmtExprs.d.ts +8 -0
  116. package/dist/misra/sections/Section14_ControlStmtExprs.d.ts.map +1 -0
  117. package/{src/misra/sections/Section14_ControlStmtExprs.ts → dist/misra/sections/Section14_ControlStmtExprs.js} +8 -10
  118. package/dist/misra/sections/Section14_ControlStmtExprs.js.map +1 -0
  119. package/dist/misra/sections/Section15_ControlFlow.d.ts +14 -0
  120. package/dist/misra/sections/Section15_ControlFlow.d.ts.map +1 -0
  121. package/dist/misra/sections/Section15_ControlFlow.js +97 -0
  122. package/dist/misra/sections/Section15_ControlFlow.js.map +1 -0
  123. package/dist/misra/sections/Section16_SwitchStatements.d.ts +13 -0
  124. package/dist/misra/sections/Section16_SwitchStatements.d.ts.map +1 -0
  125. package/{src/misra/sections/Section16_SwitchStatements.ts → dist/misra/sections/Section16_SwitchStatements.js} +49 -74
  126. package/dist/misra/sections/Section16_SwitchStatements.js.map +1 -0
  127. package/dist/misra/sections/Section17_Functions.d.ts +9 -0
  128. package/dist/misra/sections/Section17_Functions.d.ts.map +1 -0
  129. package/{src/misra/sections/Section17_Functions.ts → dist/misra/sections/Section17_Functions.js} +10 -13
  130. package/dist/misra/sections/Section17_Functions.js.map +1 -0
  131. package/dist/misra/sections/Section18_PointersAndArrays.d.ts +13 -0
  132. package/dist/misra/sections/Section18_PointersAndArrays.d.ts.map +1 -0
  133. package/{src/misra/sections/Section18_PointersAndArrays.ts → dist/misra/sections/Section18_PointersAndArrays.js} +36 -40
  134. package/dist/misra/sections/Section18_PointersAndArrays.js.map +1 -0
  135. package/dist/misra/sections/Section19_OverlappingStorage.d.ts +8 -0
  136. package/dist/misra/sections/Section19_OverlappingStorage.d.ts.map +1 -0
  137. package/dist/misra/sections/Section19_OverlappingStorage.js +16 -0
  138. package/dist/misra/sections/Section19_OverlappingStorage.js.map +1 -0
  139. package/dist/misra/sections/Section20_PreprocessingDirectives.d.ts +8 -0
  140. package/dist/misra/sections/Section20_PreprocessingDirectives.d.ts.map +1 -0
  141. package/{src/misra/sections/Section20_PreprocessingDirectives.ts → dist/misra/sections/Section20_PreprocessingDirectives.js} +7 -9
  142. package/dist/misra/sections/Section20_PreprocessingDirectives.js.map +1 -0
  143. package/dist/misra/sections/Section21_StandardLibraries.d.ts +17 -0
  144. package/dist/misra/sections/Section21_StandardLibraries.d.ts.map +1 -0
  145. package/dist/misra/sections/Section21_StandardLibraries.js +54 -0
  146. package/dist/misra/sections/Section21_StandardLibraries.js.map +1 -0
  147. package/dist/misra/sections/Section2_UnusedCode.d.ts +9 -0
  148. package/dist/misra/sections/Section2_UnusedCode.d.ts.map +1 -0
  149. package/{src/misra/sections/Section2_UnusedCode.ts → dist/misra/sections/Section2_UnusedCode.js} +11 -16
  150. package/dist/misra/sections/Section2_UnusedCode.js.map +1 -0
  151. package/dist/misra/sections/Section3_Comments.d.ts +9 -0
  152. package/dist/misra/sections/Section3_Comments.d.ts.map +1 -0
  153. package/{src/misra/sections/Section3_Comments.ts → dist/misra/sections/Section3_Comments.js} +7 -10
  154. package/dist/misra/sections/Section3_Comments.js.map +1 -0
  155. package/dist/misra/sections/Section5_Identifiers.d.ts +12 -0
  156. package/dist/misra/sections/Section5_Identifiers.d.ts.map +1 -0
  157. package/dist/misra/sections/Section5_Identifiers.js +139 -0
  158. package/dist/misra/sections/Section5_Identifiers.js.map +1 -0
  159. package/dist/misra/sections/Section6_Types.d.ts +8 -0
  160. package/dist/misra/sections/Section6_Types.d.ts.map +1 -0
  161. package/dist/misra/sections/Section6_Types.js +23 -0
  162. package/dist/misra/sections/Section6_Types.js.map +1 -0
  163. package/dist/misra/sections/Section7_LiteralsConstants.d.ts +11 -0
  164. package/dist/misra/sections/Section7_LiteralsConstants.d.ts.map +1 -0
  165. package/{src/misra/sections/Section7_LiteralsConstants.ts → dist/misra/sections/Section7_LiteralsConstants.js} +18 -25
  166. package/dist/misra/sections/Section7_LiteralsConstants.js.map +1 -0
  167. package/dist/misra/sections/Section8_DeclarationsDefinitions.d.ts +15 -0
  168. package/dist/misra/sections/Section8_DeclarationsDefinitions.d.ts.map +1 -0
  169. package/{src/misra/sections/Section8_DeclarationsDefinitions.ts → dist/misra/sections/Section8_DeclarationsDefinitions.js} +18 -33
  170. package/dist/misra/sections/Section8_DeclarationsDefinitions.js.map +1 -0
  171. package/dist/misra/tests/utils.d.ts +10 -0
  172. package/dist/misra/tests/utils.d.ts.map +1 -0
  173. package/dist/misra/tests/utils.js +33 -0
  174. package/dist/misra/tests/utils.js.map +1 -0
  175. package/dist/rules/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.d.ts +15 -0
  176. package/dist/rules/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.d.ts.map +1 -0
  177. package/dist/rules/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.js +33 -0
  178. package/dist/rules/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.js.map +1 -0
  179. package/dist/rules/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.d.ts +16 -0
  180. package/dist/rules/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.d.ts.map +1 -0
  181. package/dist/rules/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.js +60 -0
  182. package/dist/rules/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.js.map +1 -0
  183. package/dist/rules/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.d.ts +19 -0
  184. package/dist/rules/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.d.ts.map +1 -0
  185. package/dist/rules/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.js +42 -0
  186. package/dist/rules/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.js.map +1 -0
  187. package/dist/rules/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.d.ts +43 -0
  188. package/dist/rules/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.d.ts.map +1 -0
  189. package/dist/rules/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.js +103 -0
  190. package/dist/rules/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.js.map +1 -0
  191. package/dist/rules/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.d.ts +26 -0
  192. package/dist/rules/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.d.ts.map +1 -0
  193. package/dist/rules/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.js +49 -0
  194. package/dist/rules/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.js.map +1 -0
  195. package/dist/rules/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.d.ts +26 -0
  196. package/dist/rules/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.d.ts.map +1 -0
  197. package/dist/rules/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.js +49 -0
  198. package/dist/rules/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.js.map +1 -0
  199. package/dist/rules/Section17_Functions/Rule_17_4_NonVoidReturn.d.ts +31 -0
  200. package/dist/rules/Section17_Functions/Rule_17_4_NonVoidReturn.d.ts.map +1 -0
  201. package/dist/rules/Section17_Functions/Rule_17_4_NonVoidReturn.js +71 -0
  202. package/dist/rules/Section17_Functions/Rule_17_4_NonVoidReturn.js.map +1 -0
  203. package/dist/rules/Section17_Functions/Rule_17_6_StaticArraySizeParam.d.ts +27 -0
  204. package/dist/rules/Section17_Functions/Rule_17_6_StaticArraySizeParam.d.ts.map +1 -0
  205. package/dist/rules/Section17_Functions/Rule_17_6_StaticArraySizeParam.js +58 -0
  206. package/dist/rules/Section17_Functions/Rule_17_6_StaticArraySizeParam.js.map +1 -0
  207. package/dist/rules/Section17_Functions/Rule_17_7_UnusedReturnValue.d.ts +28 -0
  208. package/dist/rules/Section17_Functions/Rule_17_7_UnusedReturnValue.d.ts.map +1 -0
  209. package/dist/rules/Section17_Functions/Rule_17_7_UnusedReturnValue.js +44 -0
  210. package/dist/rules/Section17_Functions/Rule_17_7_UnusedReturnValue.js.map +1 -0
  211. package/dist/rules/Section20-PreprocessingDirectives/Rule_20_2_InvalidHeaderFileName.d.ts +55 -0
  212. package/dist/rules/Section20-PreprocessingDirectives/Rule_20_2_InvalidHeaderFileName.d.ts.map +1 -0
  213. package/dist/rules/Section20-PreprocessingDirectives/Rule_20_2_InvalidHeaderFileName.js +108 -0
  214. package/dist/rules/Section20-PreprocessingDirectives/Rule_20_2_InvalidHeaderFileName.js.map +1 -0
  215. package/dist/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.d.ts +43 -0
  216. package/dist/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.d.ts.map +1 -0
  217. package/dist/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.js +68 -0
  218. package/dist/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.js.map +1 -0
  219. package/dist/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.d.ts +29 -0
  220. package/dist/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.d.ts.map +1 -0
  221. package/dist/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.js +53 -0
  222. package/dist/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.js.map +1 -0
  223. package/dist/rules/Section2_UnusedCode/Rule_2_6_UnusedLabels.d.ts +15 -0
  224. package/dist/rules/Section2_UnusedCode/Rule_2_6_UnusedLabels.d.ts.map +1 -0
  225. package/dist/rules/Section2_UnusedCode/Rule_2_6_UnusedLabels.js +35 -0
  226. package/dist/rules/Section2_UnusedCode/Rule_2_6_UnusedLabels.js.map +1 -0
  227. package/dist/rules/Section2_UnusedCode/Rule_2_7_UnusedParameters.d.ts +13 -0
  228. package/dist/rules/Section2_UnusedCode/Rule_2_7_UnusedParameters.d.ts.map +1 -0
  229. package/dist/rules/Section2_UnusedCode/Rule_2_7_UnusedParameters.js +53 -0
  230. package/dist/rules/Section2_UnusedCode/Rule_2_7_UnusedParameters.js.map +1 -0
  231. package/dist/rules/Section3_Comments/Rule_3_1_CommentSequences.d.ts +13 -0
  232. package/dist/rules/Section3_Comments/Rule_3_1_CommentSequences.d.ts.map +1 -0
  233. package/dist/rules/Section3_Comments/Rule_3_1_CommentSequences.js +32 -0
  234. package/dist/rules/Section3_Comments/Rule_3_1_CommentSequences.js.map +1 -0
  235. package/dist/rules/Section3_Comments/Rule_3_2_LineSplicing.d.ts +10 -0
  236. package/dist/rules/Section3_Comments/Rule_3_2_LineSplicing.d.ts.map +1 -0
  237. package/dist/rules/Section3_Comments/Rule_3_2_LineSplicing.js +26 -0
  238. package/dist/rules/Section3_Comments/Rule_3_2_LineSplicing.js.map +1 -0
  239. package/dist/rules/index.d.ts +20 -0
  240. package/dist/rules/index.d.ts.map +1 -0
  241. package/dist/rules/index.js +38 -0
  242. package/dist/rules/index.js.map +1 -0
  243. package/dist/tests/Section17_Functions/misra_config.json +10 -0
  244. package/dist/tests/utils.d.ts +10 -0
  245. package/dist/tests/utils.d.ts.map +1 -0
  246. package/dist/tests/utils.js +29 -0
  247. package/dist/tests/utils.js.map +1 -0
  248. package/dist/utils/utils.d.ts +102 -0
  249. package/dist/utils/utils.d.ts.map +1 -0
  250. package/dist/utils/utils.js +202 -0
  251. package/dist/utils/utils.js.map +1 -0
  252. package/jest.config.js +6 -6
  253. package/package.json +44 -8
  254. package/src/MISRA.ts +276 -0
  255. package/src/MISRAContext.ts +84 -0
  256. package/src/MISRARule.ts +64 -0
  257. package/src/MISRATool.ts +95 -0
  258. package/src/main.ts +4 -33
  259. package/src/misra-old/MISRAAnalyser.ts +60 -0
  260. package/src/misra-old/MISRAAnalyserResult.ts +16 -0
  261. package/src/misra-old/sections/Section10_EssentialTypeModel.ts +377 -0
  262. package/src/misra-old/sections/Section11_PointerTypeConversions.ts +104 -0
  263. package/src/{misra → misra-old}/sections/Section12_Expressions.ts +7 -7
  264. package/src/{misra → misra-old}/sections/Section13_SideEffects.ts +15 -15
  265. package/src/misra-old/sections/Section14_ControlStmtExprs.ts +27 -0
  266. package/src/{misra → misra-old}/sections/Section15_ControlFlow.ts +10 -10
  267. package/src/misra-old/sections/Section18_PointersAndArrays.ts +108 -0
  268. package/src/{misra → misra-old}/sections/Section19_OverlappingStorage.ts +4 -4
  269. package/src/misra-old/sections/Section20_PreprocessingDirectives.ts +22 -0
  270. package/src/misra-old/sections/Section21_StandardLibraries.ts +99 -0
  271. package/src/{misra → misra-old}/sections/Section5_Identifiers.ts +16 -15
  272. package/src/{misra → misra-old}/sections/Section6_Types.ts +4 -4
  273. package/src/misra-old/sections/Section7_LiteralsConstants.ts +76 -0
  274. package/src/misra-old/sections/Section8_DeclarationsDefinitions.ts +133 -0
  275. package/src/rules/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.ts +41 -0
  276. package/src/rules/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.ts +70 -0
  277. package/src/rules/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.ts +41 -0
  278. package/src/rules/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.ts +113 -0
  279. package/src/rules/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.ts +61 -0
  280. package/src/rules/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.ts +57 -0
  281. package/src/rules/Section17_Functions/Rule_17_3_ImplicitFunction.ts +180 -0
  282. package/src/rules/Section17_Functions/Rule_17_4_NonVoidReturn.ts +91 -0
  283. package/src/rules/Section17_Functions/Rule_17_6_StaticArraySizeParam.ts +68 -0
  284. package/src/rules/Section17_Functions/Rule_17_7_UnusedReturnValue.ts +49 -0
  285. package/src/rules/Section20-PreprocessingDirectives/Rule_20_2_InvalidHeaderFileName.ts +120 -0
  286. package/src/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.ts +78 -0
  287. package/src/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.ts +61 -0
  288. package/src/rules/Section2_UnusedCode/Rule_2_6_UnusedLabels.ts +47 -0
  289. package/src/rules/Section2_UnusedCode/Rule_2_7_UnusedParameters.ts +67 -0
  290. package/src/rules/Section3_Comments/Rule_3_1_CommentSequences.ts +41 -0
  291. package/src/rules/Section3_Comments/Rule_3_2_LineSplicing.ts +36 -0
  292. package/src/rules/index.ts +44 -0
  293. package/src/tests/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.test.ts +55 -0
  294. package/src/tests/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.test.ts +70 -0
  295. package/src/tests/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.test.ts +128 -0
  296. package/src/tests/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.test.ts +132 -0
  297. package/src/tests/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.test.ts +146 -0
  298. package/src/tests/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.test.ts +102 -0
  299. package/src/tests/Section17_Functions/Rule_17_3_ImplicitFunctions.test.ts +79 -0
  300. package/src/tests/Section17_Functions/Rule_17_4_NonVoidReturn.test.ts +98 -0
  301. package/src/tests/Section17_Functions/Rule_17_4_NonVoidReturn_MissingConfig.test.ts +77 -0
  302. package/src/tests/Section17_Functions/Rule_17_6_StaticArraySizeParam.test.ts +36 -0
  303. package/src/tests/Section17_Functions/Rule_17_7_UnusedReturnValue.test.ts +44 -0
  304. package/src/tests/Section17_Functions/misra_config.json +19 -0
  305. package/src/tests/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.test.ts +175 -0
  306. package/src/tests/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.test.ts +219 -0
  307. package/src/tests/Section2_UnusedCode/Rule_2_6_UnusedLabels.test.ts +49 -0
  308. package/src/tests/Section2_UnusedCode/Rule_2_7_UnusedParameters.test.ts +55 -0
  309. package/src/tests/Section3_Comments/Rule_3_1_CommentSequences.test.ts +37 -0
  310. package/src/tests/utils.ts +51 -0
  311. package/src/utils/utils.ts +280 -0
  312. package/tsconfig.json +4 -3
  313. package/typedoc.config.js +1 -1
  314. package/CxxSources/lib.cpp +0 -3
  315. package/CxxSources/lib.h +0 -8
  316. package/CxxSources/main.cpp +0 -40
  317. package/TODO.md +0 -1
  318. package/consumer_order.txt +0 -2
  319. package/enum_integer_type.txt +0 -0
  320. package/is_temporary.txt +0 -0
  321. package/omp.txt +0 -0
  322. package/src/misra/passes/S16_SwitchStatementPass.ts +0 -168
  323. package/src/misra/passes/S3_CommentPass.ts +0 -40
  324. package/src/misra/sections/Section21_StandardLibraries.ts +0 -65
  325. package/src/misra/tests/S10_EssentialTypes.test.ts +0 -253
  326. package/src/misra/tests/S12_Expressions.test.ts +0 -43
  327. package/src/misra/tests/S13_SideEffects.test.ts +0 -77
  328. package/src/misra/tests/S15_ControlFlow.test.ts +0 -144
  329. package/src/misra/tests/S16_SwitchStatements.test.ts +0 -164
  330. package/src/misra/tests/S17_Functions.test.ts +0 -46
  331. package/src/misra/tests/S18_PointersArrays.test.ts +0 -167
  332. package/src/misra/tests/S19_OverlappingStorage.test.ts +0 -38
  333. package/src/misra/tests/S3_Comments.test.ts +0 -36
  334. package/src/misra/tests/S6_Types.test.ts +0 -36
  335. package/src/misra/tests/S7_LiteralsConstants.test.ts +0 -48
  336. package/src/misra/tests/utils.ts +0 -47
  337. package/types_with_templates.txt +0 -0
  338. /package/src/{misra → misra-old}/MISRAPass.ts +0 -0
  339. /package/src/{misra → misra-old}/MISRAPassResult.ts +0 -0
  340. /package/src/{misra → misra-old}/MISRAReporter.ts +0 -0
  341. /package/src/{misra → misra-old}/passes/S10_EssentialTypePass.ts +0 -0
  342. /package/src/{misra → misra-old}/passes/S12_ExpressionPass.ts +0 -0
  343. /package/src/{misra → misra-old}/passes/S13_SideEffectPass.ts +0 -0
  344. /package/src/{misra → misra-old}/passes/S15_ControlFlowPass.ts +0 -0
  345. /package/src/{misra → misra-old}/passes/S17_FunctionPass.ts +0 -0
  346. /package/src/{misra → misra-old}/passes/S18_PointersArraysPass.ts +0 -0
  347. /package/src/{misra → misra-old}/passes/S19_OverlappingStoragePass.ts +0 -0
  348. /package/src/{misra → misra-old}/passes/S21_StandardLibPass.ts +0 -0
  349. /package/src/{misra → misra-old}/passes/S5_IdentifierPass.ts +0 -0
  350. /package/src/{misra → misra-old}/passes/S6_TypePass.ts +0 -0
  351. /package/src/{misra → misra-old}/passes/S7_LiteralsConstantsPass.ts +0 -0
  352. /package/src/{misra → misra-old}/passes/S8_DeclDefPass.ts +0 -0
@@ -0,0 +1,43 @@
1
+ import { Joinpoint } from "@specs-feup/clava/api/Joinpoints.js";
2
+ import MISRARule from "../../MISRARule.js";
3
+ import MISRAContext from "../../MISRAContext.js";
4
+ import { MISRATransformationReport } from "../../MISRA.js";
5
+ /**
6
+ * MISRA Rule 16.5: A default label shall appear as either the first or the last switch label of
7
+ a switch statement
8
+ */
9
+ export default class Rule_16_5_DefaultFirstOrLast extends MISRARule {
10
+ constructor(context: MISRAContext);
11
+ /**
12
+ * Retrieves all consecutive case statements to the left of a given case statement
13
+ *
14
+ * @param $jp - The starting case statement from which the search will begin
15
+ * @returns Array containing consecutive case statements to the left of the provided joinpoint
16
+ *
17
+ */
18
+ private getConsecutiveRightCases;
19
+ /**
20
+ * Retrieves all consecutive case statements to the right of a given case statement
21
+ *
22
+ * @param $jp - The starting case statement from which the search will begin
23
+ * @returns Array containing consecutive case statements to the right of the provided joinpoint
24
+ *
25
+ */
26
+ private getConsecutiveLeftCases;
27
+ /**
28
+ * Checks if the given joinpoint is a switch statement where the default label appears either as first of last label
29
+ * @param $jp - Joinpoint to analyze
30
+ * @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
31
+ * @returns Returns true if the joinpoint violates the rule, false otherwise
32
+ */
33
+ match($jp: Joinpoint, logErrors?: boolean): boolean;
34
+ /**
35
+ * Transforms a switch statement so that the default case appears as the last label
36
+ * - If the default case is not already the last case within its case clause list, it is repositioned
37
+ * - Then, the entire case clause list containing the default case to the end of the switch statement
38
+ * @param $jp - Joinpoint to transform
39
+ * @returns Report detailing the transformation result
40
+ */
41
+ transform($jp: Joinpoint): MISRATransformationReport;
42
+ }
43
+ //# sourceMappingURL=Rule_16_5_DefaultFirstOrLast.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rule_16_5_DefaultFirstOrLast.d.ts","sourceRoot":"","sources":["../../../src/rules/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,SAAS,EAAkC,MAAM,qCAAqC,CAAC;AAC9G,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,YAAY,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,yBAAyB,EAA2B,MAAM,gBAAgB,CAAC;AAGpF;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,4BAA6B,SAAQ,SAAS;gBAEnD,OAAO,EAAE,YAAY;IAIjC;;;;;;OAMG;IACH,OAAO,CAAC,wBAAwB;IAUhC;;;;;;OAMG;IACH,OAAO,CAAC,uBAAuB;IAY/B;;;;;OAKG;IACH,KAAK,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,GAAE,OAAe,GAAG,OAAO;IAmB1D;;;;;;OAMG;IACH,SAAS,CAAC,GAAG,EAAE,SAAS,GAAG,yBAAyB;CA4BvD"}
@@ -0,0 +1,103 @@
1
+ import { Case, Switch } from "@specs-feup/clava/api/Joinpoints.js";
2
+ import MISRARule from "../../MISRARule.js";
3
+ import { MISRATransformationReport, MISRATransformationType } from "../../MISRA.js";
4
+ import { isCommentStmt } from "../../utils/utils.js";
5
+ /**
6
+ * MISRA Rule 16.5: A default label shall appear as either the first or the last switch label of
7
+ a switch statement
8
+ */
9
+ export default class Rule_16_5_DefaultFirstOrLast extends MISRARule {
10
+ constructor(context) {
11
+ super("16.5", context);
12
+ }
13
+ /**
14
+ * Retrieves all consecutive case statements to the left of a given case statement
15
+ *
16
+ * @param $jp - The starting case statement from which the search will begin
17
+ * @returns Array containing consecutive case statements to the left of the provided joinpoint
18
+ *
19
+ */
20
+ getConsecutiveRightCases($jp) {
21
+ const cases = [];
22
+ for (const stmt of $jp.siblingsRight) {
23
+ if (!(stmt instanceof Case || isCommentStmt($jp)))
24
+ break;
25
+ cases.push(stmt);
26
+ }
27
+ return cases;
28
+ }
29
+ /**
30
+ * Retrieves all consecutive case statements to the right of a given case statement
31
+ *
32
+ * @param $jp - The starting case statement from which the search will begin
33
+ * @returns Array containing consecutive case statements to the right of the provided joinpoint
34
+ *
35
+ */
36
+ getConsecutiveLeftCases($jp) {
37
+ let cases = [];
38
+ for (let i = $jp.siblingsLeft.length - 1; i >= 0; i--) {
39
+ const currentStmt = $jp.siblingsLeft[i];
40
+ if (!(currentStmt instanceof Case || isCommentStmt($jp))) {
41
+ break;
42
+ }
43
+ cases.push($jp.siblingsLeft[i]);
44
+ }
45
+ return cases.reverse();
46
+ }
47
+ /**
48
+ * Checks if the given joinpoint is a switch statement where the default label appears either as first of last label
49
+ * @param $jp - Joinpoint to analyze
50
+ * @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
51
+ * @returns Returns true if the joinpoint violates the rule, false otherwise
52
+ */
53
+ match($jp, logErrors = false) {
54
+ if (!($jp instanceof Switch))
55
+ return false;
56
+ const caseStmts = $jp.cases;
57
+ for (let i = 0; i < caseStmts.length; i++) {
58
+ const currentCase = caseStmts[i];
59
+ if (currentCase.isDefault) {
60
+ if (i == 0 || i == caseStmts.length - 1) {
61
+ return false;
62
+ }
63
+ if (logErrors) {
64
+ this.logMISRAError($jp, "The default case of a switch statement must be the first or last label.");
65
+ }
66
+ return true;
67
+ }
68
+ }
69
+ return false;
70
+ }
71
+ /**
72
+ * Transforms a switch statement so that the default case appears as the last label
73
+ * - If the default case is not already the last case within its case clause list, it is repositioned
74
+ * - Then, the entire case clause list containing the default case to the end of the switch statement
75
+ * @param $jp - Joinpoint to transform
76
+ * @returns Report detailing the transformation result
77
+ */
78
+ transform($jp) {
79
+ if (!this.match($jp))
80
+ return new MISRATransformationReport(MISRATransformationType.NoChange);
81
+ const defaultCase = $jp.getDefaultCase;
82
+ const rightStatements = defaultCase.siblingsRight.filter(sibling => !isCommentStmt(sibling));
83
+ // Reposition the default case to the last position within its case clause lis
84
+ if (rightStatements[0] instanceof Case) { // At least one of the first statements is a Case
85
+ const rightConsecutiveCases = this.getConsecutiveRightCases(defaultCase);
86
+ const lastRightCase = rightConsecutiveCases[rightConsecutiveCases.length - 1];
87
+ defaultCase.detach();
88
+ lastRightCase.insertAfter(defaultCase);
89
+ if (defaultCase.nextCase === undefined) { // Default is now the last case
90
+ return new MISRATransformationReport(MISRATransformationType.DescendantChange);
91
+ }
92
+ }
93
+ // Move the entire case clause list containing the default case to the end of the switch statement
94
+ const switchScope = $jp.children[1];
95
+ const stmts = [...this.getConsecutiveLeftCases(defaultCase), defaultCase, ...defaultCase.instructions];
96
+ for (const stmt of stmts) {
97
+ stmt.detach();
98
+ switchScope.lastChild.insertAfter(stmt);
99
+ }
100
+ return new MISRATransformationReport(MISRATransformationType.DescendantChange);
101
+ }
102
+ }
103
+ //# sourceMappingURL=Rule_16_5_DefaultFirstOrLast.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rule_16_5_DefaultFirstOrLast.js","sourceRoot":"","sources":["../../../src/rules/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAiC,MAAM,EAAe,MAAM,qCAAqC,CAAC;AAC9G,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EAAE,yBAAyB,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AACpF,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,4BAA6B,SAAQ,SAAS;IAE/D,YAAY,OAAqB;QAC7B,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC3B,CAAC;IAED;;;;;;OAMG;IACK,wBAAwB,CAAC,GAAS;QACtC,MAAM,KAAK,GAAG,EAAE,CAAC;QACjB,KAAK,MAAM,IAAI,IAAI,GAAG,CAAC,aAAa,EAAE,CAAC;YACnC,IAAI,CAAC,CAAC,IAAI,YAAY,IAAI,IAAI,aAAa,CAAC,GAAG,CAAC,CAAC;gBAC7C,MAAM;YACV,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACrB,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;IAED;;;;;;OAMG;IACK,uBAAuB,CAAC,GAAS;QACrC,IAAI,KAAK,GAAgB,EAAE,CAAC;QAC5B,KAAK,IAAI,CAAC,GAAG,GAAG,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,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RAContext.js";
4
+ import { MISRATransformationReport } from "../../MISRA.js";
5
+ /**
6
+ * MISRA Rule 16.6: Every switch statement shall have at least two switch-clauses.
7
+ */
8
+ export default class Rule_16_6_SwitchMinTwoClauses extends MISRARule {
9
+ constructor(context: MISRAContext);
10
+ /**
11
+ * Checks if the given joinpoint is a switch statement with less than two clauses
12
+ * @param $jp - Joinpoint to analyze
13
+ * @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
14
+ * @returns Returns true if the joinpoint violates the rule, false otherwise
15
+ */
16
+ match($jp: Joinpoint, logErrors?: boolean): boolean;
17
+ /**
18
+ * Transforms a switch statement with less than two clauses into equivalent statement(s), only if there is no conditional break.
19
+ * If a conditional break is present, no transformation is performed and an error is generated.
20
+ *
21
+ * @param $jp - Joinpoint to transform
22
+ * @returns Report detailing the transformation result
23
+ */
24
+ transform($jp: Joinpoint): MISRATransformationReport;
25
+ }
26
+ //# sourceMappingURL=Rule_16_6_SwitchMinTwoClauses.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rule_16_6_SwitchMinTwoClauses.d.ts","sourceRoot":"","sources":["../../../src/rules/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,SAAS,EAAiC,MAAM,qCAAqC,CAAC;AAC3G,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,YAAY,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAwB,yBAAyB,EAA2B,MAAM,gBAAgB,CAAC;AAG1G;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,6BAA8B,SAAQ,SAAS;gBAEpD,OAAO,EAAE,YAAY;IAIjC;;;;;OAKG;IACH,KAAK,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,GAAE,OAAe,GAAG,OAAO;IAU1D;;;;;;OAMG;IACH,SAAS,CAAC,GAAG,EAAE,SAAS,GAAG,yBAAyB;CAkBvD"}
@@ -0,0 +1,49 @@
1
+ import { Switch } from "@specs-feup/clava/api/Joinpoints.js";
2
+ import MISRARule from "../../MISRARule.js";
3
+ import { MISRASwitchConverter, MISRATransformationReport, MISRATransformationType } from "../../MISRA.js";
4
+ import { getNumOfSwitchClauses, switchHasConditionalBreak } from "../../utils/utils.js";
5
+ /**
6
+ * MISRA Rule 16.6: Every switch statement shall have at least two switch-clauses.
7
+ */
8
+ export default class Rule_16_6_SwitchMinTwoClauses extends MISRARule {
9
+ constructor(context) {
10
+ super("16.6", context);
11
+ }
12
+ /**
13
+ * Checks if the given joinpoint is a switch statement with less than two clauses
14
+ * @param $jp - Joinpoint to analyze
15
+ * @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
16
+ * @returns Returns true if the joinpoint violates the rule, false otherwise
17
+ */
18
+ match($jp, logErrors = false) {
19
+ if (!($jp instanceof Switch))
20
+ return false;
21
+ const nonCompliant = getNumOfSwitchClauses($jp) < 2;
22
+ if (nonCompliant && logErrors) {
23
+ this.logMISRAError($jp, "Switch statements should have at least two clauses.");
24
+ }
25
+ return nonCompliant;
26
+ }
27
+ /**
28
+ * Transforms a switch statement with less than two clauses into equivalent statement(s), only if there is no conditional break.
29
+ * If a conditional break is present, no transformation is performed and an error is generated.
30
+ *
31
+ * @param $jp - Joinpoint to transform
32
+ * @returns Report detailing the transformation result
33
+ */
34
+ transform($jp) {
35
+ if (!this.match($jp))
36
+ return new MISRATransformationReport(MISRATransformationType.NoChange);
37
+ if (switchHasConditionalBreak($jp)) {
38
+ this.logMISRAError($jp, "switch statement must have at least two clauses and cannot be transformed due to a conditional break statement.");
39
+ return new MISRATransformationReport(MISRATransformationType.NoChange);
40
+ }
41
+ const transformResultNode = MISRASwitchConverter.convert($jp);
42
+ if (transformResultNode) {
43
+ return new MISRATransformationReport(MISRATransformationType.Replacement, transformResultNode);
44
+ }
45
+ // Only breaks were present, so the switch was removed
46
+ return new MISRATransformationReport(MISRATransformationType.Removal);
47
+ }
48
+ }
49
+ //# sourceMappingURL=Rule_16_6_SwitchMinTwoClauses.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rule_16_6_SwitchMinTwoClauses.js","sourceRoot":"","sources":["../../../src/rules/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgD,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAC3G,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAC1G,OAAO,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAExF;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,6BAA8B,SAAQ,SAAS;IAEhE,YAAY,OAAqB;QAC7B,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC3B,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,GAAc,EAAE,YAAqB,KAAK;QAC5C,IAAI,CAAC,CAAC,GAAG,YAAY,MAAM,CAAC;YAAE,OAAO,KAAK,CAAC;QAE3C,MAAM,YAAY,GAAG,qBAAqB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACpD,IAAI,YAAY,IAAI,SAAS,EAAE,CAAC;YAC5B,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,qDAAqD,CAAC,CAAA;QAClF,CAAC;QACD,OAAO,YAAY,CAAC;IACxB,CAAC;IAED;;;;;;OAMG;IACH,SAAS,CAAC,GAAc;QACpB,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;YAAE,OAAO,IAAI,yBAAyB,CAAC,uBAAuB,CAAC,QAAQ,CAAC,CAAC;QAE7F,IAAI,yBAAyB,CAAC,GAAa,CAAC,EAAE,CAAC;YAC3C,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,iHAAiH,CAAC,CAAA;YAC1I,OAAO,IAAI,yBAAyB,CAAC,uBAAuB,CAAC,QAAQ,CAAC,CAAC;QAC3E,CAAC;QAED,MAAM,mBAAmB,GAAG,oBAAoB,CAAC,OAAO,CAAC,GAAa,CAAC,CAAC;QACxE,IAAI,mBAAmB,EAAE,CAAC;YACtB,OAAO,IAAI,yBAAyB,CAChC,uBAAuB,CAAC,WAAW,EACnC,mBAAmB,CACtB,CAAC;QACN,CAAC;QACD,sDAAsD;QACtD,OAAO,IAAI,yBAAyB,CAAC,uBAAuB,CAAC,OAAO,CAAC,CAAC;IAC1E,CAAC;CACJ"}
@@ -0,0 +1,26 @@
1
+ import { Joinpoint } from "@specs-feup/clava/api/Joinpoints.js";
2
+ import MISRARule from "../../MISRARule.js";
3
+ import MISRAContext from "../../MISRAContext.js";
4
+ import { MISRATransformationReport } from "../../MISRA.js";
5
+ /**
6
+ * MISRA Rule 16.7: A switch-expression shall not have essentially Boolean type.
7
+ */
8
+ export default class Rule_16_7_NonBooleanSwitchCondition extends MISRARule {
9
+ constructor(context: MISRAContext);
10
+ /**
11
+ * Checks if the given joinpoint is a switch statement with an essentially Boolean condition
12
+ * @param $jp - Joinpoint to analyze
13
+ * @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
14
+ * @returns Returns true if the joinpoint violates the rule, false otherwise
15
+ */
16
+ match($jp: Joinpoint, logErrors?: boolean): boolean;
17
+ /**
18
+ * Transforms a switch statement with a Boolean condition into equivalent statement(s), only if there is no conditional break.
19
+ * If a conditional break is present, no transformation is performed and an error is generated.
20
+ *
21
+ * @param $jp - Joinpoint to transform
22
+ * @returns Report detailing the transformation result
23
+ */
24
+ transform($jp: Joinpoint): MISRATransformationReport;
25
+ }
26
+ //# sourceMappingURL=Rule_16_7_NonBooleanSwitchCondition.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rule_16_7_NonBooleanSwitchCondition.d.ts","sourceRoot":"","sources":["../../../src/rules/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,SAAS,EAAU,MAAM,qCAAqC,CAAC;AACrF,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,YAAY,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAwB,yBAAyB,EAA2B,MAAM,gBAAgB,CAAC;AAG1G;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,mCAAoC,SAAQ,SAAS;gBAC1D,OAAO,EAAE,YAAY;IAIjC;;;;;OAKG;IACH,KAAK,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,GAAE,OAAe,GAAG,OAAO;IAU1D;;;;;;OAMG;IACH,SAAS,CAAC,GAAG,EAAE,SAAS,GAAG,yBAAyB;CAkBvD"}
@@ -0,0 +1,49 @@
1
+ import { Switch } from "@specs-feup/clava/api/Joinpoints.js";
2
+ import MISRARule from "../../MISRARule.js";
3
+ import { MISRASwitchConverter, MISRATransformationReport, MISRATransformationType } from "../../MISRA.js";
4
+ import { switchHasBooleanCondition, switchHasConditionalBreak } from "../../utils/utils.js";
5
+ /**
6
+ * MISRA Rule 16.7: A switch-expression shall not have essentially Boolean type.
7
+ */
8
+ export default class Rule_16_7_NonBooleanSwitchCondition extends MISRARule {
9
+ constructor(context) {
10
+ super("16.7", context);
11
+ }
12
+ /**
13
+ * Checks if the given joinpoint is a switch statement with an essentially Boolean condition
14
+ * @param $jp - Joinpoint to analyze
15
+ * @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
16
+ * @returns Returns true if the joinpoint violates the rule, false otherwise
17
+ */
18
+ match($jp, logErrors = false) {
19
+ if (!($jp instanceof Switch))
20
+ return false;
21
+ const booleanCondition = switchHasBooleanCondition($jp);
22
+ if (booleanCondition && logErrors) {
23
+ this.logMISRAError($jp, `Switch statement controlling expression ${$jp.condition.code} must not have essentially boolean type.`);
24
+ }
25
+ return booleanCondition;
26
+ }
27
+ /**
28
+ * Transforms a switch statement with a Boolean condition into equivalent statement(s), only if there is no conditional break.
29
+ * If a conditional break is present, no transformation is performed and an error is generated.
30
+ *
31
+ * @param $jp - Joinpoint to transform
32
+ * @returns Report detailing the transformation result
33
+ */
34
+ transform($jp) {
35
+ if (!this.match($jp))
36
+ return new MISRATransformationReport(MISRATransformationType.NoChange);
37
+ if (switchHasConditionalBreak($jp)) {
38
+ this.logMISRAError($jp, `The switch statement's controlling expression ${$jp.condition.code} must not be of a boolean type and cannot be transformed due to a conditional break statement.`);
39
+ return new MISRATransformationReport(MISRATransformationType.NoChange);
40
+ }
41
+ const transformResultNode = MISRASwitchConverter.convert($jp);
42
+ if (transformResultNode) {
43
+ return new MISRATransformationReport(MISRATransformationType.Replacement, transformResultNode);
44
+ }
45
+ // Only breaks were present, so the switch was removed
46
+ return new MISRATransformationReport(MISRATransformationType.Removal);
47
+ }
48
+ }
49
+ //# sourceMappingURL=Rule_16_7_NonBooleanSwitchCondition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rule_16_7_NonBooleanSwitchCondition.js","sourceRoot":"","sources":["../../../src/rules/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,MAAM,EAAE,MAAM,qCAAqC,CAAC;AACrF,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAC1G,OAAO,EAAE,yBAAyB,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAE5F;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,mCAAoC,SAAQ,SAAS;IACtE,YAAY,OAAqB;QAC7B,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC3B,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,GAAc,EAAE,YAAqB,KAAK;QAC5C,IAAI,CAAC,CAAC,GAAG,YAAY,MAAM,CAAC;YAAE,OAAO,KAAK,CAAC;QAE3C,MAAM,gBAAgB,GAAG,yBAAyB,CAAC,GAAG,CAAC,CAAC;QACxD,IAAI,gBAAgB,IAAI,SAAS,EAAE,CAAC;YAChC,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,2CAA2C,GAAG,CAAC,SAAS,CAAC,IAAI,0CAA0C,CAAC,CAAA;QACpI,CAAC;QACD,OAAO,gBAAgB,CAAC;IAC5B,CAAC;IAED;;;;;;OAMG;IACH,SAAS,CAAC,GAAc;QACpB,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;YAAE,OAAO,IAAI,yBAAyB,CAAC,uBAAuB,CAAC,QAAQ,CAAC,CAAC;QAE7F,IAAI,yBAAyB,CAAC,GAAa,CAAC,EAAE,CAAC;YAC3C,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,iDAAkD,GAAc,CAAC,SAAS,CAAC,IAAI,gGAAgG,CAAC,CAAA;YACxM,OAAO,IAAI,yBAAyB,CAAC,uBAAuB,CAAC,QAAQ,CAAC,CAAC;QAC3E,CAAC;QAED,MAAM,mBAAmB,GAAG,oBAAoB,CAAC,OAAO,CAAC,GAAa,CAAC,CAAC;QACxE,IAAI,mBAAmB,EAAE,CAAC;YACtB,OAAO,IAAI,yBAAyB,CAChC,uBAAuB,CAAC,WAAW,EACnC,mBAAmB,CACtB,CAAC;QACN,CAAC;QACD,sDAAsD;QACtD,OAAO,IAAI,yBAAyB,CAAC,uBAAuB,CAAC,OAAO,CAAC,CAAC;IAC1E,CAAC;CACJ"}
@@ -0,0 +1,31 @@
1
+ import { Joinpoint } from "@specs-feup/clava/api/Joinpoints.js";
2
+ import MISRARule from "../../MISRARule.js";
3
+ import MISRAContext from "../../MISRAContext.js";
4
+ import { MISRATransformationReport } from "../../MISRA.js";
5
+ /**
6
+ * MISRA Rule 17.4: All exit paths from a function with non-void return type shall have an
7
+ explicit return statement with an expression. In a non-void function:
8
+ - Every return statement has an expression, and a
9
+ - Control cannot reach the end of the function without encountering a return statement
10
+ */
11
+ export default class Rule_17_4_NonVoidReturn extends MISRARule {
12
+ constructor(context: MISRAContext);
13
+ /**
14
+ * Checks if the given joinpoint represents a non-void function that lacks an explicit return statement with an expression.
15
+ *
16
+ * @param $jp - Joinpoint to analyze
17
+ * @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
18
+ * @returns Returns true if the joinpoint violates the rule, false otherwise
19
+ */
20
+ match($jp: Joinpoint, logErrors?: boolean): boolean;
21
+ /**
22
+ * Transforms a non-void function joinpoint that has no return statement at the end, by adding a default return value based on the config file.
23
+ * - If the configuration file is is missing or invalid, no transformation is performed.
24
+ * - Otherwise, a return statement is inserted as the last statement of the function.
25
+ *
26
+ * @param $jp - Joinpoint to transform
27
+ * @returns Report detailing the transformation result
28
+ */
29
+ transform($jp: Joinpoint): MISRATransformationReport;
30
+ }
31
+ //# sourceMappingURL=Rule_17_4_NonVoidReturn.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rule_17_4_NonVoidReturn.d.ts","sourceRoot":"","sources":["../../../src/rules/Section17_Functions/Rule_17_4_NonVoidReturn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqD,SAAS,EAAc,MAAM,qCAAqC,CAAC;AAC/H,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,YAAY,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAE,yBAAyB,EAA2B,MAAM,gBAAgB,CAAC;AAGpF;;;;;GAKG;AACH,MAAM,CAAC,OAAO,OAAO,uBAAwB,SAAQ,SAAS;gBAC9C,OAAO,EAAE,YAAY;IAIjC;;;;;;OAMG;IACH,KAAK,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,GAAE,OAAe,GAAG,OAAO;IAkB1D;;;;;;;OAOG;IACH,SAAS,CAAC,GAAG,EAAE,SAAS,GAAG,yBAAyB;CA0BvD"}
@@ -0,0 +1,71 @@
1
+ import { BuiltinType, FunctionJp, ReturnStmt } from "@specs-feup/clava/api/Joinpoints.js";
2
+ import MISRARule from "../../MISRARule.js";
3
+ import ClavaJoinPoints from "@specs-feup/clava/api/clava/ClavaJoinPoints.js";
4
+ import { MISRATransformationReport, MISRATransformationType } from "../../MISRA.js";
5
+ import Query from "@specs-feup/lara/api/weaver/Query.js";
6
+ /**
7
+ * MISRA Rule 17.4: All exit paths from a function with non-void return type shall have an
8
+ explicit return statement with an expression. In a non-void function:
9
+ - Every return statement has an expression, and a
10
+ - Control cannot reach the end of the function without encountering a return statement
11
+ */
12
+ export default class Rule_17_4_NonVoidReturn extends MISRARule {
13
+ constructor(context) {
14
+ super("17.4", context);
15
+ }
16
+ /**
17
+ * Checks if the given joinpoint represents a non-void function that lacks an explicit return statement with an expression.
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, logErrors = false) {
24
+ if (!($jp instanceof FunctionJp && $jp.isImplementation))
25
+ return false;
26
+ if ($jp.returnType instanceof BuiltinType && $jp.returnType.isVoid)
27
+ return false;
28
+ const emptyReturnStms = Query.searchFrom($jp, ReturnStmt, { returnExpr: undefined }).get();
29
+ const exitReturn = $jp.body.children.filter(child => child instanceof ReturnStmt && !emptyReturnStms.includes(child))[0];
30
+ if (logErrors) {
31
+ emptyReturnStms?.forEach(emptyReturn => this.logMISRAError(emptyReturn, "Every return statement in a non-void function must include an expression."));
32
+ if (exitReturn === undefined) {
33
+ this.logMISRAError($jp, `Function '${$jp.name}' reaches the end without a return statement.`);
34
+ }
35
+ }
36
+ return emptyReturnStms.length > 0 || exitReturn === undefined;
37
+ }
38
+ /**
39
+ * Transforms a non-void function joinpoint that has no return statement at the end, by adding a default return value based on the config file.
40
+ * - If the configuration file is is missing or invalid, no transformation is performed.
41
+ * - Otherwise, a return statement is inserted as the last statement of the function.
42
+ *
43
+ * @param $jp - Joinpoint to transform
44
+ * @returns Report detailing the transformation result
45
+ */
46
+ transform($jp) {
47
+ if (!this.match($jp))
48
+ return new MISRATransformationReport(MISRATransformationType.NoChange);
49
+ const functionJp = $jp;
50
+ if (this.context.config) {
51
+ try {
52
+ const returnType = functionJp.type.code;
53
+ const defaultValueReturn = this.context.config.get("defaultValues")[returnType];
54
+ if (defaultValueReturn === undefined) {
55
+ this.logMISRAError($jp, `Function '${functionJp.name}' reaches the end without a return statement. Default value return not added due to missing default value configuration for type '${returnType}'.`);
56
+ return new MISRATransformationReport(MISRATransformationType.NoChange);
57
+ }
58
+ const newJp = ClavaJoinPoints.returnStmt(ClavaJoinPoints.exprLiteral(String(defaultValueReturn), functionJp.returnType));
59
+ functionJp.body.lastChild ? functionJp.body.lastChild.insertAfter(newJp) : functionJp.body.setFirstChild(newJp);
60
+ return new MISRATransformationReport(MISRATransformationType.DescendantChange);
61
+ }
62
+ catch (error) {
63
+ this.logMISRAError($jp, `Function '${functionJp.name}' reaches the end without a return statement. Default value return not added due to invalid structure of configuration file.`);
64
+ return new MISRATransformationReport(MISRATransformationType.NoChange);
65
+ }
66
+ }
67
+ this.logMISRAError($jp, `Function '${functionJp.name}' reaches the end without a return statement. Default value return not added due to missing config file.`);
68
+ return new MISRATransformationReport(MISRATransformationType.NoChange);
69
+ }
70
+ }
71
+ //# sourceMappingURL=Rule_17_4_NonVoidReturn.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rule_17_4_NonVoidReturn.js","sourceRoot":"","sources":["../../../src/rules/Section17_Functions/Rule_17_4_NonVoidReturn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAA4B,UAAU,EAAa,UAAU,EAAE,MAAM,qCAAqC,CAAC;AAC/H,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAE3C,OAAO,eAAe,MAAM,gDAAgD,CAAC;AAC7E,OAAO,EAAE,yBAAyB,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AACpF,OAAO,KAAK,MAAM,sCAAsC,CAAC;AAEzD;;;;;GAKG;AACH,MAAM,CAAC,OAAO,OAAO,uBAAwB,SAAQ,SAAS;IAC1D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BAAuB,CAAC,QAAQ,CAAC,CAAC;IAC3E,CAAC;CACJ"}
@@ -0,0 +1,27 @@
1
+ import { Joinpoint } from "@specs-feup/clava/api/Joinpoints.js";
2
+ import MISRARule from "../../MISRARule.js";
3
+ import MISRAContext from "../../MISRAContext.js";
4
+ import { MISRATransformationReport } from "../../MISRA.js";
5
+ /**
6
+ * MISRA Rule 17.6: The declaration of an array parameter shall not contain the static keyword between the [ ]
7
+ */
8
+ export default class Rule_17_6_StaticArraySizeParam extends MISRARule {
9
+ #private;
10
+ constructor(context: MISRAContext);
11
+ /**
12
+ * Checks if the given joinpoint represents a function with any array parameter containing the 'static' keyword between the [ ].
13
+ *
14
+ * @param $jp - Joinpoint to analyze
15
+ * @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
16
+ * @returns Returns true if the joinpoint violates the rule, false otherwise
17
+ */
18
+ match($jp: Joinpoint, logErrors?: boolean): boolean;
19
+ /**
20
+ * Transforms the joinpoint if it represents a function with any array parameter containing the 'static' keyword between the square brackets.
21
+ *
22
+ * @param $jp - Joinpoint to transform
23
+ * @returns Report detailing the transformation result
24
+ */
25
+ transform($jp: Joinpoint): MISRATransformationReport;
26
+ }
27
+ //# sourceMappingURL=Rule_17_6_StaticArraySizeParam.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rule_17_6_StaticArraySizeParam.d.ts","sourceRoot":"","sources":["../../../src/rules/Section17_Functions/Rule_17_6_StaticArraySizeParam.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuC,SAAS,EAAS,MAAM,qCAAqC,CAAC;AAC5G,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,YAAY,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAE,yBAAyB,EAA2B,MAAM,gBAAgB,CAAC;AAGpF;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,8BAA+B,SAAQ,SAAS;;gBAErD,OAAO,EAAE,YAAY;IAIjC;;;;;;OAMG;IACH,KAAK,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,GAAE,OAAe,GAAG,OAAO;IAiB1D;;;;;OAKG;IACH,SAAS,CAAC,GAAG,EAAE,SAAS,GAAG,yBAAyB;CAqBvD"}
@@ -0,0 +1,58 @@
1
+ import { AdjustedType, ArrayType, FunctionJp } from "@specs-feup/clava/api/Joinpoints.js";
2
+ import MISRARule from "../../MISRARule.js";
3
+ import ClavaJoinPoints from "@specs-feup/clava/api/clava/ClavaJoinPoints.js";
4
+ import { MISRATransformationReport, MISRATransformationType } from "../../MISRA.js";
5
+ import { getParamReferences } from "../../utils/utils.js";
6
+ /**
7
+ * MISRA Rule 17.6: The declaration of an array parameter shall not contain the static keyword between the [ ]
8
+ */
9
+ export default class Rule_17_6_StaticArraySizeParam extends MISRARule {
10
+ #invalidParams = [];
11
+ constructor(context) {
12
+ super("17.6", context);
13
+ }
14
+ /**
15
+ * Checks if the given joinpoint represents a function with any array parameter containing the 'static' keyword between the [ ].
16
+ *
17
+ * @param $jp - Joinpoint to analyze
18
+ * @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
19
+ * @returns Returns true if the joinpoint violates the rule, false otherwise
20
+ */
21
+ match($jp, logErrors = false) {
22
+ if (!($jp instanceof FunctionJp) || $jp.root.standard === "c90")
23
+ return false;
24
+ this.#invalidParams = $jp.params.filter(paramJp => paramJp.type instanceof AdjustedType &&
25
+ paramJp.type.originalType instanceof ArrayType &&
26
+ paramJp.type.originalType.arraySize !== -1 &&
27
+ /\[\s*static\s+\d+\s*\]/.test(paramJp.code));
28
+ if (logErrors) {
29
+ for (const invalidParam of this.#invalidParams) {
30
+ this.logMISRAError(invalidParam, `The 'static' keyword cannot appear inside the square brackets ('[]') in array parameter declarations.`);
31
+ }
32
+ }
33
+ return this.#invalidParams.length > 0;
34
+ }
35
+ /**
36
+ * Transforms the joinpoint if it represents a function with any array parameter containing the 'static' keyword between the square brackets.
37
+ *
38
+ * @param $jp - Joinpoint to transform
39
+ * @returns Report detailing the transformation result
40
+ */
41
+ transform($jp) {
42
+ if (!this.match($jp))
43
+ return new MISRATransformationReport(MISRATransformationType.NoChange);
44
+ for (const invalidParam of this.#invalidParams) {
45
+ const paramRefs = getParamReferences(invalidParam, $jp);
46
+ // Replace the parameter with a new array parameter whose size is variant
47
+ const originalType = invalidParam.type.originalType;
48
+ const newJp = ClavaJoinPoints.param(invalidParam.name, ClavaJoinPoints.incompleteArrayType(originalType.elementType));
49
+ const newParam = invalidParam.replaceWith(newJp);
50
+ // Replace all references to the invalid parameter with the new one
51
+ for (const ref of paramRefs) {
52
+ ref.replaceWith(newParam.varref());
53
+ }
54
+ }
55
+ return new MISRATransformationReport(MISRATransformationType.DescendantChange);
56
+ }
57
+ }
58
+ //# sourceMappingURL=Rule_17_6_StaticArraySizeParam.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rule_17_6_StaticArraySizeParam.js","sourceRoot":"","sources":["../../../src/rules/Section17_Functions/Rule_17_6_StaticArraySizeParam.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,UAAU,EAAoB,MAAM,qCAAqC,CAAC;AAC5G,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAE3C,OAAO,eAAe,MAAM,gDAAgD,CAAC;AAC7E,OAAO,EAAE,yBAAyB,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AACpF,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,8BAA+B,SAAQ,SAAS;IACjE,cAAc,GAAY,EAAE,CAAC;IAC7B,YAAY,OAAqB;QAC7B,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC3B,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,GAAc,EAAE,YAAqB,KAAK;QAC5C,IAAI,CAAC,CAAC,GAAG,YAAY,UAAU,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,KAAK,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GAAG,CAAC,WAAW,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;YACvC,CAAC;QACL,CAAC;QACD,OAAO,IAAI,yBAAyB,CAAC,uBAAuB,CAAC,gBAAgB,CAAC,CAAC;IACnF,CAAC;CACJ"}
@@ -0,0 +1,28 @@
1
+ import { Joinpoint } from "@specs-feup/clava/api/Joinpoints.js";
2
+ import MISRARule from "../../MISRARule.js";
3
+ import MISRAContext from "../../MISRAContext.js";
4
+ import { MISRATransformationReport } from "../../MISRA.js";
5
+ /**
6
+ * MISRA Rule 17.7: The value returned by a function having non-void return type shall be
7
+ used
8
+ */
9
+ export default class Rule_17_7_UnusedReturnValue extends MISRARule {
10
+ constructor(context: MISRAContext);
11
+ /**
12
+ * Checks if the given joinpoint represents a non-void function call with an unused return value.
13
+ *
14
+ * @param $jp - Joinpoint to analyze
15
+ * @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
16
+ * @returns Returns true if the joinpoint violates the rule, false otherwise
17
+ */
18
+ match($jp: Joinpoint, logErrors?: boolean): boolean;
19
+ /**
20
+ * Transforms the joinpoint if it represents a non-void function call, whose return type is unused.
21
+ * It ensures that the return value is explicitly cast to void.
22
+ *
23
+ * @param $jp - Joinpoint to transform
24
+ * @returns Report detailing the transformation result
25
+ */
26
+ transform($jp: Joinpoint): MISRATransformationReport;
27
+ }
28
+ //# sourceMappingURL=Rule_17_7_UnusedReturnValue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rule_17_7_UnusedReturnValue.d.ts","sourceRoot":"","sources":["../../../src/rules/Section17_Functions/Rule_17_7_UnusedReturnValue.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,SAAS,EAAE,MAAM,qCAAqC,CAAC;AAC7F,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,YAAY,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAE,yBAAyB,EAA2B,MAAM,gBAAgB,CAAC;AAEpF;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,2BAA4B,SAAQ,SAAS;gBAClD,OAAO,EAAE,YAAY;IAIjC;;;;;;OAMG;IACH,KAAK,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,GAAE,OAAe,GAAG,OAAO;IAW1D;;;;;;OAMG;IACH,SAAS,CAAC,GAAG,EAAE,SAAS,GAAG,yBAAyB;CAMvD"}
@@ -0,0 +1,44 @@
1
+ import { BuiltinType, Call, ExprStmt } from "@specs-feup/clava/api/Joinpoints.js";
2
+ import MISRARule from "../../MISRARule.js";
3
+ import ClavaJoinPoints from "@specs-feup/clava/api/clava/ClavaJoinPoints.js";
4
+ import { MISRATransformationReport, MISRATransformationType } from "../../MISRA.js";
5
+ /**
6
+ * MISRA Rule 17.7: The value returned by a function having non-void return type shall be
7
+ used
8
+ */
9
+ export default class Rule_17_7_UnusedReturnValue extends MISRARule {
10
+ constructor(context) {
11
+ super("17.7", context);
12
+ }
13
+ /**
14
+ * Checks if the given joinpoint represents a non-void function call with an unused return value.
15
+ *
16
+ * @param $jp - Joinpoint to analyze
17
+ * @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
18
+ * @returns Returns true if the joinpoint violates the rule, false otherwise
19
+ */
20
+ match($jp, logErrors = false) {
21
+ if (!($jp instanceof Call))
22
+ return false;
23
+ if ($jp.returnType instanceof BuiltinType && $jp.returnType.isVoid)
24
+ return false;
25
+ if ($jp.parent instanceof ExprStmt && logErrors) {
26
+ this.logMISRAError($jp, `Return value of ${$jp.signature} must be used. It can be discarded with an explicit cast to void.`);
27
+ }
28
+ return $jp.parent instanceof ExprStmt;
29
+ }
30
+ /**
31
+ * Transforms the joinpoint if it represents a non-void function call, whose return type is unused.
32
+ * It ensures that the return value is explicitly cast to void.
33
+ *
34
+ * @param $jp - Joinpoint to transform
35
+ * @returns Report detailing the transformation result
36
+ */
37
+ transform($jp) {
38
+ if (!this.match($jp))
39
+ return new MISRATransformationReport(MISRATransformationType.NoChange);
40
+ const newJp = ClavaJoinPoints.cStyleCast(ClavaJoinPoints.type("void"), $jp);
41
+ return new MISRATransformationReport(MISRATransformationType.Replacement, $jp.replaceWith(newJp));
42
+ }
43
+ }
44
+ //# sourceMappingURL=Rule_17_7_UnusedReturnValue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rule_17_7_UnusedReturnValue.js","sourceRoot":"","sources":["../../../src/rules/Section17_Functions/Rule_17_7_UnusedReturnValue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,QAAQ,EAAa,MAAM,qCAAqC,CAAC;AAC7F,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAE3C,OAAO,eAAe,MAAM,gDAAgD,CAAC;AAC7E,OAAO,EAAE,yBAAyB,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAEpF;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,2BAA4B,SAAQ,SAAS;IAC9D,YAAY,OAAqB;QAC7B,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC3B,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,GAAc,EAAE,YAAqB,KAAK;QAC5C,IAAI,CAAC,CAAC,GAAG,YAAY,IAAI,CAAC;YAAE,OAAO,KAAK,CAAC;QAEzC,IAAI,GAAG,CAAC,UAAU,YAAY,WAAW,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM;YAAE,OAAO,KAAK,CAAC;QAEjF,IAAI,GAAG,CAAC,MAAM,YAAY,QAAQ,IAAI,SAAS,EAAE,CAAC;YAC9C,IAAI,CAAC,aAAa,CAAC,GAAG,EAAC,mBAAmB,GAAG,CAAC,SAAS,mEAAmE,CAAC,CAAC;QAChI,CAAC;QACD,OAAO,GAAG,CAAC,MAAM,YAAY,QAAQ,CAAC;IAC1C,CAAC;IAED;;;;;;OAMG;IACH,SAAS,CAAC,GAAc;QACpB,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;YAAE,OAAO,I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