@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
@@ -0,0 +1,221 @@
1
+ import Query from "@specs-feup/lara/api/weaver/Query.js";
2
+ import { Comment, Type, Case, Joinpoint, ArrayType, TypedefDecl, DeclStmt, TypedefNameDecl, StorageClass, FunctionJp, Vardecl, FileJp, RecordJp, EnumDecl, PointerType, Switch, BuiltinType, BinaryOp, Break, Scope, Statement, Expression, WrapperStmt, ElaboratedType, TagType, Param, Varref } from "@specs-feup/clava/api/Joinpoints.js";
3
+
4
+ /**
5
+ * Checks if the comment is an inline comment
6
+ * @param $comment - The comment to check
7
+ * @returns Returns true if it's an inline comment, otherwise returns false
8
+ */
9
+ export function isInlineComment($comment: Comment): boolean {
10
+ return $comment.astName === "InlineComment";
11
+ }
12
+
13
+ /**
14
+ * Retrieves all comments associated with a given joinpoint
15
+ * @param $jp - The joinpoint to retrieve comments from
16
+ * @returns Array of comments
17
+ */
18
+ export function getComments($jp: Joinpoint): Comment[] {
19
+ return $jp instanceof Comment ? [$jp] : $jp.inlineComments;
20
+ }
21
+
22
+ /**
23
+ * Checks if a given join point is a comment statement
24
+ *
25
+ * @param $jp The join point to check
26
+ * @returns Returns true if the given join point is a comment statement, otherwise false
27
+ */
28
+ export function isCommentStmt($jp: Joinpoint): boolean {
29
+ return $jp instanceof WrapperStmt && $jp.kind === "comment";
30
+ }
31
+
32
+ export function getParamReferences($param: Param, $startingPoint: Joinpoint): Varref[] {
33
+ return Query.searchFrom($startingPoint, Varref, (ref) => {
34
+ try {
35
+ return ref.decl && ref.decl.astId === $param.astId;
36
+ } catch (error) {
37
+ return false;
38
+ }
39
+ }).get();
40
+ }
41
+
42
+ /**
43
+ * Checks if a storage class has external linkage
44
+ * @param $class - The storage class to check
45
+ * @returns Returns true if the class has external linkage, otherwise returns false
46
+ */
47
+ export function hasExternalLinkage($class: StorageClass) {
48
+ return $class !== StorageClass.STATIC && $class !== StorageClass.EXTERN;
49
+ }
50
+
51
+ /**
52
+ * Retrieves all variables and functions that can be externed from the files, i.e.,
53
+ * elements with storage classes that are not `STATIC` or `EXTERN`
54
+ * @returns Array of functions and variables that can be externed
55
+ */
56
+ export function getExternals(): (FunctionJp | Vardecl)[] {
57
+ let result: (FunctionJp | Vardecl)[] = [];
58
+
59
+ for (const file of Query.search(FileJp).get()) {
60
+ for(const child of file.children) {
61
+ if((child instanceof Vardecl || child instanceof FunctionJp) && hasExternalLinkage(child.storageClass)) {
62
+ result.push(child);
63
+ }
64
+ }
65
+ }
66
+ return result;
67
+ }
68
+
69
+ /**
70
+ * Checks if the provided node has a defined type
71
+ * @param $jp The joinpoint to check its type
72
+ * @returns true if the joinpoint has a defined type, otherwise false
73
+ */
74
+ export function hasDefinedType($jp: Joinpoint): boolean {
75
+ return $jp.hasType && $jp.type !== null || $jp.type !== undefined;
76
+ }
77
+
78
+ /**
79
+ * Retrieves the base type of the provided joinpoint.
80
+ * @param $jp The joinpoint to retrieve its type
81
+ * @returns The base type of the joinpoint, or undefined if the type is not defined
82
+ */
83
+ export function getBaseType($jp: Joinpoint): Type | undefined {
84
+ if (!hasDefinedType($jp)) return undefined;
85
+
86
+ let jpType: Type;
87
+ if ($jp.type instanceof PointerType) {
88
+ jpType = $jp.type.pointee;
89
+ while (jpType instanceof PointerType) {
90
+ jpType = jpType.pointee;
91
+ }
92
+ } else if ($jp.type instanceof ArrayType) {
93
+ jpType = $jp.type.elementType;
94
+ } else {
95
+ jpType = $jp.type;
96
+ }
97
+ return jpType;
98
+ }
99
+
100
+ /**
101
+ * Retrieves the typedef declaration for the provided joinpoint, if available
102
+ * @param $jp The joinpoint to analyze
103
+ * @returns The typedef declaration if found, or undefined if not
104
+ */
105
+ export function getTypeDecl($jp: Joinpoint): TypedefDecl | undefined {
106
+ if ($jp instanceof DeclStmt && $jp.children.length === 1 && $jp.children[0] instanceof TypedefDecl)
107
+ return $jp.children[0];
108
+
109
+ if ($jp instanceof RecordJp || $jp instanceof EnumDecl) {
110
+ const typeDecls = Query.searchFrom($jp, TypedefDecl).get();
111
+ if (typeDecls.length === 1)
112
+ return typeDecls[0];
113
+ }
114
+ }
115
+
116
+ /**
117
+ * Checks if the provided joinpoint declares a type (typedef)
118
+ * @param $jp The joinpoint to check
119
+ * @returns Returns true if the joinpoint declares a typedef, otherwise false
120
+ */
121
+ export function hasTypeDecl($jp: Joinpoint): boolean {
122
+ return getTypeDecl($jp) !== undefined;
123
+ }
124
+
125
+ /**
126
+ * Retrieves all joinpoints with a defined type
127
+ * @returns Array of joinpoints with a defined type
128
+ */
129
+ export function getTypedJps(startingPoint?: Joinpoint): Joinpoint[] {
130
+ if (startingPoint) {
131
+ return Query.searchFrom(startingPoint, Joinpoint).get().filter(jp => jp.hasType && jp.type !== null && jp.type !== undefined)
132
+ }
133
+ return Query.search(Joinpoint).get().filter(jp =>
134
+ jp.hasType &&
135
+ jp.type !== null &&
136
+ jp.type !== undefined);
137
+ }
138
+
139
+ /**
140
+ * Checks if a given joinpoint uses the specified tag declaration
141
+ * @param $jp The joinpoint to analyze
142
+ * @param tag The tag to check against
143
+ * @returns Returns true if the joinpoint uses the given tag, false otherwise
144
+ */
145
+ export function isTagUsed($jp: Joinpoint, tag: RecordJp | EnumDecl): boolean {
146
+ const jpType = getBaseType($jp);
147
+ return jpType instanceof ElaboratedType &&
148
+ jpType.namedType instanceof TagType &&
149
+ jpType.namedType.decl.astId === tag.astId &&
150
+ $jp.astId !== getTypeDecl(tag)?.astId
151
+ }
152
+
153
+ /**
154
+ * Retrieves all joinpoints that use the specified tag declaration
155
+ *
156
+ * @param tag The tag to search for in the joinpoints
157
+ * @returns Array of joinpoints that use the specified tag declaration
158
+ */
159
+ export function getTagUses(tag: RecordJp | EnumDecl): Joinpoint[] {
160
+ return getTypedJps().filter(jp => isTagUsed(jp, tag));
161
+ }
162
+
163
+ /**
164
+ * Retrieves the last statement of the given case
165
+ * @param $jp - The case to retrieve the last statement from
166
+ * @returns The last statement of the case or undefined if there are no statements or it has a consecutive case.
167
+ */
168
+ export function getLastStmtOfCase($jp: Case): Joinpoint | undefined {
169
+ if ($jp.instructions.length === 0) { // Has a consecutive case
170
+ return undefined;
171
+ }
172
+
173
+ let lastStmt: Joinpoint | undefined;
174
+ for (const stmt of $jp.siblingsRight) {
175
+ if (stmt instanceof Case) {
176
+ break;
177
+ }
178
+ lastStmt = stmt;
179
+ }
180
+ return lastStmt;
181
+ }
182
+
183
+ /**
184
+ * Retrieves the number of switch clauses with instructions in the provided switch statement
185
+ * @param $jp - The switch statement to analyze
186
+ * @returns The number of switch clauses with instructions
187
+ */
188
+ export function getNumOfSwitchClauses($jp: Switch): number {
189
+ let firstStatements = []
190
+
191
+ for (const caseLabel of $jp.cases) {
192
+ if (caseLabel.instructions.length === 0) { // Has a consecutive case
193
+ continue;
194
+ }
195
+ firstStatements.push(caseLabel.instructions[0])
196
+ }
197
+ return firstStatements.length;
198
+ }
199
+
200
+ /**
201
+ * Checks if the provided switch statement has a Boolean condition
202
+ * @param switchStmt - The switch statement to check
203
+ * @returns
204
+ * Returns true if the switch statement has a Boolean condition, otherwise false
205
+ */
206
+ export function switchHasBooleanCondition(switchStmt: Switch): boolean {
207
+ return switchStmt.condition instanceof BinaryOp ||
208
+ (hasDefinedType(switchStmt.condition) &&
209
+ switchStmt.condition.type instanceof BuiltinType &&
210
+ switchStmt.condition.type.builtinKind === "Bool"
211
+ );
212
+ }
213
+
214
+ /**
215
+ * Checks if the provided switch statement contains any conditional break
216
+ * @param switchStmt - The switch statement to analyze
217
+ * @returns Returns true if the switch statement contains a conditional break, otherwise false
218
+ */
219
+ export function switchHasConditionalBreak(switchStmt: Switch): boolean {
220
+ return Query.searchFrom(switchStmt, Break, { currentRegion: region => region.astId !== switchStmt.astId, enclosingStmt: jp => jp.astId === switchStmt.astId }).get().length > 0;
221
+ }
package/tsconfig.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
- "include": ["src/**/*.ts"],
3
- "exclude": ["node_modules", "**/*.spec.ts", "**/*.test.ts"],
2
+ "include": ["src/**/*.ts", "src/**/*.json"],
3
+ "exclude": ["node_modules", "**/*.spec.ts", "**/*.test.ts", "src/misra-old"],
4
4
  "compilerOptions": {
5
5
  "outDir": "dist",
6
6
  "target": "ES2022",
@@ -12,7 +12,8 @@
12
12
  "moduleResolution": "NodeNext",
13
13
  "sourceMap": true,
14
14
  "declarationMap": true,
15
- "allowSyntheticDefaultImports": true
15
+ "allowSyntheticDefaultImports": true,
16
+ "resolveJsonModule": true
16
17
  //"esModuleInterop": true
17
18
  }
