@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
@@ -1,253 +0,0 @@
1
- import MISRAReporter from "../MISRAReporter.js";
2
- import S10_EssentialTypePass from "../passes/S10_EssentialTypePass.js";
3
- import Query from "@specs-feup/lara/api/weaver/Query.js";
4
- import { FileJp, Joinpoint } from "@specs-feup/clava/api/Joinpoints.js";
5
- import { expectNumberOfErrors, registerSourceCode, TestFile } from "./utils.js";
6
-
7
- const passingOperands = `void goodOperands() {
8
- bool bla, blb;
9
- unsigned u8a, u8b, u16b;
10
- char cha, chb;
11
- enum ena {R,G,B} ena;
12
- enum {K1=5};
13
- int a1,s8a,s16b,s8b;
14
- float f32a, f32b;
15
-
16
- bla && blb;
17
- bla ? u8a : u8b;
18
- cha - chb;
19
- cha > chb;
20
- ena > a1;
21
- K1 * s8a; /* Compliant as K1 from anonymous enum */
22
- s8a + s16b;
23
- -( s8a ) * s8b;
24
- s8a > 0;
25
- --s16b;
26
- u8a + u16b;
27
- u8a & 2U;
28
- u8a > 0U;
29
- u8a << 2U;
30
- u8a << 1; /* Compliant by exception */
31
- f32a + f32b;
32
- f32a > 0.0;
33
-
34
- '0' + u8a; /* Convert u8a to digit */
35
- s8a + '0'; /* Convert s8a to digit */
36
- cha - '0'; /* Convert cha to ordinal */
37
- '0' - s8a; /* Convert -s8a to digit */
38
- }`;
39
-
40
- const failingOperands = `void badOperands() {
41
- char cha, chb;
42
- enum ena {R,G,B} ena;
43
- bool bla, blb;
44
- int a1,a2,s8a;
45
- unsigned u8a;
46
- float f32a;
47
-
48
- cha && bla ; /* Rationale 2 - char type used as a Boolean value */
49
- ena ? a1 : a2 ; /* Rationale 2 - enum type used as a Boolean value */
50
- s8a && bla ; /* Rationale 2 - signed type used as a Boolean value */
51
- u8a ? a1 : a2 ; /* Rationale 2 - unsigned type used as a Boolean value */
52
- f32a && bla ; /* Rationale 2 - floating type used as a Boolean value */
53
- bla * blb ; /* Rationale 3 - Boolean used as a numeric value */
54
- bla > blb ; /* Rationale 3 - Boolean used as a numeric value */
55
- cha & chb ; /* Rationale 4 - char type used as a numeric value */
56
- cha << 1 ; /* Rationale 4 - char type used as a numeric value */
57
- ena * a1 ; /* Rationale 5 - enum type used in arithmetic operation */
58
- s8a & 2 ; /* Rationale 6 - bitwise operation on signed type */
59
- 50 << 3U ; /* Rationale 6 - shift operation on signed type */
60
- u8a << s8a ; /* Rationale 7 - shift magnitude uses signed type */
61
- u8a << -1 ; /* Rationale 7 - shift magnitude uses signed type */
62
- -u8a ; /* Rationale 8 - unary minus on unsigned type */
63
-
64
- int s16a;
65
- s16a - 'a';
66
- '0' + f32a;
67
- cha + ':';
68
- cha - ena;
69
- }`;
70
-
71
- const operandFiles: TestFile[] = [
72
- {name: "badoperands.cpp", code: failingOperands},
73
- {name: "goodoperands.cpp", code: passingOperands},
74
- ];
75
-
76
- const passingAssignments = `void use_uint16(unsigned int a) {
77
- return;
78
- }
79
-
80
- void goodAssignments() {
81
- unsigned char u8b, u8c, u8d;
82
- enum ena {R,G,B} ena;
83
- enum {A1, K1};
84
- int s8a;
85
- char cha;
86
-
87
- unsigned int u8a = 0; /* By exception */
88
- bool flag = ( bool ) 0;
89
- bool set = true; /* true is essentially Boolean */
90
- bool get = ( u8b > u8c );
91
- s8a = K1; /* Constant value fits */
92
- u8a = 2; /* By exception */
93
- //u8a = 2 * 24; /* By exception */ <-- DO THIS WHEN ISINTEGERCONSTANTEXPR IS AVAILABLE
94
- u8a = ( unsigned int ) s8a; /* Cast gives same essential type */
95
-
96
- unsigned int u32a;
97
- unsigned char u16a, u16b;
98
- u32a = u16a; /* Assignment to a wider essential type */
99
- u32a = 2U + 125U; /* Assignment to a wider essential type */
100
- use_uint16 ( u8a ); /* Assignment to a wider essential type */
101
- use_uint16 ( u8a + u16b ); /* Assignment to same essential type */
102
- }`;
103
-
104
- const failingAssignments = `void use_uint32(unsigned int a) {
105
- return;
106
- }
107
-
108
- void use_uint16(unsigned short a) {
109
- return;
110
- }
111
-
112
- unsigned char foo1 ( unsigned int x )
113
- {
114
- return x; /* uint16_t to uint8_t */
115
- }
116
-
117
- void badAssignments() {
118
- char cha;
119
- unsigned u8b, u8c;
120
- int s32a;
121
- short u16a;
122
- long u32a;
123
-
124
- unsigned u8a = 1.0f; /* unsigned and floating */
125
- bool bla = 0; /* boolean and signed */
126
- cha = 7; /* character and signed */
127
- u8a = 'a'; /* unsigned and character */
128
- u8b = 1 - 2; /* unsigned and signed */
129
- //u8c += 'a'; /* u8c = u8c + 'a' assigns character to unsigned */
130
- use_uint32 ( s32a ); /* signed and unsigned */
131
- //s8a = K2; /* Constant value does not fit */
132
- u16a = u32a; /* uint32_t to uint16_t */
133
- use_uint16 ( u32a ); /* uint32_t to uint16_t */
134
- }`;
135
-
136
- const assignmentFiles: TestFile[] = [
137
- {name: "badassignments.cpp", code: failingAssignments},
138
- {name: "goodassignments.cpp", code: passingAssignments}
139
- ];
140
-
141
- const failingCasts = `void badCasts() {
142
- enum enuma {R,G,B} ena;
143
- enum enumc {C,M,Y} enc;
144
-
145
- //( bool ) false; /* Compliant - 'false' is essentially Boolean */
146
- //( int ) 3U; /* Compliant */
147
- //( bool ) 0; /* Compliant - by exception */
148
- ( bool ) 3U; /* Non-compliant */
149
- //( int ) ena; /* Compliant */
150
- ( enum enuma ) 3; /* Non-compliant */
151
- //( char ) enc; /* Compliant */
152
- }`;
153
-
154
- const passingCasts = `void goodCasts() {
155
- enum enuma {R,G,B} ena;
156
- enum enumc {C,M,Y} enc;
157
-
158
- ( bool ) false; /* Compliant - 'false' is essentially Boolean */
159
- ( int ) 3U; /* Compliant */
160
- ( bool ) 0; /* Compliant - by exception */
161
- //( bool ) 3U; /* Non-compliant */
162
- ( int ) ena; /* Compliant */
163
- //( enum enuma ) 3; /* Non-compliant */
164
- ( char ) enc; /* Compliant */
165
- }`;
166
-
167
- const castFiles: TestFile[] = [
168
- {name: "goodcasts.cpp", code: passingCasts},
169
- {name: "badcasts.cpp", code: failingCasts}
170
- ];
171
-
172
- const passingComposites = `void goodComposites() {
173
- unsigned short u16a,u16b,u16c;
174
- unsigned long u32a,u32b;
175
- signed long s32a;
176
-
177
- u16c = u16a + u16b; /* Same essential type */
178
- u32a = ( unsigned long ) u16a + u16b; /* Cast causes addition in uint32_t */
179
-
180
- ( unsigned short ) ( u32a + u32b ); /* Compliant */
181
- ( unsigned long ) s32a; /* Compliant - s32a is not composite */
182
- }`;
183
-
184
- const failingComposites = `void badComposites() {
185
- unsigned short u16a,u16b,u16c;
186
- unsigned long u32a,u32b;
187
- signed long s32a,s32b;
188
-
189
- u32a = u16a + u16b; /* Implicit conversion on assignment */
190
- ( unsigned short ) ( s32a + s32b );
191
- //( unsigned long ) ( u16a + u16b ); WIDTH PROBLEMS
192
- }`;
193
-
194
- const compositeFiles: TestFile[] = [
195
- {name: "goodcomposites.cpp", code: passingComposites},
196
- {name: "badcomposites.cpp", code: failingComposites}
197
- ]
198
-
199
- describe("Essential type model: operands", () => {
200
- const reporter = new MISRAReporter();
201
- const pass = new S10_EssentialTypePass(true, [1, 2]);
202
- registerSourceCode(operandFiles);
203
-
204
- it("should pass", () => {
205
- expectNumberOfErrors(reporter, pass, 0, Query.search(FileJp, {name: "goodoperands.cpp"}).first() as Joinpoint);
206
- });
207
-
208
- it("should fail", () => {
209
- expectNumberOfErrors(reporter, pass, 24, Query.search(FileJp, {name: "badoperands.cpp"}).first() as Joinpoint);
210
- });
211
- });
212
-
213
- describe("Essential type model: assignments", () => {
214
- const reporter = new MISRAReporter();
215
- const pass = new S10_EssentialTypePass(true, [3]);
216
- registerSourceCode(assignmentFiles);
217
-
218
- it("should pass", () => {
219
- expectNumberOfErrors(reporter, pass, 0, Query.search(FileJp, {name: "goodassignments.cpp"}).first() as Joinpoint);
220
- });
221
-
222
- it("should fail", () => { //SHOULD BE 9 BUT DOESNT WORK FOR RETURN STMTS
223
- expectNumberOfErrors(reporter, pass, 8, Query.search(FileJp, {name: "badassignments.cpp"}).first() as Joinpoint);
224
- });
225
- });
226
-
227
- describe("Essential type model: casts", () => {
228
- const reporter = new MISRAReporter();
229
- const pass = new S10_EssentialTypePass(true, [5]);
230
- registerSourceCode(castFiles);
231
-
232
- it("should pass", () => {
233
- expectNumberOfErrors(reporter, pass, 0, Query.search(FileJp, {name: "goodcasts.cpp"}).first() as Joinpoint);
234
- });
235
-
236
- it("should fail", () => { //SHOULD BE 9 BUT DOESNT WORK FOR RETURN STMTS
237
- expectNumberOfErrors(reporter, pass, 2, Query.search(FileJp, {name: "badcasts.cpp"}).first() as Joinpoint);
238
- });
239
- });
240
-
241
- describe("Essential type model: composite expressions", () => {
242
- const reporter = new MISRAReporter();
243
- const pass = new S10_EssentialTypePass(true, [6,8]);
244
- registerSourceCode(compositeFiles);
245
-
246
- it("should pass", () => {
247
- expectNumberOfErrors(reporter, pass, 0, Query.search(FileJp, {name: "goodcomposites.cpp"}).first() as Joinpoint);
248
- });
249
-
250
- it("should fail", () => { //SHOULD BE 9 BUT DOESNT WORK FOR RETURN STMTS
251
- expectNumberOfErrors(reporter, pass, 2, Query.search(FileJp, {name: "badcomposites.cpp"}).first() as Joinpoint);
252
- });
253
- });
@@ -1,43 +0,0 @@
1
- import MISRAReporter from "../MISRAReporter.js";
2
- import S12_ExpressionPass from "../passes/S12_ExpressionPass.js";
3
- import Query from "@specs-feup/lara/api/weaver/Query.js";
4
- import { FileJp, Joinpoint } from "@specs-feup/clava/api/Joinpoints.js";
5
- import { expectNumberOfErrors, registerSourceCode, TestFile } from "./utils.js";
6
-
7
- const passingCode = `int main(int argc, char *argv[]) {
8
- int x, y, z;
9
- x = 2;
10
- y = 3;
11
-
12
- x = x + (y * z);
13
-
14
- return 0;
15
- }`;
16
-
17
- const failingCode = `int test(int argc, char *argv[]) {
18
- int x, y, z;
19
- x = 2, y = 3;
20
-
21
- x = x + y * z;
22
-
23
- return 0;
24
- }`;
25
-
26
- const files: TestFile[] = [
27
- {name: "bad.cpp", code: failingCode},
28
- {name: "good.cpp", code: passingCode}
29
- ]
30
-
31
- describe("Expressions", () => {
32
- const reporter = new MISRAReporter();
33
- const pass = new S12_ExpressionPass(true, [1, 3]);
34
- registerSourceCode(files);
35
-
36
- it("should pass", () => {
37
- expectNumberOfErrors(reporter, pass, 0, Query.search(FileJp, {name: "good.cpp"}).first() as Joinpoint);
38
- });
39
-
40
- it("should fail", () => {
41
- expectNumberOfErrors(reporter, pass, 2, Query.search(FileJp, {name: "bad.cpp"}).first() as Joinpoint);
42
- });
43
- });
@@ -1,77 +0,0 @@
1
- import MISRAReporter from "../MISRAReporter.js";
2
- import S13_SideEffectPass from "../passes/S13_SideEffectPass.js";
3
- import Query from "@specs-feup/lara/api/weaver/Query.js";
4
- import { FileJp, Joinpoint } from "@specs-feup/clava/api/Joinpoints.js";
5
- import { expectNumberOfErrors, registerSourceCode, TestFile } from "./utils.js";
6
-
7
- const passingCode = `int v1;
8
- void f1 ( void )
9
- {
10
- int a[ 2 ] = { v1, 0 };
11
- }
12
- int x = 0u;
13
- extern void p ( int a[ 2 ] );
14
- void h1 ( void )
15
- {
16
- /* Non-compliant - two side effects */
17
- p ( ( int[ 2 ] ) { x, x } );
18
- }
19
-
20
- void foo1() {
21
- unsigned u8a, u8b;
22
- int a[4], x, y, s;
23
- u8a = ( 1u == 1u ) ? 0u : u8b;
24
- u8b++;
25
- s = sizeof ( 5 );
26
- if ( ( x == 0u ) || ( v1 == 1u ) )
27
- {
28
- }
29
- }`;
30
-
31
- const failingCode = `volatile int v1;
32
- void f ( void )
33
- {
34
- /* Non-compliant - volatile access is persistent side effect */
35
- int a[ 2 ] = { v1, 0 };
36
- }
37
- int x = 0u;
38
- extern void p ( int a[ 2 ] );
39
- void h ( void )
40
- {
41
- /* Non-compliant - two side effects */
42
- p ( ( int[ 2 ] ) { x++, x++ } );
43
- }
44
-
45
- int bar() {
46
- return 5;
47
- }
48
-
49
- void foo() {
50
- unsigned u8a, u8b;
51
- int a[4], x, y, s;
52
- u8a = ( 1u == 1u ) ? 0u : u8b++;
53
- s = sizeof ( bar() ); /* Non-compliant */
54
- a[ x ] = a[ x = y ];
55
- if ( ( x == 0u ) || ( v1 == 1u ) )
56
- {
57
- }
58
- }`;
59
-
60
- const files: TestFile[] = [
61
- {name: "bad.cpp", code: failingCode},
62
- {name: "good.cpp", code: passingCode}
63
- ]
64
-
65
- describe("Expressions", () => {
66
- const reporter = new MISRAReporter();
67
- const pass = new S13_SideEffectPass(true, [1, 3, 4, 5, 6]);
68
- registerSourceCode(files);
69
-
70
- it("should pass", () => {
71
- expectNumberOfErrors(reporter, pass, 0, Query.search(FileJp, {name: "good.cpp"}).first() as Joinpoint);
72
- });
73
-
74
- it("should fail", () => {
75
- expectNumberOfErrors(reporter, pass, 8, Query.search(FileJp, {name: "bad.cpp"}).first() as Joinpoint);
76
- });
77
- });
@@ -1,144 +0,0 @@
1
- import MISRAReporter from "../MISRAReporter.js";
2
- import S15_ControlFlowPass from "../passes/S15_ControlFlowPass.js";
3
- import Query from "@specs-feup/lara/api/weaver/Query.js";
4
- import { FileJp, Joinpoint } from "@specs-feup/clava/api/Joinpoints.js";
5
- import { expectNumberOfErrors, registerSourceCode, TestFile } from "./utils.js";
6
-
7
- const passingCode = `void f ( void )
8
- {
9
- int j = 0;
10
- ++j;
11
- if ( 10 == j )
12
- {
13
- goto L2; /* Compliant */
14
- }
15
- L2 :
16
- ++j;
17
- }
18
-
19
- void f1 ( int a )
20
- {
21
- if ( a <= 0 )
22
- {
23
- }
24
- goto L1; /* Compliant */
25
- if ( a == 0 )
26
- {
27
- goto L1; /* Compliant */
28
- }
29
- L1:
30
- if ( a > 0 )
31
- {
32
- L2:
33
- ;
34
- }
35
- }
36
-
37
- void f2() {
38
- int x,y,z;
39
- while ( x != 0u )
40
- {
41
- x = 5;
42
- if ( x == 1u )
43
- {
44
- break;
45
- }
46
- while ( y != 0u )
47
- {
48
- y = 6;
49
- if ( y == 1u )
50
- {
51
- goto L1;
52
- }
53
- }
54
- L1:
55
- z = x + y;
56
- }
57
- }
58
-
59
- int main(int argc, char *argv[]) {
60
-
61
-
62
- return 0;
63
- }`;
64
-
65
- const failingCode = `void g ( void )
66
- {
67
- int j = 0;
68
- L1:
69
- ++j;
70
- if ( 10 == j )
71
- {
72
- goto L2; /* Compliant */
73
- }
74
- goto L1; /* Non-compliant */
75
- L2 :
76
- ++j;
77
- }
78
-
79
- void g1 ( int a )
80
- {
81
- if ( a <= 0 )
82
- {
83
- goto L2; /* Non-compliant */
84
- }
85
- goto L1; /* Compliant */
86
- if ( a == 0 )
87
- {
88
- goto L1; /* Compliant */
89
- }
90
- goto L2; /* Non-compliant */
91
- L1:
92
- if ( a > 0 )
93
- {
94
- L2:
95
- ;
96
- }
97
- }
98
-
99
- void g2() {
100
- int x,y,z;
101
- while ( x != 0u )
102
- {
103
- x = 5;
104
- if ( x == 1u )
105
- {
106
- break;
107
- }
108
- while ( y != 0u )
109
- {
110
- y = 6;
111
- if ( y == 1u )
112
- {
113
- goto L1;
114
- }
115
- }
116
- }
117
- L1:
118
- z = x + y;
119
- }
120
-
121
- int test(int argc, char *argv[]) {
122
-
123
-
124
- return 0;
125
- }`;
126
-
127
- const files: TestFile[] = [
128
- {name: "bad.cpp", code: failingCode},
129
- {name: "good.cpp", code: passingCode}
130
- ]
131
-
132
- describe("Expressions", () => {
133
- const reporter = new MISRAReporter();
134
- const pass = new S15_ControlFlowPass(true, [1, 2, 3, 4]);
135
- registerSourceCode(files);
136
-
137
- it("should pass", () => {
138
- expectNumberOfErrors(reporter, pass, 4, Query.search(FileJp, {name: "good.cpp"}).first() as Joinpoint);
139
- });
140
-
141
- it("should fail", () => {
142
- expectNumberOfErrors(reporter, pass, 11, Query.search(FileJp, {name: "bad.cpp"}).first() as Joinpoint);
143
- });
144
- });
@@ -1,164 +0,0 @@
1
- import MISRAReporter from "../MISRAReporter.js";
2
- import S16_SwitchStatementPass from "../passes/S16_SwitchStatementPass.js";
3
- import Query from "@specs-feup/lara/api/weaver/Query.js";
4
- import { FileJp, Joinpoint } from "@specs-feup/clava/api/Joinpoints.js";
5
- import { expectNumberOfErrors, registerSourceCode, TestFile } from "./utils.js";
6
-
7
- const passingMisc = `void f ( void )
8
- {
9
- int x;
10
- bool flag;
11
- switch ( x )
12
- {
13
- case 1:
14
- case 2:
15
- x = 1;
16
- break;
17
- default:
18
- break;
19
- }
20
- switch (x) {
21
- case 1:
22
- case 2:
23
- default:
24
- break;
25
- }
26
- }`;
27
-
28
- const failingMisc = `void f ( void )
29
- {
30
- int x;
31
- bool flag;
32
- switch ( x )
33
- {
34
- case 1: /* Compliant */
35
- if ( flag )
36
- {
37
- case 2: /* Non-compliant */
38
- x = 1;
39
- }
40
- break;
41
- default:
42
- break;
43
- case 3:
44
- break;
45
- }
46
- switch (x) {
47
- case 1:
48
- case 2:
49
- break;
50
- }
51
- }`;
52
-
53
- const passingFormat = `void f ( void )
54
- {
55
- int x, y, z;
56
- int flag;
57
- switch (x) {
58
- case 1:
59
- z = y+x;
60
- break;
61
- case 2:
62
- z = y-x;
63
- break;
64
- default:
65
- z = 4;
66
- break;
67
- }
68
- switch (flag) {
69
- case 0:
70
- x = 2;
71
- break;
72
- case 1:
73
- x = 4;
74
- break;
75
- case 2:
76
- x = 6;
77
- break;
78
- }
79
- switch (z) {
80
- case 1:
81
- y = 0;
82
- break;
83
- case 6:
84
- case 42:
85
- y = 1;
86
- break;
87
- case 9139:
88
- default:
89
- y = 2;
90
- break;
91
- }
92
- }`;
93
-
94
- const failingFormat = `void f ( void )
95
- {
96
- int x, y, z;
97
- bool flag;
98
- switch (x) {
99
- case 1:
100
- z = y+x;
101
- case 2:
102
- z = y-x;
103
- break;
104
- default:
105
- z = 4;
106
- }
107
- switch (flag) {
108
- case 0:
109
- x = 2;
110
- break;
111
- case 1:
112
- x = 4;
113
- break;
114
- }
115
- switch (z) {
116
- case 1:
117
- case 6:
118
- case 42:
119
- y = 1;
120
- break;
121
- case 9139:
122
- default:
123
- y = 2;
124
- break;
125
- }
126
- }`;
127
-
128
- const miscFiles: TestFile[] = [
129
- {name: "badmmisc.cpp", code: failingMisc},
130
- {name: "goodmisc.cpp", code: passingMisc}
131
- ];
132
-
133
- const formatFiles: TestFile[] = [
134
- {name: "badformat.cpp", code: failingFormat},
135
- {name: "goodformat.cpp", code: passingFormat}
136
- ];
137
-
138
- describe("Switch statements: misc", () => {
139
- const reporter = new MISRAReporter();
140
- const pass = new S16_SwitchStatementPass(true, [2, 4, 5]);
141
- registerSourceCode(miscFiles);
142
-
143
- it("should pass", () => {
144
- expectNumberOfErrors(reporter, pass, 0, Query.search(FileJp, {name: "goodmisc.cpp"}).first() as Joinpoint);
145
- });
146
-
147
- it("should fail", () => {
148
- expectNumberOfErrors(reporter, pass, 3, Query.search(FileJp, {name: "badmisc.cpp"}).first() as Joinpoint);
149
- });
150
- });
151
-
152
- describe("Switch statements: format", () => {
153
- const reporter = new MISRAReporter();
154
- const pass = new S16_SwitchStatementPass(true, [1, 6, 7]);
155
- registerSourceCode(formatFiles);
156
-
157
- it("should pass", () => {
158
- expectNumberOfErrors(reporter, pass, 0, Query.search(FileJp, {name: "goodformat.cpp"}).first() as Joinpoint);
159
- });
160
-
161
- it("should fail", () => {
162
- expectNumberOfErrors(reporter, pass, 5, Query.search(FileJp, {name: "badformat.cpp"}).first() as Joinpoint);
163
- });
164
- });