@specs-feup/clava-misra 1.0.0 → 1.0.1

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 (350) 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 +40 -8
  254. package/src/MISRA.ts +266 -0
  255. package/src/MISRAContext.ts +91 -0
  256. package/src/MISRARule.ts +77 -0
  257. package/src/MISRATool.ts +96 -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 +40 -0
  276. package/src/rules/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.ts +69 -0
  277. package/src/rules/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.ts +46 -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 +57 -0
  280. package/src/rules/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.ts +56 -0
  281. package/src/rules/Section17_Functions/Rule_17_4_NonVoidReturn.ts +78 -0
  282. package/src/rules/Section17_Functions/Rule_17_6_StaticArraySizeParam.ts +68 -0
  283. package/src/rules/Section17_Functions/Rule_17_7_UnusedReturnValue.ts +47 -0
  284. package/src/rules/Section20-PreprocessingDirectives/Rule_20_2_InvalidHeaderFileName.ts +120 -0
  285. package/src/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.ts +75 -0
  286. package/src/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.ts +60 -0
  287. package/src/rules/Section2_UnusedCode/Rule_2_6_UnusedLabels.ts +46 -0
  288. package/src/rules/Section2_UnusedCode/Rule_2_7_UnusedParameters.ts +65 -0
  289. package/src/rules/Section3_Comments/Rule_3_1_CommentSequences.ts +41 -0
  290. package/src/rules/Section3_Comments/Rule_3_2_LineSplicing.ts +36 -0
  291. package/src/rules/index.ts +40 -0
  292. package/src/tests/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.test.ts +55 -0
  293. package/src/tests/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.test.ts +70 -0
  294. package/src/tests/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.test.ts +128 -0
  295. package/src/tests/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.test.ts +132 -0
  296. package/src/tests/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.test.ts +146 -0
  297. package/src/tests/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.test.ts +102 -0
  298. package/src/tests/Section17_Functions/Rule_17_4_NonVoidReturn.test.ts +85 -0
  299. package/src/tests/Section17_Functions/Rule_17_4_NonVoidReturn_MissingConfig.test.ts +77 -0
  300. package/src/tests/Section17_Functions/Rule_17_6_StaticArraySizeParam.test.ts +36 -0
  301. package/src/tests/Section17_Functions/Rule_17_7_UnusedReturnValue.test.ts +44 -0
  302. package/src/tests/Section17_Functions/misra_config.json +10 -0
  303. package/src/tests/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.test.ts +175 -0
  304. package/src/tests/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.test.ts +219 -0
  305. package/src/tests/Section2_UnusedCode/Rule_2_6_UnusedLabels.test.ts +49 -0
  306. package/src/tests/Section2_UnusedCode/Rule_2_7_UnusedParameters.test.ts +55 -0
  307. package/src/tests/Section3_Comments/Rule_3_1_CommentSequences.test.ts +37 -0
  308. package/src/tests/utils.ts +39 -0
  309. package/src/utils/utils.ts +221 -0
  310. package/tsconfig.json +4 -3
  311. package/typedoc.config.js +1 -1
  312. package/CxxSources/lib.cpp +0 -3
  313. package/CxxSources/lib.h +0 -8
  314. package/CxxSources/main.cpp +0 -40
  315. package/TODO.md +0 -1
  316. package/consumer_order.txt +0 -2
  317. package/enum_integer_type.txt +0 -0
  318. package/is_temporary.txt +0 -0
  319. package/omp.txt +0 -0
  320. package/src/misra/passes/S16_SwitchStatementPass.ts +0 -168
  321. package/src/misra/passes/S3_CommentPass.ts +0 -40
  322. package/src/misra/sections/Section21_StandardLibraries.ts +0 -65
  323. package/src/misra/tests/S10_EssentialTypes.test.ts +0 -253
  324. package/src/misra/tests/S12_Expressions.test.ts +0 -43
  325. package/src/misra/tests/S13_SideEffects.test.ts +0 -77
  326. package/src/misra/tests/S15_ControlFlow.test.ts +0 -144
  327. package/src/misra/tests/S16_SwitchStatements.test.ts +0 -164
  328. package/src/misra/tests/S17_Functions.test.ts +0 -46
  329. package/src/misra/tests/S18_PointersArrays.test.ts +0 -167
  330. package/src/misra/tests/S19_OverlappingStorage.test.ts +0 -38
  331. package/src/misra/tests/S3_Comments.test.ts +0 -36
  332. package/src/misra/tests/S6_Types.test.ts +0 -36
  333. package/src/misra/tests/S7_LiteralsConstants.test.ts +0 -48
  334. package/src/misra/tests/utils.ts +0 -47
  335. package/types_with_templates.txt +0 -0
  336. /package/src/{misra → misra-old}/MISRAPass.ts +0 -0
  337. /package/src/{misra → misra-old}/MISRAPassResult.ts +0 -0
  338. /package/src/{misra → misra-old}/MISRAReporter.ts +0 -0
  339. /package/src/{misra → misra-old}/passes/S10_EssentialTypePass.ts +0 -0
  340. /package/src/{misra → misra-old}/passes/S12_ExpressionPass.ts +0 -0
  341. /package/src/{misra → misra-old}/passes/S13_SideEffectPass.ts +0 -0
  342. /package/src/{misra → misra-old}/passes/S15_ControlFlowPass.ts +0 -0
  343. /package/src/{misra → misra-old}/passes/S17_FunctionPass.ts +0 -0
  344. /package/src/{misra → misra-old}/passes/S18_PointersArraysPass.ts +0 -0
  345. /package/src/{misra → misra-old}/passes/S19_OverlappingStoragePass.ts +0 -0
  346. /package/src/{misra → misra-old}/passes/S21_StandardLibPass.ts +0 -0
  347. /package/src/{misra → misra-old}/passes/S5_IdentifierPass.ts +0 -0
  348. /package/src/{misra → misra-old}/passes/S6_TypePass.ts +0 -0
  349. /package/src/{misra → misra-old}/passes/S7_LiteralsConstantsPass.ts +0 -0
  350. /package/src/{misra → misra-old}/passes/S8_DeclDefPass.ts +0 -0