18
19
  }
package/typedoc.config.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { fileURLToPath } from "url";
2
2
 
3
3
  export default {
4
- extends: [ fileURLToPath(import.meta.resolve("lara-js/typedoc.base.json")) ],
4
+ extends: [ fileURLToPath(import.meta.resolve("@specs-feup/lara/typedoc.base.json")) ],
5
5
  entryPoints: ["src/"],
6
6
  }
@@ -1,3 +0,0 @@
1
- #include <stdio.h>
2
-
3
- void foo() { printf("Hello, world!"); }
package/CxxSources/lib.h DELETED
@@ -1,8 +0,0 @@
1
- #ifndef __LIB_H__
2
- #define __LIB_H__
3
-
4
- #include <stdio.h>
5
-
6
- void foo();
7
-
8
- #endif // __LIB_H__
@@ -1,40 +0,0 @@
1
- void f ( void )
2
- {
3
- int x, y, z;
4
- int flag;
5
- switch (x) {
6
- case 1:
7
- z = y+x;
8
- break;
9
- case 2:
10
- z = y-x;
11
- break;
12
- default:
13
- z = 4;
14
- break;
15
- }
16
- switch (flag) {
17
- case 0:
18
- x = 2;
19
- break;
20
- case 1:
21
- x = 4;
22
- break;
23
- case 2:
24
- x = 6;
25
- break;
26
- }
27
- switch (z) {
28
- case 1:
29
- y = 0;
30
- break;
31
- case 6:
32
- case 42:
33
- y = 1;
34
- break;
35
- case 9139:
36
- default:
37
- y = 2;
38
- break;
39
- }
40
- }
package/TODO.md DELETED
@@ -1 +0,0 @@
1
- section 8 has a rule that hasn't been adapted yet
@@ -1,2 +0,0 @@
1
- ASTConsumer built 1
2
- ASTConsumer destroyed 1
File without changes
package/is_temporary.txt DELETED
File without changes
package/omp.txt DELETED
File without changes
@@ -1,168 +0,0 @@
1
- import { LaraJoinPoint } from "@specs-feup/lara/api/LaraJoinPoint.js";
2
- import MISRAPass from "../MISRAPass.js";
3
- import { PreprocessingReqs } from "../MISRAReporter.js";
4
- import { BinaryOp, Break, BuiltinType, Case, Expression, Joinpoint, Switch } from "@specs-feup/clava/api/Joinpoints.js";
5
- import Fix from "@specs-feup/clava/api/clava/analysis/Fix.js";
6
- import ClavaJoinPoints from "@specs-feup/clava/api/clava/ClavaJoinPoints.js";
7
-
8
- export default class S16_SwitchStatementPass extends MISRAPass {
9
- protected _preprocessingReqs: PreprocessingReqs[] = [];
10
- private _wellFormedSwitch: boolean = false;
11
-
12
- initRuleMapper(): void {
13
- this._ruleMapper = new Map([
14
- [1, this.r16_1_16_3_wellFormedSwitch.bind(this)],
15
- [2, this.r16_2_topLevelSwitchLabels.bind(this)],
16
- [4, this.r16_4_switchHasDefault.bind(this)],
17
- [5, this.r16_5_defaultFirstOrLast.bind(this)],
18
- [6, this.r16_6_noTwoClauses.bind(this)],
19
- [7, this.r16_7_noEssentialBooleanInSwitch.bind(this)]
20
- ]);
21
- }
22
-
23
- matchJoinpoint($jp: LaraJoinPoint): boolean {
24
- return $jp instanceof Switch || $jp instanceof Case;
25
- }
26
-
27
- private r16_1_16_3_wellFormedSwitch($startNode: Joinpoint) {
28
- if (!($startNode instanceof Switch)) return;
29
- this._wellFormedSwitch = true;
30
-
31
- let foundStmt = false;
32
- let first = true;
33
- for (const child of $startNode.children[1].children) {
34
- if (child instanceof Break) {;
35
- foundStmt = false;
36
- }
37
- else if (child instanceof Case) {
38
- first = false;
39
- }
40
- else {
41
- foundStmt = true;
42
- }
43
-
44
- if (foundStmt && child instanceof Case) {
45
- this.logMISRAError(`A break is missing before ${child.code}`);
46
- this._wellFormedSwitch = false;
47
- }
48
- }
49
- if (!($startNode.children[1].lastChild instanceof Break)) {
50
- this.logMISRAError("A break is missing at the end of the switch statement.");
51
- this._wellFormedSwitch = false;
52
- }
53
- }
54
-
55
- private r16_2_topLevelSwitchLabels($startNode: Joinpoint) {
56
- if (!($startNode instanceof Case)) return;
57
-
58
- if (!($startNode.currentRegion instanceof Switch)) {
59
- this.logMISRAError("A switch label can only be used if its enclosing compound statement is the switch statement itself.");
60
- }
61
- }
62
-
63
- private r16_4_switchHasDefault($startNode: Joinpoint) {
64
- if (!($startNode instanceof Switch && !$startNode.hasDefaultCase)) return;
65
-
66
- this.logMISRAError("Switch statement is missing a default case.");
67
- }
68
-
69
-
70
- private r16_5_defaultFirstOrLast($startNode: Joinpoint) {
71
- if (!($startNode instanceof Switch)) return;
72
-
73
- for (let i = 0; i < $startNode.cases.length; i++) {
74
- if ($startNode.cases[i].isDefault && (i == 0 || i == $startNode.cases.length-1)) {
75
- return;
76
- }
77
- else if ($startNode.cases[i].isDefault) {
78
- this.logMISRAError("The default case of a switch statement must be the first or last label.");
79
- return;
80
- }
81
- }
82
- }
83
-
84
- private r16_6_noTwoClauses($startNode: Joinpoint) {
85
- if (!($startNode instanceof Switch)) return;
86
- this.dependsOn(1, $startNode);
87
- if (this._wellFormedSwitch === false) return;
88
-
89
- let clauses = 0;
90
- for (const child of $startNode.children[1].children) {
91
- if (child instanceof Break) {
92
- clauses++;
93
- }
94
- }
95
-
96
- if (clauses <= 2) {
97
- this.logMISRAError("Switch statements should have more than two clauses.", new Fix(
98
- $startNode,
99
- (switchStmt: Joinpoint) => {
100
- const switchJp = switchStmt as Switch;
101
- let firstClauseExpr: Expression | undefined = undefined;
102
- let secondClauseExpr: Expression | undefined = undefined;
103
- let firstClause: Joinpoint[] = [];
104
- let secondClause: Joinpoint[] = [];
105
- let currClauseExpr: Expression | undefined = undefined;
106
- let currClause: Joinpoint[] = [];
107
- let clauseHasDefault: boolean = false;
108
- let filledFirstClause: boolean = false;
109
- const newVar = ClavaJoinPoints.varDecl("switchToIf_" + switchJp.astId, switchJp.condition);
110
- switchJp.insertBefore(newVar.stmt);
111
- for (const child of switchStmt.children[1].children) {
112
- if (child instanceof Case) {
113
- let tempOp: BinaryOp;
114
- if (child.isDefault) {
115
- clauseHasDefault = true;
116
- continue;
117
- }
118
- else if (child.values.length === 1) {
119
- tempOp = ClavaJoinPoints.binaryOp("eq", newVar.varref(), child.values[0]);
120
- }
121
- else {
122
- tempOp = ClavaJoinPoints.binaryOp("l_or", ClavaJoinPoints.binaryOp("ge", newVar.varref(), child.values[0]), ClavaJoinPoints.binaryOp("le", newVar.varref(), child.values[1]));
123
- }
124
- currClauseExpr = currClauseExpr ? ClavaJoinPoints.binaryOp("l_or", currClauseExpr, tempOp) : tempOp;
125
- }
126
- else if (child instanceof Break) {
127
- if (clauseHasDefault) {
128
- secondClause = currClause;
129
- secondClauseExpr = undefined;
130
- }
131
- else if (filledFirstClause) {
132
- secondClause = currClause;
133
- secondClauseExpr = currClauseExpr;
134
- }
135
- else {
136
- firstClause = currClause;
137
- firstClauseExpr = currClauseExpr;
138
- filledFirstClause = true;
139
- }
140
- clauseHasDefault = false;
141
- currClause = [];
142
- currClauseExpr = undefined;
143
- }
144
- else {
145
- currClause.push(child);
146
- }
147
- }
148
-
149
- const elseStmt = secondClauseExpr ? ClavaJoinPoints.ifStmt(secondClauseExpr, ClavaJoinPoints.scope(...secondClause)) : ClavaJoinPoints.scope(...secondClause);
150
- switchJp.replaceWith(ClavaJoinPoints.ifStmt(firstClauseExpr ?? "", ClavaJoinPoints.scope(...firstClause), elseStmt));
151
- }
152
- ));
153
- }
154
- }
155
-
156
- private r16_7_noEssentialBooleanInSwitch($startNode: Joinpoint) { //UNFINISHED, can have transformation
157
- if (!($startNode instanceof Switch)) return;
158
- this.dependsOn(1, $startNode);
159
- if (this._wellFormedSwitch === false) return;
160
-
161
- if ($startNode.condition.type.desugarAll instanceof BuiltinType && $startNode.condition.type.desugarAll.builtinKind === "Bool") {
162
- this.logMISRAError("The controlling expression of a switch statement must not have essentially boolean type.");
163
- }
164
- }
165
-
166
- protected _name: string = "Switch statements";
167
-
168
- }
@@ -1,40 +0,0 @@
1
- import { LaraJoinPoint } from "@specs-feup/lara/api/LaraJoinPoint.js";
2
- import MISRAPass from "../MISRAPass.js";
3
- import { PreprocessingReqs } from "../MISRAReporter.js";
4
- import { Comment, Joinpoint } from "@specs-feup/clava/api/Joinpoints.js";
5
- import Fix from "@specs-feup/clava/api/clava/analysis/Fix.js";
6
-
7
- export default class S3_CommentPass extends MISRAPass {
8
- protected _preprocessingReqs: PreprocessingReqs[] = [];
9
-
10
- initRuleMapper(): void {
11
- this._ruleMapper = new Map([
12
- [3, this.r3_1_fixComments.bind(this)]
13
- ]);
14
- }
15
-
16
- matchJoinpoint($jp: LaraJoinPoint): boolean {
17
- return true;
18
- }
19
-
20
- private static removeCommentSequences(str: string) {
21
- return str.replace(/(\/\/|\/\*)/g, '');
22
- }
23
-
24
- private r3_1_fixComments($startNode: Joinpoint) { //inlines
25
- if ($startNode instanceof Comment && /(\/\/|\/\*)/g.test($startNode.text)) {
26
- this.logMISRAError(`Comment ${$startNode.text} contains invalid character sequences.`, new Fix(
27
- $startNode,
28
- $jp => ($jp as Comment).setText(S3_CommentPass.removeCommentSequences($startNode.text))
29
- ));
30
- }
31
- $startNode.inlineComments.filter(comment => /(\/\/|\/\*)/g.test(comment.text)).forEach(comment => {
32
- this.logMISRAError(`Comment ${comment.text} contains invalid character sequences.`, new Fix(
33
- $startNode,
34
- $jp => ($jp as Comment).setText(S3_CommentPass.removeCommentSequences(comment.text))
35
- ));
36
- });
37
- }
38
-
39
- protected _name: string = "Comments";
40
- }
@@ -1,65 +0,0 @@
1
- import Query from "@specs-feup/lara/api/weaver/Query.js";
2
- import { Call, FileJp, Include, Joinpoint, Program } from "@specs-feup/clava/api/Joinpoints.js";
3
- import MISRAAnalyser from "../MISRAAnalyser.js";
4
-
5
- export default class Section21_StandardLibraries extends MISRAAnalyser {
6
- ruleMapper: Map<number, (jp: FileJp | Program) => void>;
7
-
8
- constructor(rules: number[]) {
9
- super(rules);
10
- this.ruleMapper = new Map([
11
- [3, this.r21_3_noDynamicAllocation.bind(this)],
12
- [4, this.r21_4_noSetjmpUsage.bind(this)],
13
- [5, this.r21_5_noSignalUsage.bind(this)],
14
- [6, this.r21_6_noStandardIO.bind(this)],
15
- [7, this.r21_7_noStringFunctions.bind(this)],
16
- [8, this.r21_8_noSysFunctions.bind(this)],
17
- [9, this.r21_9_noStdAlgos.bind(this)],
18
- [10, this.r21_10_noDateUsage.bind(this)],
19
- [11, this.r21_11_noTgmathUsage.bind(this)],
20
- [12, this.r21_12_noFenvExceptions.bind(this)]
21
- ]);
22
- }
23
-
24
- private r21_3_noDynamicAllocation($startNode: Joinpoint) {
25
- Query.searchFrom($startNode, Call, {name: /(malloc|realloc|calloc|free)/}).get().forEach(call => this.logMISRAError(call, "Use of memory allocation functions provided by <stdlib.h> is not allowed."), this);
26
- }
27
-
28
- private r21_4_noSetjmpUsage($startNode: Joinpoint) {
29
- Query.searchFrom($startNode, Include, {name: "setjmp.h", isAngled: true}).get().forEach(include => this.logMISRAError(include, "Use of <setjmp.h> is not allowed."), this);
30
- }
31
-
32
- private r21_5_noSignalUsage($startNode: Joinpoint) {
33
- Query.searchFrom($startNode, Include, {name: "signal.h", isAngled: true}).get().forEach(include => this.logMISRAError(include, "Use of <setjmp.h> is not allowed."), this);
34
- }
35
-
36
- private r21_6_noStandardIO($startNode: Joinpoint) {
37
- Query.searchFrom($startNode, Include, {name: /(stdio.h|wchar.h)/}).get().forEach(include => this.logMISRAError(include, "Use of the standard library I/O functions provided by <stdio.h> and <wchar.h> is not allowed."), this);
38
- }
39
-
40
- //how to avoid triggering errors for functions with the same name?
41
- private r21_7_noStringFunctions($startNode: Joinpoint) {
42
- Query.searchFrom($startNode, Call, {name: /(atoi|atof|atol|atoll)/}).get().forEach(call => this.logMISRAError(call, `Use of function ${call.signature} is not allowed.`), this);
43
- }
44
-
45
- private r21_8_noSysFunctions($startNode: Joinpoint) {
46
- Query.searchFrom($startNode, Call, {name: /(system|abort|exit|getenv)/}).get().forEach(call => this.logMISRAError(call, `Use of function ${call.signature} is not allowed.`), this);
47
- }
48
-
49
- private r21_9_noStdAlgos($startNode: Joinpoint) {
50
- Query.searchFrom($startNode, Call, {name: /(qsort|bsearch)/}).get().forEach(call => this.logMISRAError(call, `Use of function ${call.signature} is not allowed.`), this);
51
- }
52
-
53
- private r21_10_noDateUsage($startNode: Joinpoint) {
54
- Query.searchFrom($startNode, Include, {name: "time.h", isAngled: true}).get().forEach(include => this.logMISRAError(include, "Use of <time.h> is not allowed."), this);
55
- Query.searchFrom($startNode, Call, {name: "wcsftime"}).get().forEach(call => this.logMISRAError(call, "Identifier 'wcsftime' shall not be used."), this);
56
- }
57
-
58
- private r21_11_noTgmathUsage($startNode: Joinpoint) {
59
- Query.searchFrom($startNode, Include, {name: "tgmath.h", isAngled: true}).get().forEach(include => this.logMISRAError(include, "Use of <tgmath.h> is not allowed."), this);
60
- }
61
-
62
- private r21_12_noFenvExceptions($startNode: Joinpoint) {
63
- Query.searchFrom($startNode, Call, {name : /(feclearexcept|fegetexceptflag|feraiseexcept|fesetexceptflag|fetestexcept)/}).get().forEach(call => this.logMISRAError(call, `Use of function ${call.signature} is not allowed`), this);
64
- }
65
- }