package/.gitignore ADDED
@@ -0,0 +1,117 @@
1
+ ##### User-added #####
2
+ woven_code/
3
+ /dist
4
+ /docs
5
+ package-lock.json
6
+ CxxSources
7
+ /misra_config.json
8
+ /src/main.ts
9
+
10
+ # Extensions
11
+ ltex.dictionary.*
12
+ ######################
13
+
14
+ # Logs
15
+ logs
16
+ *.log
17
+ npm-debug.log*
18
+ yarn-debug.log*
19
+ yarn-error.log*
20
+ lerna-debug.log*
21
+
22
+ # Diagnostic reports (https://nodejs.org/api/report.html)
23
+ report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
24
+
25
+ # Runtime data
26
+ pids
27
+ *.pid
28
+ *.seed
29
+ *.pid.lock
30
+
31
+ # Directory for instrumented libs generated by jscoverage/JSCover
32
+ lib-cov
33
+
34
+ # Coverage directory used by tools like istanbul
35
+ coverage
36
+ *.lcov
37
+
38
+ # nyc test coverage
39
+ .nyc_output
40
+
41
+ # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
42
+ .grunt
43
+
44
+ # Bower dependency directory (https://bower.io/)
45
+ bower_components
46
+
47
+ # node-waf configuration
48
+ .lock-wscript
49
+
50
+ # Compiled binary addons (https://nodejs.org/api/addons.html)
51
+ build/Release
52
+
53
+ # Dependency directories
54
+ node_modules/
55
+ jspm_packages/
56
+
57
+ # TypeScript v1 declaration files
58
+ typings/
59
+
60
+ # TypeScript cache
61
+ *.tsbuildinfo
62
+
63
+ # Optional npm cache directory
64
+ .npm
65
+
66
+ # Optional eslint cache
67
+ .eslintcache
68
+
69
+ # Microbundle cache
70
+ .rpt2_cache/
71
+ .rts2_cache_cjs/
72
+ .rts2_cache_es/
73
+ .rts2_cache_umd/
74
+
75
+ # Optional REPL history
76
+ .node_repl_history
77
+
78
+ # Output of 'npm pack'
79
+ *.tgz
80
+
81
+ # Yarn Integrity file
82
+ .yarn-integrity
83
+
84
+ # dotenv environment variables file
85
+ .env
86
+ .env.test
87
+
88
+ # parcel-bundler cache (https://parceljs.org/)
89
+ .cache
90
+
91
+ # Next.js build output
92
+ .next
93
+
94
+ # Nuxt.js build / generate output
95
+ .nuxt
96
+ dist
97
+
98
+ # Gatsby files
99
+ .cache/
100
+ # Comment in the public line in if your project uses Gatsby and *not* Next.js
101
+ # https://nextjs.org/blog/next-9-1#public-directory-support
102
+ # public
103
+
104
+ # vuepress build output
105
+ .vuepress/dist
106
+
107
+ # Serverless directories
108
+ .serverless/
109
+
110
+ # FuseBox cache
111
+ .fusebox/
112
+
113
+ # DynamoDB Local files
114
+ .dynamodb/
115
+
116
+ # TernJS port file
117
+ .tern-port
package/README.md CHANGED
@@ -1,32 +1,87 @@
1
- # clava-project-template
1
+ # Clava MISRA Tool
2
2
 
3
- A template for developing projects for Clava in Typescript
3
+ A Clava-based library to automatically detect and correct parts of C code that violate MISRA-C:2012 coding standard.
4
4
 
5
- ## Installing dev environment
5
+ For more details, see the [Clava Transpiler repository](https://github.com/specs-feup/clava).
6
6
 
7
- Execute the following commands to download all the required code:
7
+ ## Installation
8
+
9
+ To get started, ensure the tool's NPM package is installed in your project:
8
10
 
9
11
  ```bash
10
- npm install
12
+ npm install @specs-feup/clava-misra
11
13
  ```
12
14
 
13
- ## Executing Clava-JS
15
+ ## Usage
14
16
 
15
- You can execute your project in Clava by running the following on your terminal
17
+ ### 1. Analysis
18
+ You can use the tool to simply check the violations by executing the following statements in your script:
16
19
 
17
- ```bash
18
- npm run run
20
+ ```ts
21
+ import MISRATool from "@specs-feup/clava-misra/dist/MISRATool.js";
22
+
23
+ MISRATool.checkCompliance();
19
24
  ```
25
+ After analysis, each identified violation will be displayed, including its location and description.
20
26
 
21
- Take a look inside the `scripts` field in the `package.json` file for more information.
27
+ ### 2. Correction
28
+ Besides analysis, the tool can also correct the provided source code to comply with the coding guidelines, using the following statements:
29
+
30
+ ```ts
31
+ import MISRATool from "@specs-feup/clava-misra/dist/MISRATool.js";
32
+
33
+ MISRATool.applyCorrections();
34
+ ```
22
35
 
23
- You can also run tests, get test coverage information and generate documentation for your project.
36
+ After the transformation, any violations that could not be fixed will be displayed along with their justification. The corrected files will be saved in the `woven_code` folder.
24
37
 
25
- ## Debugging
38
+ You can provide an **optional** JSON config file to assist in correcting specific rules, such as implicit function calls, disallowed functions, and missing return statements. For instance, you can:
39
+ - Define default values for certain types to address functions with missing return statements.
40
+ - Provide custom implementations for disallowed functions.
41
+ - Specify the path or library for implicit function calls.
26
42
 
27
- You can get debugging information using a `DEBUG` environment variable.
28
- This variable is used by the [debug](https://www.npmjs.com/package/debug) module to determine what to expose.
43
+ The config file should follow this structure:
44
+ ```json
45
+ {
46
+ "defaultValues": {
47
+ "unsigned int": 0,
48
+ "float": 0.0,
49
+ "enum Status": "SUCCESS",
50
+ "Color": "RED",
51
+ "my_int_type": "0"
52
+ }
53
+ }
54
+ ```
55
+ **Note:** Not all fields are required and if the config file is not provided or lacks the necessary information to fix a violation, the violation will remain and be displayed as unresolved.
56
+
57
+ After preparing the config file, provide its full path to `applyCorrections` method call:
58
+
59
+ ```ts
60
+ import MISRATool from "@specs-feup/clava-misra/dist/MISRATool.js";
61
+
62
+ MISRATool.applyCorrections("/full/path/to/json/config/file");
63
+ ```
64
+
65
+ ## Execution
66
+
67
+ To execute a project that uses this tool, you must provide the following information:
68
+
69
+ - The path to your **script file**.
70
+ - The **C standard** to use (`c90`, `c99`, or `c11`).
71
+ - The path to the **source code** to process.
72
+
73
+ ```bash
74
+ npx clava classic [path/to/scriptFile.js] -pi -std [c90 | c99 | c11] -p [path/to/source/code]
75
+ ```
76
+
77
+ **Example:**
29
78
 
30
79
  ```bash
31
- DEBUG="*" npm run run
80
+ npx clava classic main.js -pi -std c99 -p CxxSources/
32
81
  ```
82
+
83
+ To view other available options, run:
84
+
85
+ ```bash
86
+ npx clava classic -dummy
87
+ ```
@@ -0,0 +1,129 @@
1
+ import { If, Joinpoint, Statement, Switch } from "@specs-feup/clava/api/Joinpoints.js";
2
+ export declare enum MISRATransformationType {
3
+ NoChange = 0,
4
+ DescendantChange = 1,
5
+ Replacement = 2,
6
+ Removal = 3
7
+ }
8
+ /**
9
+ * Represents an error in MISRA compliance, including the rule ID, the joinpoint where the violation occurred, and a descriptive message.
10
+ */
11
+ export declare class MISRAError {
12
+ /**
13
+ * Represents the specific MISRA rule that was violated
14
+ */
15
+ ruleID: string;
16
+ /**
17
+ * The joinpoint where the error was detected
18
+ */
19
+ $jp: Joinpoint;
20
+ /**
21
+ * Explanation of the violation
22
+ */
23
+ message: string;
24
+ /**
25
+ *
26
+ * @param ruleID - specific MISRA rule that was violated
27
+ * @param $jp - joinpoint where the error was detected
28
+ * @param message - description of the error
29
+ */
30
+ constructor(ruleID: string, $jp: Joinpoint, message: string);
31
+ /**
32
+ * Checks if two instances of MISRAError are equal based on all properties
33
+ * @param other
34
+ * @returns Returns `true` if the errors are the same, `false` otherwise
35
+ */
36
+ equals(other: MISRAError): boolean;
37
+ }
38
+ /**
39
+ * A report of a MISRA transformation, including the transformation type and an optional new joinpoint node.
40
+ *
41
+ * If the transformation type is `Replacement`, the `newNode` must be provided to indicate the new joinpoint.
42
+ */
43
+ export declare class MISRATransformationReport {
44
+ /**
45
+ * The type of the MISRA transformation
46
+ */
47
+ type: MISRATransformationType;
48
+ /**
49
+ * An optional new joinpoint node, provided if the transformation involves a replacement
50
+ */
51
+ newNode?: Joinpoint;
52
+ /**
53
+ *
54
+ * @param type The type of the MISRA transformation
55
+ * @param newNode The new joinpoint node resulting from the transformation. Required if the transformation type is `Replacement`.
56
+ */
57
+ constructor(type: MISRATransformationType, newNode?: Joinpoint);
58
+ }
59
+ /**
60
+ * Converts a switch statement into either consecutive statements or if statements
61
+ * - If the switch has only one clause and a default case, it is converted to consecutive statements
62
+ * - Otherwise, it is converted to if statements
63
+ */
64
+ export declare class MISRASwitchConverter {
65
+ /**
66
+ * Converts a switch statement to consecutive statements or if statements
67
+ *
68
+ * @param switchStmt - The switch statement to convert
69
+ * @returns The converted statements or `undefined` if no statements remain
70
+ */
71
+ static convert(switchStmt: Switch): Statement | undefined;
72
+ /**
73
+ * Converts a switch with only one clause and a default case into consecutive statements
74
+ *
75
+ * @param switchStmt - The switch statement to convert
76
+ * @returns The first statement or `undefined` if no statements remain
77
+ */
78
+ static convertToConsecutiveStmts(switchStmt: Switch): Statement | undefined;
79
+ /**
80
+ * Converts a switch statement into a series of if statements
81
+ *
82
+ * @param switchStmt - The switch statement to convert
83
+ * @returns The first if statement created
84
+ */
85
+ static convertToIfStatements(switchStmt: Switch): If;
86
+ /**
87
+ * Creates an if statement for the given consecutive cases
88
+ *
89
+ * @param condition - The switch condition
90
+ * @param cases - A list of consecutive cases
91
+ * @param index - The index of the current case group
92
+ * @param lastIfStmt - The last if statement, used to chain else
93
+ * @returns The new if statement
94
+ */
95
+ private static createIfStatement;
96
+ /**
97
+ * Creates the equivalent condition for an if statement based on the case values
98
+ *
99
+ * @param condition - The switch condition
100
+ * @param cases - A list of case` statements
101
+ * @returns The combined condition
102
+ */
103
+ private static equivalentCondition;
104
+ /**
105
+ * Removes all break statements from the given scope
106
+ * @param scope - The scope from which the break statements will be removed
107
+ */
108
+ private static removeBreakStmts;
109
+ /**
110
+ * Removes all case statements from the given scope
111
+ * @param scope - The scope from which the case statements will be removed
112
+ */
113
+ private static removeCases;
114
+ /**
115
+ * Groups case statements into consecutive blocks, ensuring the block with the default case is last
116
+ *
117
+ * @param switchStmt - The switch statement
118
+ * @returns The grouped case statements
119
+ */
120
+ private static consecutiveCases;
121
+ /**
122
+ * Organizes case groups such that the group with default case is placed last.
123
+ *
124
+ * @param caseGroups - The groups of case statements
125
+ * @returns The organized case groups
126
+ */
127
+ private static organizeCaseGroups;
128
+ }
129
+ //# sourceMappingURL=MISRA.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MISRA.d.ts","sourceRoot":"","sources":["../src/MISRA.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqC,EAAE,EAAE,SAAS,EAAS,SAAS,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAIjI,oBAAY,uBAAuB;IAC/B,QAAQ,IAAA;IACR,gBAAgB,IAAA;IAChB,WAAW,IAAA;IACX,OAAO,IAAA;CACV;AAED;;GAEG;AACH,qBAAa,UAAU;IACnB;;OAEG;IACI,MAAM,EAAE,MAAM,CAAC;IACtB;;OAEG;IACI,GAAG,EAAE,SAAS,CAAC;IACtB;;OAEG;IACI,OAAO,EAAE,MAAM,CAAC;IAEvB;;;;;OAKG;gBACS,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM;IAM3D;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO;CAKrC;AAED;;;;GAIG;AACH,qBAAa,yBAAyB;IAClC;;OAEG;IACH,IAAI,EAAE,uBAAuB,CAAC;IAC9B;;OAEG;IACH,OAAO,CAAC,EAAE,SAAS,CAAC;IAEpB;;;;OAIG;gBACS,IAAI,EAAE,uBAAuB,EAAE,OAAO,CAAC,EAAE,SAAS;CAOjE;AAED;;;;GAIG;AACH,qBAAa,oBAAoB;IAC7B;;;;;OAKG;IACH,MAAM,CAAC,OAAO,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS;IAQzD;;;;;OAKG;IACH,MAAM,CAAC,yBAAyB,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS;IA6B3E;;;;;OAKG;IACH,MAAM,CAAC,qBAAqB,CAAC,UAAU,EAAE,MAAM,GAAG,EAAE;IAuBpD;;;;;;;;OAQG;IACH,OAAO,CAAC,MAAM,CAAC,iBAAiB;IAahC;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAC,mBAAmB;IAgBlC;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAK/B;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,WAAW;IAK1B;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAiB/B;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,kBAAkB;CAQpC"}
package/dist/MISRA.js ADDED
@@ -0,0 +1,245 @@
1
+ import { Break, Case } from "@specs-feup/clava/api/Joinpoints.js";
2
+ import { getNumOfSwitchClauses, isCommentStmt } from "./utils/utils.js";
3
+ import ClavaJoinPoints from "@specs-feup/clava/api/clava/ClavaJoinPoints.js";
4
+ export var MISRATransformationType;
5
+ (function (MISRATransformationType) {
6
+ MISRATransformationType[MISRATransformationType["NoChange"] = 0] = "NoChange";
7
+ MISRATransformationType[MISRATransformationType["DescendantChange"] = 1] = "DescendantChange";
8
+ MISRATransformationType[MISRATransformationType["Replacement"] = 2] = "Replacement";
9
+ MISRATransformationType[MISRATransformationType["Removal"] = 3] = "Removal";
10
+ })(MISRATransformationType || (MISRATransformationType = {}));
11
+ /**
12
+ * Represents an error in MISRA compliance, including the rule ID, the joinpoint where the violation occurred, and a descriptive message.
13
+ */
14
+ export class MISRAError {
15
+ /**
16
+ * Represents the specific MISRA rule that was violated
17
+ */
18
+ ruleID;
19
+ /**
20
+ * The joinpoint where the error was detected
21
+ */
22
+ $jp;
23
+ /**
24
+ * Explanation of the violation
25
+ */
26
+ message;
27
+ /**
28
+ *
29
+ * @param ruleID - specific MISRA rule that was violated
30
+ * @param $jp - joinpoint where the error was detected
31
+ * @param message - description of the error
32
+ */
33
+ constructor(ruleID, $jp, message) {
34
+ this.ruleID = ruleID;
35
+ this.$jp = $jp;
36
+ this.message = message;
37
+ }
38
+ /**
39
+ * Checks if two instances of MISRAError are equal based on all properties
40
+ * @param other
41
+ * @returns Returns `true` if the errors are the same, `false` otherwise
42
+ */
43
+ equals(other) {
44
+ return this.ruleID === other.ruleID &&
45
+ this.$jp.astId === other.$jp.astId &&
46
+ this.message === other.message;
47
+ }
48
+ }
49
+ /**
50
+ * A report of a MISRA transformation, including the transformation type and an optional new joinpoint node.
51
+ *
52
+ * If the transformation type is `Replacement`, the `newNode` must be provided to indicate the new joinpoint.
53
+ */
54
+ export class MISRATransformationReport {
55
+ /**
56
+ * The type of the MISRA transformation
57
+ */
58
+ type;
59
+ /**
60
+ * An optional new joinpoint node, provided if the transformation involves a replacement
61
+ */
62
+ newNode;
63
+ /**
64
+ *
65
+ * @param type The type of the MISRA transformation
66
+ * @param newNode The new joinpoint node resulting from the transformation. Required if the transformation type is `Replacement`.
67
+ */
68
+ constructor(type, newNode) {
69
+ this.type = type;
70
+ if (type === MISRATransformationType.Replacement && !newNode) {
71
+ throw new Error("newNode must be provided when a 'Replacement' transformation is performed");
72
+ }
73
+ this.newNode = newNode;
74
+ }
75
+ }
76
+ /**
77
+ * Converts a switch statement into either consecutive statements or if statements
78
+ * - If the switch has only one clause and a default case, it is converted to consecutive statements
79
+ * - Otherwise, it is converted to if statements
80
+ */
81
+ export class MISRASwitchConverter {
82
+ /**
83
+ * Converts a switch statement to consecutive statements or if statements
84
+ *
85
+ * @param switchStmt - The switch statement to convert
86
+ * @returns The converted statements or `undefined` if no statements remain
87
+ */
88
+ static convert(switchStmt) {
89
+ if (switchStmt.hasDefaultCase && getNumOfSwitchClauses(switchStmt) < 2) { // The statements will always be executed
90
+ return this.convertToConsecutiveStmts(switchStmt);
91
+ }
92
+ else {
93
+ return this.convertToIfStatements(switchStmt);
94
+ }
95
+ }
96
+ /**
97
+ * Converts a switch with only one clause and a default case into consecutive statements
98
+ *
99
+ * @param switchStmt - The switch statement to convert
100
+ * @returns The first statement or `undefined` if no statements remain
101
+ */
102
+ static convertToConsecutiveStmts(switchStmt) {
103
+ const scope = switchStmt.children[1];
104
+ this.removeBreakStmts(scope);
105
+ this.removeCases(scope);
106
+ // If there are no statements except break and comments, the switch can be removed
107
+ if (scope.children.length === 0 || scope.children.every(stmt => isCommentStmt(stmt))) {
108
+ switchStmt.detach();
109
+ return undefined;
110
+ }
111
+ let firstStmt, lastStmt;
112
+ const stmts = scope.children;
113
+ for (let i = 0; i < stmts.length; i++) {
114
+ const stmt = stmts[i];
115
+ stmt.detach();
116
+ if (!firstStmt) {
117
+ firstStmt = stmt;
118
+ switchStmt.replaceWith(firstStmt);
119
+ lastStmt = stmt;
120
+ continue;
121
+ }
122
+ lastStmt.insertAfter(stmt);
123
+ lastStmt = stmt;
124
+ }
125
+ return firstStmt;
126
+ }
127
+ /**
128
+ * Converts a switch statement into a series of if statements
129
+ *
130
+ * @param switchStmt - The switch statement to convert
131
+ * @returns The first if statement created
132
+ */
133
+ static convertToIfStatements(switchStmt) {
134
+ const scope = switchStmt.children[1];
135
+ const consecutiveCases = this.consecutiveCases(switchStmt);
136
+ this.removeBreakStmts(scope);
137
+ let ifStmt;
138
+ let lastIfStmt;
139
+ for (let i = 0; i < consecutiveCases.length; i++) {
140
+ const cases = consecutiveCases[i];
141
+ if (cases.some(caseStmt => caseStmt.isDefault)) { // Has default case
142
+ lastIfStmt.setElse(ClavaJoinPoints.scope(...cases[cases.length - 1].instructions));
143
+ }
144
+ else {
145
+ lastIfStmt = this.createIfStatement(switchStmt.condition, cases, i, lastIfStmt);
146
+ if (i === 0) {
147
+ ifStmt = lastIfStmt;
148
+ }
149
+ }
150
+ }
151
+ switchStmt.replaceWith(ifStmt);
152
+ return ifStmt;
153
+ }
154
+ /**
155
+ * Creates an if statement for the given consecutive cases
156
+ *
157
+ * @param condition - The switch condition
158
+ * @param cases - A list of consecutive cases
159
+ * @param index - The index of the current case group
160
+ * @param lastIfStmt - The last if statement, used to chain else
161
+ * @returns The new if statement
162
+ */
163
+ static createIfStatement(condition, cases, index, lastIfStmt) {
164
+ const conditionExpr = this.equivalentCondition(condition, cases);
165
+ const thenBody = ClavaJoinPoints.scope(...cases[cases.length - 1].instructions);
166
+ const newIfStmt = ClavaJoinPoints.ifStmt(conditionExpr, thenBody);
167
+ if (index === 0) {
168
+ return newIfStmt;
169
+ }
170
+ else {
171
+ lastIfStmt.setElse(newIfStmt);
172
+ return newIfStmt;
173
+ }
174
+ }
175
+ /**
176
+ * Creates the equivalent condition for an if statement based on the case values
177
+ *
178
+ * @param condition - The switch condition
179
+ * @param cases - A list of case` statements
180
+ * @returns The combined condition
181
+ */
182
+ static equivalentCondition(condition, cases) {
183
+ let lastBinaryOp;
184
+ for (let i = 0; i < cases.length; i++) {
185
+ const caseStmt = cases[i];
186
+ const newBinaryOp = ClavaJoinPoints.binaryOp("==", condition, caseStmt.values[0]);
187
+ if (i === 0) {
188
+ lastBinaryOp = newBinaryOp;
189
+ continue;
190
+ }
191
+ lastBinaryOp = ClavaJoinPoints.binaryOp("||", lastBinaryOp, newBinaryOp);
192
+ }
193
+ return lastBinaryOp;
194
+ }
195
+ /**
196
+ * Removes all break statements from the given scope
197
+ * @param scope - The scope from which the break statements will be removed
198
+ */
199
+ static removeBreakStmts(scope) {
200
+ const breakStmts = scope.children.filter(child => child instanceof Break);
201
+ breakStmts.forEach(stmt => stmt.detach());
202
+ }
203
+ /**
204
+ * Removes all case statements from the given scope
205
+ * @param scope - The scope from which the case statements will be removed
206
+ */
207
+ static removeCases(scope) {
208
+ const cases = scope.children.filter(child => child instanceof Case);
209
+ cases.forEach(caseStmt => caseStmt.detach());
210
+ }
211
+ /**
212
+ * Groups case statements into consecutive blocks, ensuring the block with the default case is last
213
+ *
214
+ * @param switchStmt - The switch statement
215
+ * @returns The grouped case statements
216
+ */
217
+ static consecutiveCases(switchStmt) {
218
+ let caseGroups = [];
219
+ let currentList = [];
220
+ for (const caseStmt of switchStmt.cases) {
221
+ currentList.push(caseStmt);
222
+ if (caseStmt.instructions.length !== 0) { // Has no consecutive case
223
+ caseGroups.push(currentList);
224
+ currentList = [];
225
+ }
226
+ }
227
+ // Ensure the block containing the default case is placed at the last position
228
+ return this.organizeCaseGroups(caseGroups);
229
+ }
230
+ /**
231
+ * Organizes case groups such that the group with default case is placed last.
232
+ *
233
+ * @param caseGroups - The groups of case statements
234
+ * @returns The organized case groups
235
+ */
236
+ static organizeCaseGroups(caseGroups) {
237
+ const nonDefaultGroups = caseGroups.filter(block => !block.some(caseStmt => caseStmt.isDefault));
238
+ const defaultBlock = caseGroups.find(block => block.some(caseStmt => caseStmt.isDefault));
239
+ if (defaultBlock) {
240
+ nonDefaultGroups.push(defaultBlock);
241
+ }
242
+ return nonDefaultGroups;
243
+ }
244
+ }
245
+ //# sourceMappingURL=MISRA.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MISRA.js","sourceRoot":"","sources":["../src/MISRA.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,EAAE,IAAI,EAAuD,MAAM,qCAAqC,CAAC;AACjI,OAAO,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AI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;QAC1F,IAAI,YAAY,EAAE,CAAC;YACf,gBAAgB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACxC,CAAC;QACD,OAAO,gBAAgB,CAAC;IAC5B,CAAC;CACJ"}
@@ -0,0 +1,21 @@
1
+ import { Joinpoint } from "@specs-feup/clava/api/Joinpoints.js";
2
+ import { MISRAError } from "./MISRA.js";
3
+ /**
4
+ * Tracks MISRA errors and warnings during the analysis and/or transformation of the code.
5
+ * Also generated unique variable and function names.
6
+ */
7
+ export default class MISRAContext {
8
+ #private;
9
+ get errors(): MISRAError[];
10
+ get warnings(): MISRAError[];
11
+ get config(): Map<string, any> | undefined;
12
+ set config(configFilePath: string);
13
+ generateVarName(): string;
14
+ generateFuncName(): string;
15
+ generateHeaderFilename(): string;
16
+ addMISRAError(ruleID: string, $jp: Joinpoint, message: string): void;
17
+ addMISRAWarning(ruleID: string, $jp: Joinpoint, message: string): void;
18
+ printErrors(): void;
19
+ printWarnings(): void;
20
+ }
21
+ //# sourceMappingURL=MISRAContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MISRAContext.d.ts","sourceRoot":"","sources":["../src/MISRAContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGxC;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,YAAY;;IAuB7B,IAAI,MAAM,IAAI,UAAU,EAAE,CAEzB;IAED,IAAI,QAAQ,IAAI,UAAU,EAAE,CAE3B;IAED,IAAI,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CAEzC;IAED,IAAI,MAAM,CAAC,cAAc,EAAE,MAAM,EAQhC;IAED,eAAe;IAIf,gBAAgB;IAIhB,sBAAsB;IAItB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM;IAQ7D,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM;IAQ/D,WAAW;IAKX,aAAa;CAIhB"}