@specs-feup/clava-misra 1.0.2 → 1.0.4

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 (322) hide show
  1. package/.gitignore +8 -0
  2. package/README.md +53 -19
  3. package/dist/MISRA.d.ts +28 -10
  4. package/dist/MISRA.d.ts.map +1 -1
  5. package/dist/MISRA.js +30 -10
  6. package/dist/MISRA.js.map +1 -1
  7. package/dist/MISRAContext.d.ts +65 -11
  8. package/dist/MISRAContext.d.ts.map +1 -1
  9. package/dist/MISRAContext.js +131 -35
  10. package/dist/MISRAContext.js.map +1 -1
  11. package/dist/MISRARule.d.ts +38 -25
  12. package/dist/MISRARule.d.ts.map +1 -1
  13. package/dist/MISRARule.js +40 -18
  14. package/dist/MISRARule.js.map +1 -1
  15. package/dist/MISRATool.d.ts +46 -5
  16. package/dist/MISRATool.d.ts.map +1 -1
  17. package/dist/MISRATool.js +118 -45
  18. package/dist/MISRATool.js.map +1 -1
  19. package/dist/StandardGuideline.d.ts +22 -0
  20. package/dist/StandardGuideline.d.ts.map +1 -0
  21. package/dist/StandardGuideline.js +12 -0
  22. package/dist/StandardGuideline.js.map +1 -0
  23. package/dist/ast-visitor/Context.d.ts +11 -0
  24. package/dist/ast-visitor/Context.d.ts.map +1 -0
  25. package/dist/ast-visitor/Context.js +15 -0
  26. package/dist/ast-visitor/Context.js.map +1 -0
  27. package/dist/ast-visitor/Visit.d.ts +23 -0
  28. package/dist/ast-visitor/Visit.d.ts.map +1 -0
  29. package/dist/ast-visitor/Visit.js +18 -0
  30. package/dist/ast-visitor/Visit.js.map +1 -0
  31. package/dist/ast-visitor/VisitWithContext.d.ts +32 -0
  32. package/dist/ast-visitor/VisitWithContext.d.ts.map +1 -0
  33. package/dist/ast-visitor/VisitWithContext.js +26 -0
  34. package/dist/ast-visitor/VisitWithContext.js.map +1 -0
  35. package/dist/main.js +1 -2
  36. package/dist/main.js.map +1 -1
  37. package/dist/rules/Section13_SideEffects/Rule_13_6_SafeSizeOfOperand.d.ts +27 -0
  38. package/dist/rules/Section13_SideEffects/Rule_13_6_SafeSizeOfOperand.d.ts.map +1 -0
  39. package/dist/rules/Section13_SideEffects/Rule_13_6_SafeSizeOfOperand.js +98 -0
  40. package/dist/rules/Section13_SideEffects/Rule_13_6_SafeSizeOfOperand.js.map +1 -0
  41. package/dist/rules/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.d.ts +45 -6
  42. package/dist/rules/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.d.ts.map +1 -1
  43. package/dist/rules/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.js +91 -8
  44. package/dist/rules/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.js.map +1 -1
  45. package/dist/rules/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.d.ts +15 -5
  46. package/dist/rules/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.d.ts.map +1 -1
  47. package/dist/rules/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.js +20 -6
  48. package/dist/rules/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.js.map +1 -1
  49. package/dist/rules/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.d.ts +11 -5
  50. package/dist/rules/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.d.ts.map +1 -1
  51. package/dist/rules/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.js +13 -10
  52. package/dist/rules/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.js.map +1 -1
  53. package/dist/rules/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.d.ts +11 -6
  54. package/dist/rules/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.d.ts.map +1 -1
  55. package/dist/rules/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.js +19 -11
  56. package/dist/rules/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.js.map +1 -1
  57. package/dist/rules/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.d.ts +15 -5
  58. package/dist/rules/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.d.ts.map +1 -1
  59. package/dist/rules/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.js +24 -10
  60. package/dist/rules/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.js.map +1 -1
  61. package/dist/rules/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.d.ts +22 -6
  62. package/dist/rules/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.d.ts.map +1 -1
  63. package/dist/rules/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.js +37 -10
  64. package/dist/rules/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.js.map +1 -1
  65. package/dist/rules/Section17_Functions/Rule_17_3_ImplicitFunction.d.ts +66 -0
  66. package/dist/rules/Section17_Functions/Rule_17_3_ImplicitFunction.d.ts.map +1 -0
  67. package/dist/rules/Section17_Functions/Rule_17_3_ImplicitFunction.js +209 -0
  68. package/dist/rules/Section17_Functions/Rule_17_3_ImplicitFunction.js.map +1 -0
  69. package/dist/rules/Section17_Functions/Rule_17_4_NonVoidReturn.d.ts +37 -12
  70. package/dist/rules/Section17_Functions/Rule_17_4_NonVoidReturn.d.ts.map +1 -1
  71. package/dist/rules/Section17_Functions/Rule_17_4_NonVoidReturn.js +112 -39
  72. package/dist/rules/Section17_Functions/Rule_17_4_NonVoidReturn.js.map +1 -1
  73. package/dist/rules/Section17_Functions/Rule_17_6_StaticArraySizeParam.d.ts +15 -5
  74. package/dist/rules/Section17_Functions/Rule_17_6_StaticArraySizeParam.d.ts.map +1 -1
  75. package/dist/rules/Section17_Functions/Rule_17_6_StaticArraySizeParam.js +21 -7
  76. package/dist/rules/Section17_Functions/Rule_17_6_StaticArraySizeParam.js.map +1 -1
  77. package/dist/rules/Section17_Functions/Rule_17_7_UnusedReturnValue.d.ts +11 -6
  78. package/dist/rules/Section17_Functions/Rule_17_7_UnusedReturnValue.d.ts.map +1 -1
  79. package/dist/rules/Section17_Functions/Rule_17_7_UnusedReturnValue.js +17 -8
  80. package/dist/rules/Section17_Functions/Rule_17_7_UnusedReturnValue.js.map +1 -1
  81. package/dist/rules/Section21-StandardLibraries/DisallowedStdLibFunctionRule.d.ts +105 -0
  82. package/dist/rules/Section21-StandardLibraries/DisallowedStdLibFunctionRule.d.ts.map +1 -0
  83. package/dist/rules/Section21-StandardLibraries/DisallowedStdLibFunctionRule.js +258 -0
  84. package/dist/rules/Section21-StandardLibraries/DisallowedStdLibFunctionRule.js.map +1 -0
  85. package/dist/rules/Section21-StandardLibraries/Rule_21_10_NoTimeDateFunctions.d.ts +25 -0
  86. package/dist/rules/Section21-StandardLibraries/Rule_21_10_NoTimeDateFunctions.d.ts.map +1 -0
  87. package/dist/rules/Section21-StandardLibraries/Rule_21_10_NoTimeDateFunctions.js +27 -0
  88. package/dist/rules/Section21-StandardLibraries/Rule_21_10_NoTimeDateFunctions.js.map +1 -0
  89. package/dist/rules/Section21-StandardLibraries/Rule_21_11_NoTgmathFunctions.d.ts +29 -0
  90. package/dist/rules/Section21-StandardLibraries/Rule_21_11_NoTgmathFunctions.d.ts.map +1 -0
  91. package/dist/rules/Section21-StandardLibraries/Rule_21_11_NoTgmathFunctions.js +31 -0
  92. package/dist/rules/Section21-StandardLibraries/Rule_21_11_NoTgmathFunctions.js.map +1 -0
  93. package/dist/rules/Section21-StandardLibraries/Rule_21_3_NoDynamicMemory.d.ts +25 -0
  94. package/dist/rules/Section21-StandardLibraries/Rule_21_3_NoDynamicMemory.d.ts.map +1 -0
  95. package/dist/rules/Section21-StandardLibraries/Rule_21_3_NoDynamicMemory.js +27 -0
  96. package/dist/rules/Section21-StandardLibraries/Rule_21_3_NoDynamicMemory.js.map +1 -0
  97. package/dist/rules/Section21-StandardLibraries/Rule_21_6_NoStdIOFunctions.d.ts +25 -0
  98. package/dist/rules/Section21-StandardLibraries/Rule_21_6_NoStdIOFunctions.d.ts.map +1 -0
  99. package/dist/rules/Section21-StandardLibraries/Rule_21_6_NoStdIOFunctions.js +27 -0
  100. package/dist/rules/Section21-StandardLibraries/Rule_21_6_NoStdIOFunctions.js.map +1 -0
  101. package/dist/rules/Section21-StandardLibraries/Rule_21_7_NoNumericStringConversions.d.ts +25 -0
  102. package/dist/rules/Section21-StandardLibraries/Rule_21_7_NoNumericStringConversions.d.ts.map +1 -0
  103. package/dist/rules/Section21-StandardLibraries/Rule_21_7_NoNumericStringConversions.js +27 -0
  104. package/dist/rules/Section21-StandardLibraries/Rule_21_7_NoNumericStringConversions.js.map +1 -0
  105. package/dist/rules/Section21-StandardLibraries/Rule_21_8_NoProcessControlFunctions.d.ts +30 -0
  106. package/dist/rules/Section21-StandardLibraries/Rule_21_8_NoProcessControlFunctions.d.ts.map +1 -0
  107. package/dist/rules/Section21-StandardLibraries/Rule_21_8_NoProcessControlFunctions.js +32 -0
  108. package/dist/rules/Section21-StandardLibraries/Rule_21_8_NoProcessControlFunctions.js.map +1 -0
  109. package/dist/rules/Section21-StandardLibraries/Rule_21_9_NoGenericSearchOrSort.d.ts +25 -0
  110. package/dist/rules/Section21-StandardLibraries/Rule_21_9_NoGenericSearchOrSort.d.ts.map +1 -0
  111. package/dist/rules/Section21-StandardLibraries/Rule_21_9_NoGenericSearchOrSort.js +27 -0
  112. package/dist/rules/Section21-StandardLibraries/Rule_21_9_NoGenericSearchOrSort.js.map +1 -0
  113. package/dist/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.d.ts +6 -14
  114. package/dist/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.d.ts.map +1 -1
  115. package/dist/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.js +17 -27
  116. package/dist/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.js.map +1 -1
  117. package/dist/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.d.ts +13 -7
  118. package/dist/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.d.ts.map +1 -1
  119. package/dist/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.js +31 -17
  120. package/dist/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.js.map +1 -1
  121. package/dist/rules/Section2_UnusedCode/Rule_2_6_UnusedLabels.d.ts +26 -7
  122. package/dist/rules/Section2_UnusedCode/Rule_2_6_UnusedLabels.d.ts.map +1 -1
  123. package/dist/rules/Section2_UnusedCode/Rule_2_6_UnusedLabels.js +32 -14
  124. package/dist/rules/Section2_UnusedCode/Rule_2_6_UnusedLabels.js.map +1 -1
  125. package/dist/rules/Section2_UnusedCode/Rule_2_7_UnusedParameters.d.ts +48 -6
  126. package/dist/rules/Section2_UnusedCode/Rule_2_7_UnusedParameters.d.ts.map +1 -1
  127. package/dist/rules/Section2_UnusedCode/Rule_2_7_UnusedParameters.js +84 -34
  128. package/dist/rules/Section2_UnusedCode/Rule_2_7_UnusedParameters.js.map +1 -1
  129. package/dist/rules/Section3_Comments/Rule_3_1_CommentSequences.d.ts +24 -5
  130. package/dist/rules/Section3_Comments/Rule_3_1_CommentSequences.d.ts.map +1 -1
  131. package/dist/rules/Section3_Comments/Rule_3_1_CommentSequences.js +27 -7
  132. package/dist/rules/Section3_Comments/Rule_3_1_CommentSequences.js.map +1 -1
  133. package/dist/rules/Section5_Identifiers/IdentifierRenameRule.d.ts +46 -0
  134. package/dist/rules/Section5_Identifiers/IdentifierRenameRule.d.ts.map +1 -0
  135. package/dist/rules/Section5_Identifiers/IdentifierRenameRule.js +40 -0
  136. package/dist/rules/Section5_Identifiers/IdentifierRenameRule.js.map +1 -0
  137. package/dist/rules/Section5_Identifiers/Rule_5_1_DistinctExternalIdentifiers.d.ts +25 -0
  138. package/dist/rules/Section5_Identifiers/Rule_5_1_DistinctExternalIdentifiers.d.ts.map +1 -0
  139. package/dist/rules/Section5_Identifiers/Rule_5_1_DistinctExternalIdentifiers.js +46 -0
  140. package/dist/rules/Section5_Identifiers/Rule_5_1_DistinctExternalIdentifiers.js.map +1 -0
  141. package/dist/rules/Section5_Identifiers/Rule_5_6_UniqueTypedefNames.d.ts +26 -0
  142. package/dist/rules/Section5_Identifiers/Rule_5_6_UniqueTypedefNames.d.ts.map +1 -0
  143. package/dist/rules/Section5_Identifiers/Rule_5_6_UniqueTypedefNames.js +54 -0
  144. package/dist/rules/Section5_Identifiers/Rule_5_6_UniqueTypedefNames.js.map +1 -0
  145. package/dist/rules/Section5_Identifiers/Rule_5_7_UniqueTagNames.d.ts +27 -0
  146. package/dist/rules/Section5_Identifiers/Rule_5_7_UniqueTagNames.d.ts.map +1 -0
  147. package/dist/rules/Section5_Identifiers/Rule_5_7_UniqueTagNames.js +55 -0
  148. package/dist/rules/Section5_Identifiers/Rule_5_7_UniqueTagNames.js.map +1 -0
  149. package/dist/rules/Section5_Identifiers/Rule_5_8_UniqueExternalLinkIdentifiers.d.ts +24 -0
  150. package/dist/rules/Section5_Identifiers/Rule_5_8_UniqueExternalLinkIdentifiers.d.ts.map +1 -0
  151. package/dist/rules/Section5_Identifiers/Rule_5_8_UniqueExternalLinkIdentifiers.js +42 -0
  152. package/dist/rules/Section5_Identifiers/Rule_5_8_UniqueExternalLinkIdentifiers.js.map +1 -0
  153. package/dist/rules/Section5_Identifiers/Rule_5_9_UniqueInternalLinkIdentifiers.d.ts +24 -0
  154. package/dist/rules/Section5_Identifiers/Rule_5_9_UniqueInternalLinkIdentifiers.d.ts.map +1 -0
  155. package/dist/rules/Section5_Identifiers/Rule_5_9_UniqueInternalLinkIdentifiers.js +42 -0
  156. package/dist/rules/Section5_Identifiers/Rule_5_9_UniqueInternalLinkIdentifiers.js.map +1 -0
  157. package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_6_SingleExternalDefinition.d.ts +35 -0
  158. package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_6_SingleExternalDefinition.d.ts.map +1 -0
  159. package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_6_SingleExternalDefinition.js +98 -0
  160. package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_6_SingleExternalDefinition.js.map +1 -0
  161. package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_7_RestrictExternalLinkage.d.ts +35 -0
  162. package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_7_RestrictExternalLinkage.d.ts.map +1 -0
  163. package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_7_RestrictExternalLinkage.js +76 -0
  164. package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_7_RestrictExternalLinkage.js.map +1 -0
  165. package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_9_BlockScopeDefinition.d.ts +32 -0
  166. package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_9_BlockScopeDefinition.d.ts.map +1 -0
  167. package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_9_BlockScopeDefinition.js +57 -0
  168. package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_9_BlockScopeDefinition.js.map +1 -0
  169. package/dist/rules/UserConfigurableRule.d.ts +55 -0
  170. package/dist/rules/UserConfigurableRule.d.ts.map +1 -0
  171. package/dist/rules/UserConfigurableRule.js +16 -0
  172. package/dist/rules/UserConfigurableRule.js.map +1 -0
  173. package/dist/rules/index.d.ts +11 -18
  174. package/dist/rules/index.d.ts.map +1 -1
  175. package/dist/rules/index.js +47 -7
  176. package/dist/rules/index.js.map +1 -1
  177. package/dist/tests/Section17_Functions/misra_config.json +10 -0
  178. package/dist/tests/Section21-StandardLibraries/misra_config.json +88 -0
  179. package/dist/tests/Section21-StandardLibraries/problematic_misra_config.json +19 -0
  180. package/dist/tests/utils.d.ts +6 -3
  181. package/dist/tests/utils.d.ts.map +1 -1
  182. package/dist/tests/utils.js +33 -7
  183. package/dist/tests/utils.js.map +1 -1
  184. package/dist/utils/CallUtils.d.ts +15 -0
  185. package/dist/utils/CallUtils.d.ts.map +1 -0
  186. package/dist/utils/CallUtils.js +34 -0
  187. package/dist/utils/CallUtils.js.map +1 -0
  188. package/dist/utils/CommentUtils.d.ts +21 -0
  189. package/dist/utils/CommentUtils.d.ts.map +1 -0
  190. package/dist/utils/CommentUtils.js +27 -0
  191. package/dist/utils/CommentUtils.js.map +1 -0
  192. package/dist/utils/FileUtils.d.ts +67 -0
  193. package/dist/utils/FileUtils.d.ts.map +1 -0
  194. package/dist/utils/FileUtils.js +144 -0
  195. package/dist/utils/FileUtils.js.map +1 -0
  196. package/dist/utils/FunctionUtils.d.ts +47 -0
  197. package/dist/utils/FunctionUtils.d.ts.map +1 -0
  198. package/dist/utils/FunctionUtils.js +87 -0
  199. package/dist/utils/FunctionUtils.js.map +1 -0
  200. package/dist/utils/IdentifierUtils.d.ts +63 -0
  201. package/dist/utils/IdentifierUtils.d.ts.map +1 -0
  202. package/dist/utils/IdentifierUtils.js +133 -0
  203. package/dist/utils/IdentifierUtils.js.map +1 -0
  204. package/dist/utils/JoinpointUtils.d.ts +36 -0
  205. package/dist/utils/JoinpointUtils.d.ts.map +1 -0
  206. package/dist/utils/JoinpointUtils.js +63 -0
  207. package/dist/utils/JoinpointUtils.js.map +1 -0
  208. package/dist/utils/ProgramUtils.d.ts +39 -0
  209. package/dist/utils/ProgramUtils.d.ts.map +1 -0
  210. package/dist/utils/ProgramUtils.js +97 -0
  211. package/dist/utils/ProgramUtils.js.map +1 -0
  212. package/dist/utils/SwitchUtils.d.ts +21 -0
  213. package/dist/utils/SwitchUtils.d.ts.map +1 -0
  214. package/dist/utils/SwitchUtils.js +47 -0
  215. package/dist/utils/SwitchUtils.js.map +1 -0
  216. package/dist/utils/TypeDeclUtils.d.ts +35 -0
  217. package/dist/utils/TypeDeclUtils.d.ts.map +1 -0
  218. package/dist/utils/TypeDeclUtils.js +78 -0
  219. package/dist/utils/TypeDeclUtils.js.map +1 -0
  220. package/dist/utils/VarUtils.d.ts +51 -0
  221. package/dist/utils/VarUtils.d.ts.map +1 -0
  222. package/dist/utils/VarUtils.js +91 -0
  223. package/dist/utils/VarUtils.js.map +1 -0
  224. package/package.json +16 -7
  225. package/src/MISRA.ts +33 -17
  226. package/src/MISRAContext.ts +128 -30
  227. package/src/MISRARule.ts +61 -29
  228. package/src/MISRATool.ts +126 -42
  229. package/src/StandardGuideline.ts +23 -0
  230. package/src/ast-visitor/Context.ts +16 -0
  231. package/src/ast-visitor/Visit.ts +26 -0
  232. package/src/ast-visitor/VisitWithContext.ts +42 -0
  233. package/src/main.ts +1 -4
  234. package/src/rules/Section13_SideEffects/Rule_13_6_SafeSizeOfOperand.ts +114 -0
  235. package/src/rules/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.ts +103 -13
  236. package/src/rules/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.ts +24 -10
  237. package/src/rules/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.ts +17 -8
  238. package/src/rules/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.ts +20 -12
  239. package/src/rules/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.ts +23 -12
  240. package/src/rules/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.ts +44 -13
  241. package/src/rules/Section17_Functions/Rule_17_3_ImplicitFunction.ts +153 -104
  242. package/src/rules/Section17_Functions/Rule_17_4_NonVoidReturn.ts +114 -44
  243. package/src/rules/Section17_Functions/Rule_17_6_StaticArraySizeParam.ts +27 -10
  244. package/src/rules/Section17_Functions/Rule_17_7_UnusedReturnValue.ts +20 -12
  245. package/src/rules/Section21-StandardLibraries/DisallowedStdLibFunctionRule.ts +317 -0
  246. package/src/rules/Section21-StandardLibraries/Rule_21_10_NoTimeDateFunctions.ts +30 -0
  247. package/src/rules/Section21-StandardLibraries/Rule_21_11_NoTgmathFunctions.ts +35 -0
  248. package/src/rules/Section21-StandardLibraries/Rule_21_3_NoDynamicMemory.ts +30 -0
  249. package/src/rules/Section21-StandardLibraries/Rule_21_6_NoStdIOFunctions.ts +30 -0
  250. package/src/rules/Section21-StandardLibraries/Rule_21_7_NoNumericStringConversions.ts +29 -0
  251. package/src/rules/Section21-StandardLibraries/Rule_21_8_NoProcessControlFunctions.ts +36 -0
  252. package/src/rules/Section21-StandardLibraries/Rule_21_9_NoGenericSearchOrSort.ts +30 -0
  253. package/src/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.ts +14 -29
  254. package/src/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.ts +33 -19
  255. package/src/rules/Section2_UnusedCode/Rule_2_6_UnusedLabels.ts +33 -20
  256. package/src/rules/Section2_UnusedCode/Rule_2_7_UnusedParameters.ts +90 -45
  257. package/src/rules/Section3_Comments/Rule_3_1_CommentSequences.ts +27 -8
  258. package/src/rules/Section5_Identifiers/IdentifierRenameRule.ts +63 -0
  259. package/src/rules/Section5_Identifiers/Rule_5_1_DistinctExternalIdentifiers.ts +52 -0
  260. package/src/rules/Section5_Identifiers/Rule_5_6_UniqueTypedefNames.ts +62 -0
  261. package/src/rules/Section5_Identifiers/Rule_5_7_UniqueTagNames.ts +61 -0
  262. package/src/rules/Section5_Identifiers/Rule_5_8_UniqueExternalLinkIdentifiers.ts +47 -0
  263. package/src/rules/Section5_Identifiers/Rule_5_9_UniqueInternalLinkIdentifiers.ts +47 -0
  264. package/src/rules/Section8_DeclarationsAndDefinitions/Rule_8_6_SingleExternalDefinition.ts +118 -0
  265. package/src/rules/Section8_DeclarationsAndDefinitions/Rule_8_7_RestrictExternalLinkage.ts +89 -0
  266. package/src/rules/Section8_DeclarationsAndDefinitions/Rule_8_9_BlockScopeDefinition.ts +65 -0
  267. package/src/rules/UserConfigurableRule.ts +60 -0
  268. package/src/rules/index.ts +45 -7
  269. package/src/tests/Section13_SideEffects/Rule_13_6_SafeSizeOfOperand.test.ts +114 -0
  270. package/src/tests/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.test.ts +7 -5
  271. package/src/tests/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.test.ts +40 -13
  272. package/src/tests/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.test.ts +10 -12
  273. package/src/tests/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.test.ts +5 -5
  274. package/src/tests/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.test.ts +5 -5
  275. package/src/tests/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.test.ts +5 -5
  276. package/src/tests/Section17_Functions/Rule_17_3_ImplicitFunctions.test.ts +68 -40
  277. package/src/tests/Section17_Functions/Rule_17_3_ImplicitFunctions_MissingConfig.test.ts +98 -0
  278. package/src/tests/Section17_Functions/Rule_17_3_ImplicitFunctions_ProblematicConfig.test.ts +71 -0
  279. package/src/tests/Section17_Functions/Rule_17_4_NonVoidReturn.test.ts +103 -49
  280. package/src/tests/Section17_Functions/Rule_17_4_NonVoidReturn_MissingConfig.test.ts +7 -7
  281. package/src/tests/Section17_Functions/Rule_17_6_StaticArraySizeParam.test.ts +36 -7
  282. package/src/tests/Section17_Functions/Rule_17_7_UnusedReturnValue.test.ts +25 -21
  283. package/src/tests/Section17_Functions/misra_config.json +4 -3
  284. package/src/tests/Section21-StandardLibraries/Rule_21_10_NoTimeDateFunctions.test.ts +62 -0
  285. package/src/tests/Section21-StandardLibraries/Rule_21_11_NoTgmathFunctions.test.ts +67 -0
  286. package/src/tests/Section21-StandardLibraries/Rule_21_3_NoDynamicMemory.test.ts +84 -0
  287. package/src/tests/Section21-StandardLibraries/Rule_21_3_NoDynamicMemory_MissingConfig.test.ts +33 -0
  288. package/src/tests/Section21-StandardLibraries/Rule_21_3_NoDynamicMemory_ProblematicConfig.test.ts +71 -0
  289. package/src/tests/Section21-StandardLibraries/Rule_21_6_NoStdIOFunctions.test.ts +63 -0
  290. package/src/tests/Section21-StandardLibraries/Rule_21_7_NoNumericStringConversions.test.ts +91 -0
  291. package/src/tests/Section21-StandardLibraries/Rule_21_8_NoProcessControlFunctions.test.ts +65 -0
  292. package/src/tests/Section21-StandardLibraries/Rule_21_9_NoGenericSearchOrSort.test.ts +89 -0
  293. package/src/tests/Section21-StandardLibraries/misra_config.json +88 -0
  294. package/src/tests/Section21-StandardLibraries/problematic_misra_config.json +19 -0
  295. package/src/tests/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.test.ts +148 -113
  296. package/src/tests/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.test.ts +243 -163
  297. package/src/tests/Section2_UnusedCode/Rule_2_6_UnusedLabels.test.ts +32 -20
  298. package/src/tests/Section2_UnusedCode/Rule_2_7_UnusedParameters.test.ts +36 -30
  299. package/src/tests/Section3_Comments/Rule_3_1_CommentSequences.test.ts +37 -8
  300. package/src/tests/Section5_Identifiers/Rule_5_1_DistinctExternalIdentifiers.test.ts +78 -0
  301. package/src/tests/Section5_Identifiers/Rule_5_6_UniqueTypedefNames.test.ts +120 -0
  302. package/src/tests/Section5_Identifiers/Rule_5_7_UniqueTagNames.test.ts +51 -0
  303. package/src/tests/Section5_Identifiers/Rule_5_8_UniqueExternalLinkIdentifiers.test.ts +73 -0
  304. package/src/tests/Section5_Identifiers/Rule_5_9_UniqueInternalLinkIdentifiers.test.ts +97 -0
  305. package/src/tests/Section8_DeclarationsAndDefinitions/Rule_8_6_SingleExternalDefinition.test.ts +160 -0
  306. package/src/tests/Section8_DeclarationsAndDefinitions/Rule_8_7_RestrictExternalLinkage.test.ts +46 -0
  307. package/src/tests/Section8_DeclarationsAndDefinitions/Rule_8_9_BlockScopeDefinition.test.ts +69 -0
  308. package/src/tests/utils.ts +32 -7
  309. package/src/utils/CallUtils.ts +37 -0
  310. package/src/utils/CommentUtils.ts +29 -0
  311. package/src/utils/FileUtils.ts +169 -0
  312. package/src/utils/FunctionUtils.ts +97 -0
  313. package/src/utils/IdentifierUtils.ts +142 -0
  314. package/src/utils/JoinpointUtils.ts +70 -0
  315. package/src/utils/ProgramUtils.ts +107 -0
  316. package/src/utils/SwitchUtils.ts +52 -0
  317. package/src/utils/TypeDeclUtils.ts +88 -0
  318. package/src/utils/VarUtils.ts +102 -0
  319. package/tsconfig.json +2 -1
  320. package/src/rules/Section20-PreprocessingDirectives/Rule_20_2_InvalidHeaderFileName.ts +0 -120
  321. package/src/rules/Section3_Comments/Rule_3_2_LineSplicing.ts +0 -36
  322. package/src/utils/utils.ts +0 -280
@@ -0,0 +1,47 @@
1
+ import {Joinpoint, Program} from "@specs-feup/clava/api/Joinpoints.js";
2
+ import { getIdentifierDecls, getInternalLinkageIdentifiers } from "../../utils/ProgramUtils.js";
3
+ import { getIdentifierName, isIdentifierDuplicated, isIdentifierNameDeclaredBefore, isInternalLinkageIdentifier } from "../../utils/IdentifierUtils.js";
4
+ import IdentifierRenameRule from "./IdentifierRenameRule.js";
5
+ import { AnalysisType } from "../../MISRA.js";
6
+
7
+ /**
8
+ * MISRA-C Rule 5.9: Identifiers that define objects or functions with internal linkage should be unique
9
+ */
10
+ export default class Rule_5_9_UniqueInternalLinkIdentifiers extends IdentifierRenameRule {
11
+ /**
12
+ * Scope of analysis
13
+ */
14
+ readonly analysisType = AnalysisType.SYSTEM;
15
+
16
+ /**
17
+ * @returns Rule identifier according to MISRA-C:2012
18
+ */
19
+ override get name(): string {
20
+ return "5.9";
21
+ }
22
+
23
+ /**
24
+ *
25
+ * @param $jp - Joinpoint to analyze
26
+ * @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
27
+ * @returns Returns true if the joinpoint violates the rule, false otherwise
28
+ */
29
+ match($jp: Joinpoint, logErrors: boolean = false): boolean {
30
+ if (!($jp instanceof Program)) return false;
31
+
32
+ const internalLinkageIdentifiers = getInternalLinkageIdentifiers();
33
+ this.invalidIdentifiers = getIdentifierDecls().filter((identifierJp) =>
34
+ isInternalLinkageIdentifier(identifierJp) ?
35
+ isIdentifierNameDeclaredBefore(identifierJp, internalLinkageIdentifiers) :
36
+ isIdentifierDuplicated(identifierJp, internalLinkageIdentifiers)
37
+ );
38
+
39
+ const nonCompliant = this.invalidIdentifiers.length > 0;
40
+ if (nonCompliant && logErrors) {
41
+ this.invalidIdentifiers.forEach(identifierJp => {
42
+ this.logMISRAError(identifierJp, `Identifier '${getIdentifierName(identifierJp)}' is already defined with internal linkage in this or other file.`);
43
+ })
44
+ }
45
+ return nonCompliant;
46
+ }
47
+ }
@@ -0,0 +1,118 @@
1
+ import { FileJp, Joinpoint, Program, StorageClass, Vardecl } from "@specs-feup/clava/api/Joinpoints.js";
2
+ import MISRARule from "../../MISRARule.js";
3
+ import { AnalysisType, MISRATransformationReport, MISRATransformationType } from "../../MISRA.js";
4
+ import { getIdentifierName } from "../../utils/IdentifierUtils.js";
5
+ import { getExternalLinkageVars, resetCaches, resetExternalVarRefs } from "../../utils/ProgramUtils.js";
6
+ import { compareLocation } from "../../utils/JoinpointUtils.js";
7
+ import Query from "@specs-feup/lara/api/weaver/Query.js";
8
+ import { isSameVarDecl } from "../../utils/VarUtils.js";
9
+
10
+ /**
11
+ * MISRA-C Rule 8.6: An identifier with external linkage shall have exactly one external definition
12
+ */
13
+ export default class Rule_8_6_SingleExternalDefinition extends MISRARule {
14
+ /**
15
+ * Scope of analysis
16
+ */
17
+ readonly analysisType = AnalysisType.SYSTEM;
18
+
19
+ /**
20
+ * A positive integer starting from 1 that indicates the rule's priority, determining the order in which rules are applied.
21
+ */
22
+ readonly priority = 2;
23
+
24
+ #invalidDecls: Vardecl[] = [];
25
+
26
+ /**
27
+ * @returns Rule identifier according to MISRA-C:2012
28
+ */
29
+ override get name(): string {
30
+ return "8.6";
31
+ }
32
+
33
+ /**
34
+ *
35
+ * @param $jp - Joinpoint to analyze
36
+ * @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
37
+ * @returns Returns true if the joinpoint violates the rule, false otherwise
38
+ */
39
+ match($jp: Joinpoint, logErrors: boolean = false): boolean {
40
+ if (!($jp instanceof Program)) {
41
+ return false;
42
+ }
43
+
44
+ const externalLinkageVars = getExternalLinkageVars();
45
+ this.#invalidDecls = externalLinkageVars.filter((decl1) =>
46
+ externalLinkageVars.some((decl2) =>
47
+ isSameVarDecl(decl1, decl2) &&
48
+ decl1.getAncestor("file").ast !== decl2.getAncestor("file").ast &&
49
+ compareLocation(decl2, decl1) < 0
50
+ )
51
+ );
52
+
53
+ const nonCompliant = this.#invalidDecls.length > 0;
54
+ if (nonCompliant && logErrors) {
55
+ this.#invalidDecls.forEach(identifierJp => {
56
+ this.logMISRAError(identifierJp, `Identifier '${getIdentifierName(identifierJp)}' with external linkage is defined in multiple files.`)
57
+ });
58
+ }
59
+ return nonCompliant;
60
+ }
61
+
62
+ /**
63
+ *
64
+ * @param $jp - Joinpoint to transform
65
+ * @returns Report detailing the transformation result
66
+ */
67
+ apply($jp: Joinpoint): MISRATransformationReport {
68
+ if (!this.match($jp)) {
69
+ return new MISRATransformationReport(MISRATransformationType.NoChange);
70
+ }
71
+
72
+ let solved = false;
73
+ const uniqueDecls = this.#invalidDecls.reduce((acc: Vardecl[], decl1) => acc.some(decl2 => isSameVarDecl(decl1, decl2)) ? acc : [...acc, decl1], []);
74
+
75
+ for (const decl of uniqueDecls) {
76
+ if (this.context.getRuleResult(this.ruleID, decl) === MISRATransformationType.NoChange) {
77
+ continue;
78
+ }
79
+
80
+ const filesWithInitialization = Query.search(FileJp, (fileJp) => {
81
+ return fileJp.descendants.some((jp) =>
82
+ isSameVarDecl(jp, decl) && (jp as Vardecl).init !== undefined
83
+ );
84
+ }).get();
85
+
86
+ if (filesWithInitialization.length > 1) {
87
+
88
+ const other = this.#invalidDecls.filter(identifier => isSameVarDecl(identifier, decl));
89
+ for (const varDecl of other) {
90
+ this.logMISRAError(varDecl, `Identifier '${getIdentifierName(varDecl)}' with external linkage has multiple definitions across files. Automatic correction cannot be applied due to multiple initializations.`);
91
+ this.context.addRuleResult(this.ruleID, varDecl, MISRATransformationType.NoChange);
92
+ }
93
+ }
94
+ else if (filesWithInitialization.length === 0) {
95
+ const other = this.#invalidDecls.filter(identifier => isSameVarDecl(decl, identifier));
96
+ other.forEach(varDecl => {
97
+ varDecl.setStorageClass(StorageClass.EXTERN)
98
+ });
99
+ solved = true;
100
+ }
101
+ else {
102
+ const other = getExternalLinkageVars().filter(identifierJp =>
103
+ isSameVarDecl(decl, identifierJp) &&
104
+ (identifierJp.getAncestor("file").ast !== filesWithInitialization[0].ast)
105
+ );
106
+ other.forEach(varDecl => {
107
+ varDecl.setStorageClass(StorageClass.EXTERN);
108
+ });
109
+ solved = true;
110
+ }
111
+ }
112
+ if (solved) {
113
+ resetCaches();
114
+ return new MISRATransformationReport(MISRATransformationType.DescendantChange);
115
+ }
116
+ return new MISRATransformationReport(MISRATransformationType.NoChange);
117
+ }
118
+ }
@@ -0,0 +1,89 @@
1
+ import { FunctionJp, Joinpoint, Program, StorageClass, Vardecl, Varref } from "@specs-feup/clava/api/Joinpoints.js";
2
+ import MISRARule from "../../MISRARule.js";
3
+ import { AnalysisType, MISRATransformationReport, MISRATransformationType } from "../../MISRA.js";
4
+ import { getIdentifierName, isExternalLinkageIdentifier } from "../../utils/IdentifierUtils.js";
5
+ import { findExternalVarRefs, hasMultipleExternalLinkDeclarations, isVarUsed } from "../../utils/VarUtils.js";
6
+ import { findExternalFunctionDecl, isFunctionUsed } from "../../utils/FunctionUtils.js";
7
+ import { resetCaches, resetExternalVarRefs } from "../../utils/ProgramUtils.js";
8
+
9
+ /**
10
+ * MISRA-C Rule 8.7: Functions and objects should not be defined with external linkage if they are referenced in only one translation unit
11
+ */
12
+ export default class Rule_8_7_RestrictExternalLinkage extends MISRARule {
13
+ /**
14
+ * Scope of analysis
15
+ */
16
+ readonly analysisType = AnalysisType.SYSTEM;
17
+
18
+ /**
19
+ * @returns Rule identifier according to MISRA-C:2012
20
+ */
21
+ override get name(): string {
22
+ return "8.7";
23
+ }
24
+
25
+ /**
26
+ * External declarations (`extern`) of the current identifier found in other source files.
27
+ */
28
+ #externalDecls: FunctionJp[] | Vardecl[] = [];
29
+
30
+ /**
31
+ *
32
+ * @param $jp - Joinpoint to analyze
33
+ * @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
34
+ * @returns Returns true if the joinpoint violates the rule, false otherwise
35
+ */
36
+ match($jp: Joinpoint, logErrors: boolean = false): boolean {
37
+ if (!isExternalLinkageIdentifier($jp) || ($jp instanceof FunctionJp && $jp.name === "main")) {
38
+ return false;
39
+ }
40
+
41
+ this.#externalDecls = $jp instanceof Vardecl ? findExternalVarRefs($jp) : findExternalFunctionDecl($jp as FunctionJp);
42
+ const isUsed = this.#externalDecls.some(decl => decl instanceof Vardecl ? isVarUsed(decl) : isFunctionUsed(decl));
43
+ const nonCompliant = this.#externalDecls.length === 0 || !isUsed;
44
+ if (nonCompliant && logErrors) {
45
+ this.logMISRAError(
46
+ $jp,
47
+ `${$jp instanceof FunctionJp ? "Function" : "Object"} '${getIdentifierName($jp)}' has external linkage but is only referenced within a single translation unit. Consider using the 'static' keyword to give it internal linkage.`
48
+ );
49
+ this.#externalDecls.forEach(decl => this.logMISRAError(decl, `'extern' declaration of '${getIdentifierName(decl)}' is unused. The corresponding definition is not referenced outside its translation unit and does not require external linkage.`))
50
+ }
51
+ return nonCompliant;
52
+ }
53
+
54
+ /**
55
+ *
56
+ * @param $jp - Joinpoint to transform
57
+ * @returns Report detailing the transformation result
58
+ */
59
+ apply($jp: Joinpoint): MISRATransformationReport {
60
+ const previousResult = this.context.getRuleResult(this.ruleID, $jp);
61
+ if (previousResult === MISRATransformationType.NoChange || !this.match($jp)) {
62
+ return new MISRATransformationReport(MISRATransformationType.NoChange);
63
+ }
64
+
65
+ this.removeExternalDeclarations();
66
+ if ($jp instanceof Vardecl && hasMultipleExternalLinkDeclarations($jp)) {
67
+ this.logMISRAError(
68
+ $jp,
69
+ `${$jp instanceof FunctionJp ? "Function" : "Object"} '${getIdentifierName($jp)}' has external linkage but is only referenced within a single translation unit. Couldn't give it internal linkage as it is defined in multiple files.`)
70
+ this.context.addRuleResult(this.ruleID, $jp, MISRATransformationType.NoChange);
71
+ return new MISRATransformationReport(MISRATransformationType.NoChange);
72
+ }
73
+
74
+ const identifierJp = ($jp as Vardecl | FunctionJp);
75
+ identifierJp.setStorageClass(StorageClass.STATIC);
76
+ resetCaches();
77
+ return new MISRATransformationReport(MISRATransformationType.DescendantChange);
78
+ }
79
+
80
+ /**
81
+ * Removes unused external declarations (`extern`) of the current identifier found in other source files.
82
+ */
83
+ private removeExternalDeclarations() {
84
+ if (this.#externalDecls.length > 0 && this.#externalDecls[0] instanceof Vardecl) {
85
+ resetExternalVarRefs();
86
+ }
87
+ this.#externalDecls.forEach(decl => decl instanceof FunctionJp ? decl.detach() : decl.parent.detach());
88
+ }
89
+ }
@@ -0,0 +1,65 @@
1
+ import {DeclStmt, Joinpoint, Vardecl } from "@specs-feup/clava/api/Joinpoints.js";
2
+ import MISRARule from "../../MISRARule.js";
3
+ import { AnalysisType, MISRATransformationReport, MISRATransformationType } from "../../MISRA.js";
4
+ import Query from "@specs-feup/lara/api/weaver/Query.js";
5
+ import { findReferencingFunctions } from "../../utils/VarUtils.js";
6
+ import { isInternalLinkageIdentifier } from "../../utils/IdentifierUtils.js";
7
+ import { resetCaches } from "../../utils/ProgramUtils.js";
8
+
9
+ /**
10
+ * MISRA-C Rule 8.9: An object should be defined at block scope if its identifier only appears in a single function
11
+ */
12
+ export default class Rule_8_9_BlockScopeDefinition extends MISRARule {
13
+ /**
14
+ * Scope of analysis
15
+ */
16
+ readonly analysisType = AnalysisType.SYSTEM;
17
+
18
+ /**
19
+ * @returns Rule identifier according to MISRA-C:2012
20
+ */
21
+ override get name(): string {
22
+ return "8.9";
23
+ }
24
+
25
+ /**
26
+ * Checks if the provided joinpoint represents an object definition with internal linkage, whose identifier only appears in a single function.
27
+ *
28
+ * @param $jp - Joinpoint to analyze
29
+ * @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
30
+ * @returns Returns true if the joinpoint violates the rule, false otherwise
31
+ */
32
+ match($jp: Joinpoint, logErrors: boolean = false): boolean {
33
+ if (!($jp instanceof Vardecl && isInternalLinkageIdentifier($jp))) {
34
+ return false;
35
+ }
36
+
37
+ const nonCompliant = findReferencingFunctions($jp).length <= 1;
38
+
39
+ if (nonCompliant && logErrors) {
40
+ this.logMISRAError($jp, `Object '${$jp.name}' should be defined at block scope because its identifier only appears in one single function.`)
41
+ }
42
+ return nonCompliant;
43
+ }
44
+
45
+ /**
46
+ * If the joinpoint represents the definition of an object with internal linkage used exclusively in one function, it is moved to that function's block scope.
47
+ *
48
+ * @param $jp - Joinpoint to transform
49
+ * @returns Report detailing the transformation result
50
+ */
51
+ apply($jp: Joinpoint): MISRATransformationReport {
52
+ if (!this.match($jp)) {
53
+ return new MISRATransformationReport(MISRATransformationType.NoChange);
54
+ }
55
+
56
+ const referencingFunctions = findReferencingFunctions($jp as Vardecl);
57
+ const functionJp = referencingFunctions.length > 0 ? referencingFunctions[0] : undefined;
58
+ const declStmt = $jp.getAncestor("declStmt");
59
+ declStmt.detach();
60
+ functionJp?.body.firstChild.insertBefore(declStmt);
61
+ resetCaches();
62
+
63
+ return new MISRATransformationReport(MISRATransformationType.Removal);
64
+ }
65
+ }
@@ -0,0 +1,60 @@
1
+ import { Joinpoint } from "@specs-feup/clava/api/Joinpoints.js";
2
+ import { LaraJoinPoint } from "@specs-feup/lara/api/LaraJoinPoint.js";
3
+ import MISRARule from "../MISRARule.js";
4
+ import { AnalysisType, MISRATransformationReport } from "../MISRA.js";
5
+
6
+ /**
7
+ * Represents a MISRARule that requires the user to provide custom settings to assist in the automatic transformation.
8
+ *
9
+ * Need to implement/define:
10
+ * - analysisType
11
+ * - name()
12
+ * - getErrorMsgPrefix($jp)
13
+ * - getFixFromConfig($jp, errorMsgPrefix)
14
+ * - match($jp, logErrors)
15
+ * - apply($jp)
16
+ *
17
+ */
18
+ export default abstract class UserConfigurableRule extends MISRARule {
19
+ /**
20
+ * Specifies the scope of analysis: single unit or entire system.
21
+ */
22
+ abstract readonly analysisType: AnalysisType;
23
+
24
+ /**
25
+ * @returns Rule identifier according to MISRA-C:2012
26
+ */
27
+ abstract override get name(): string;
28
+
29
+ /**
30
+ * Returns the prefix to be used for error messages related to the given joinpoint
31
+ *
32
+ * @param $jp - Joinpoint where the violation was detected
33
+ * @returns Returns a prefix to prepend to error messages if no configuration is specified or if the configuration does not contain a fix for this violation
34
+ */
35
+ protected abstract getErrorMsgPrefix($jp: Joinpoint): string;
36
+
37
+ /**
38
+ * Retrieves a fix for the given joinpoint using the provided configuration file
39
+ * @param $jp - Joinpoint where the violation was detected
40
+ * @return The fix retrieved from the configuration for the violation, or `undefined` if no applicable fix is found.
41
+ */
42
+ protected abstract getFixFromConfig($jp: Joinpoint): any;
43
+
44
+ /**
45
+ * Checks if the joinpoint violates the rule
46
+ *
47
+ * @param $jp - Joinpoint to analyze
48
+ * @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
49
+ * @returns Returns true if the joinpoint violates the rule, false otherwise
50
+ */
51
+ abstract match($jp: Joinpoint, logErrors: boolean): boolean;
52
+
53
+ /**
54
+ * Transforms the joinpoint to comply with the MISRA-C rule
55
+ *
56
+ * @param $jp - Joinpoint to transform
57
+ * @returns Report detailing the transformation result
58
+ */
59
+ abstract apply($jp: LaraJoinPoint): MISRATransformationReport;
60
+ }
@@ -1,5 +1,6 @@
1
1
  import MISRAContext from "../MISRAContext.js";
2
2
  import MISRARule from "../MISRARule.js";
3
+ import Rule_13_6_SafeSizeOfOperand from "./Section13_SideEffects/Rule_13_6_SafeSizeOfOperand.js";
3
4
  import Rule_16_2_TopLevelSwitch from "./Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.js";
4
5
  import Rule_16_3_UnconditionalBreak from "./Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.js";
5
6
  import Rule_16_4_SwitchHasDefault from "./Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.js";
@@ -10,22 +11,52 @@ import Rule_17_3_ImplicitFunction from "./Section17_Functions/Rule_17_3_Implicit
10
11
  import Rule_17_4_NonVoidReturn from "./Section17_Functions/Rule_17_4_NonVoidReturn.js";
11
12
  import Rule_17_6_StaticArraySizeParam from "./Section17_Functions/Rule_17_6_StaticArraySizeParam.js";
12
13
  import Rule_17_7_UnusedReturnValue from "./Section17_Functions/Rule_17_7_UnusedReturnValue.js";
14
+ import Rule_21_10_NoTimeDateFunctions from "./Section21-StandardLibraries/Rule_21_10_NoTimeDateFunctions.js";
15
+ import Rule_21_11_NoTgmathFunctions from "./Section21-StandardLibraries/Rule_21_11_NoTgmathFunctions.js";
16
+ import Rule_21_3_NoDynamicMemory from "./Section21-StandardLibraries/Rule_21_3_NoDynamicMemory.js";
17
+ import Rule_21_6_NoStdIOFunctions from "./Section21-StandardLibraries/Rule_21_6_NoStdIOFunctions.js";
18
+ import Rule_21_7_NoNumericStringConversions from "./Section21-StandardLibraries/Rule_21_7_NoNumericStringConversions.js";
19
+ import Rule_21_8_NoProcessControlFunctions from "./Section21-StandardLibraries/Rule_21_8_NoProcessControlFunctions.js";
20
+ import Rule_21_9_NoGenericSearchOrSort from "./Section21-StandardLibraries/Rule_21_9_NoGenericSearchOrSort.js";
13
21
  import Rule_2_3_UnusedTypeDecl from "./Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.js";
14
22
  import Rule_2_4_UnusedTagDecl from "./Section2_UnusedCode/Rule_2_4_UnusedTagDecl.js";
15
23
  import Rule_2_6_UnusedLabels from "./Section2_UnusedCode/Rule_2_6_UnusedLabels.js";
16
24
  import Rule_2_7_UnusedParameters from "./Section2_UnusedCode/Rule_2_7_UnusedParameters.js";
17
25
  import Rule_3_1_CommentSequences from "./Section3_Comments/Rule_3_1_CommentSequences.js";
18
- import Rule_3_2_CommentSequences from "./Section3_Comments/Rule_3_2_LineSplicing.js";
26
+ import Rule_5_1_DistinctExternalIdentifiers from "./Section5_Identifiers/Rule_5_1_DistinctExternalIdentifiers.js";
27
+ import Rule_5_6_UniqueTypedefNames from "./Section5_Identifiers/Rule_5_6_UniqueTypedefNames.js";
28
+ import Rule_5_7_UniqueTagNames from "./Section5_Identifiers/Rule_5_7_UniqueTagNames.js";
29
+ import Rule_5_8_UniqueExternalLinkIdentifiers from "./Section5_Identifiers/Rule_5_8_UniqueExternalLinkIdentifiers.js";
30
+ import Rule_5_9_UniqueInternalLinkIdentifiers from "./Section5_Identifiers/Rule_5_9_UniqueInternalLinkIdentifiers.js";
31
+ import Rule_8_6_SingleExternalDefinition from "./Section8_DeclarationsAndDefinitions/Rule_8_6_SingleExternalDefinition.js";
32
+ import Rule_8_7_RestrictExternalLinkage from "./Section8_DeclarationsAndDefinitions/Rule_8_7_RestrictExternalLinkage.js";
33
+ import Rule_8_9_BlockScopeDefinition from "./Section8_DeclarationsAndDefinitions/Rule_8_9_BlockScopeDefinition.js";
19
34
 
20
- export function sortRules(context: MISRAContext) {
35
+ /**
36
+ * Selects MISRA-C rules based on the provided analysis type.
37
+ * Returns rules sorted by priority (lower value has higher priority).
38
+ *
39
+ * @param context - The shared analysis context
40
+ * @param analysisType - Rule type to include ("all" for all rules).
41
+ * @returns Filtered and sorted list of MISRA rules.
42
+ */
43
+ export function selectRules(context: MISRAContext, analysisType: string) {
21
44
 
22
- const rules: MISRARule[] = [
45
+ let rules: MISRARule[] = [
23
46
  new Rule_2_3_UnusedTypeDecl(context),
24
47
  new Rule_2_4_UnusedTagDecl(context),
25
48
  new Rule_2_6_UnusedLabels(context),
26
49
  new Rule_2_7_UnusedParameters(context),
27
50
  new Rule_3_1_CommentSequences(context),
28
- new Rule_3_2_CommentSequences(context),
51
+ new Rule_5_1_DistinctExternalIdentifiers(context),
52
+ new Rule_5_6_UniqueTypedefNames(context),
53
+ new Rule_5_7_UniqueTagNames(context),
54
+ new Rule_5_8_UniqueExternalLinkIdentifiers(context),
55
+ new Rule_5_9_UniqueInternalLinkIdentifiers(context),
56
+ new Rule_8_6_SingleExternalDefinition(context),
57
+ new Rule_8_7_RestrictExternalLinkage(context),
58
+ new Rule_8_9_BlockScopeDefinition(context),
59
+ new Rule_13_6_SafeSizeOfOperand(context),
29
60
  new Rule_16_2_TopLevelSwitch(context),
30
61
  new Rule_16_3_UnconditionalBreak(context),
31
62
  new Rule_16_4_SwitchHasDefault(context),
@@ -36,9 +67,16 @@ export function sortRules(context: MISRAContext) {
36
67
  new Rule_17_4_NonVoidReturn(context),
37
68
  new Rule_17_6_StaticArraySizeParam(context),
38
69
  new Rule_17_7_UnusedReturnValue(context),
70
+ new Rule_21_3_NoDynamicMemory(context),
71
+ new Rule_21_6_NoStdIOFunctions(context),
72
+ new Rule_21_7_NoNumericStringConversions(context),
73
+ new Rule_21_8_NoProcessControlFunctions(context),
74
+ new Rule_21_9_NoGenericSearchOrSort(context),
75
+ new Rule_21_10_NoTimeDateFunctions(context),
76
+ new Rule_21_11_NoTgmathFunctions(context)
39
77
  ];
40
-
41
- return rules.sort((ruleA, ruleB) => ruleA.priority - ruleB.priority);
78
+ rules.sort((ruleA, ruleB) => ruleA.priority - ruleB.priority);
79
+ return analysisType === "all" ? rules : rules.filter(rule => rule.analysisType === analysisType);
42
80
  }
43
81
 
44
- export default sortRules;
82
+ export default selectRules;
@@ -0,0 +1,114 @@
1
+ import Query from "@specs-feup/lara/api/weaver/Query.js";
2
+ import { countErrorsAfterCorrection, countMISRAErrors, registerSourceCode, TestFile } from "../utils.js";
3
+ import { FileJp } from "@specs-feup/clava/api/Joinpoints.js";
4
+
5
+ const misraExample = `
6
+ #include <stdint.h>
7
+ #include <stddef.h>
8
+
9
+ static void test_13_6_1(void) {
10
+ volatile int32_t i;
11
+ int32_t j;
12
+ size_t s;
13
+
14
+ s = sizeof(j);
15
+ s = sizeof(j++); // Non-compliant (rule 13.6)
16
+ s = sizeof(i);
17
+ s = sizeof(int32_t);
18
+ }
19
+
20
+ static void f(int32_t n) {
21
+ static volatile uint32_t v;
22
+ size_t s;
23
+ s = sizeof(int32_t[n]); /* Compliant */
24
+ s = sizeof(int32_t[n++]); /* Non-compliant (rule 13.6) */
25
+ }
26
+ `;
27
+
28
+ const passingCode = `
29
+ #include <stdint.h>
30
+ #include <stddef.h>
31
+
32
+ static void test_13_6_2(int32_t n1, int32_t buffer[]) {
33
+ size_t s1;
34
+ volatile int32_t i1;
35
+ int32_t j1;
36
+
37
+ s1 = sizeof(j1); /* Compliant */
38
+ s1 = sizeof(i1); /* Compliant - exception */
39
+ s1 = sizeof(i1 + j1); /* Compliant */
40
+ s1 = sizeof(int32_t); /* Compliant */
41
+ s1 = sizeof( int32_t[ n1 ] ); /* Compliant */
42
+ s1 = sizeof(buffer[s1]); /* Compliant */
43
+ }
44
+ `;
45
+
46
+ const failingCode = `
47
+ #include <stdint.h>
48
+ #include <stddef.h>
49
+
50
+ static int32_t foo_13_6_3(float n) {
51
+ if (n > 0) {
52
+ return 1;
53
+ }
54
+ return -1;
55
+ }
56
+
57
+ static float bar_13_6_4() {
58
+ return 5.0;
59
+ }
60
+
61
+ static void test_13_6_3(int32_t n) {
62
+ uint32_t a2 = 0x0F;
63
+ uint32_t b2 = 0x0A;
64
+ int32_t i2;
65
+ int32_t j2;
66
+ size_t s2;
67
+
68
+ s2 = sizeof(i2++); // Non-compliant (rule 13.6)
69
+ s2 = sizeof(i2--); // Non-compliant (rule 13.6)
70
+ s2 = sizeof(++i2); // Non-compliant (rule 13.6)
71
+ s2 = sizeof(i2--); // Non-compliant (rule 13.6)
72
+ s2 = sizeof(j2 = i2); // Non-compliant (rule 13.6)
73
+ s2 = sizeof(j2 += i2); // Non-compliant (rule 13.6)
74
+ s2 = sizeof(j2 -= 2); // Non-compliant (rule 13.6)
75
+ s2 = sizeof(j2 *= 2); // Non-compliant (rule 13.6)
76
+ s2 = sizeof(j2 /= 2); // Non-compliant (rule 13.6)
77
+ s2 = sizeof(j2 %= 2); // Non-compliant (rule 13.6)
78
+ s2 = sizeof(a2 <<= 1); // Non-compliant (rule 13.6)
79
+ s2 = sizeof(a2 >>= 1); // Non-compliant (rule 13.6)
80
+ s2 = sizeof(b2 &= 0xAB); // Non-compliant (rule 13.6)
81
+ s2 = sizeof(b2 ^= 0xAB); // Non-compliant (rule 13.6)
82
+ s2 = sizeof(b2 |= 0xAB); // Non-compliant (rule 13.6)
83
+
84
+ // Function calls
85
+ s2 = sizeof(bar_13_6_4());
86
+ s2 = sizeof(foo_13_6_3(bar_13_6_4()));
87
+
88
+ // Declaration of variable-length array type; will not be corrected
89
+ s2 = sizeof(int32_t[ n++ ]); // Non-compliant (rule 13.6)
90
+ }
91
+ `;
92
+
93
+ const files: TestFile[] = [
94
+ { name: "misraExample.c", code: misraExample},
95
+ { name: "bad.c", code: failingCode },
96
+ { name: "good.c", code: passingCode }
97
+ ];
98
+
99
+ describe("Rule 13.6", () => {
100
+ registerSourceCode(files);
101
+
102
+ it("should detect errors in bad.c", () => {
103
+ expect(countMISRAErrors()).toBe(21);
104
+ expect(countMISRAErrors("13.6")).toBe(21);
105
+
106
+ expect(countMISRAErrors(Query.search(FileJp, {name: "misraExample.c"}).first()!)).toBe(2);
107
+ expect(countMISRAErrors(Query.search(FileJp, {name: "bad.c"}).first()!)).toBe(19);
108
+ expect(countMISRAErrors(Query.search(FileJp, {name: "good.c"}).first()!)).toBe(0);
109
+ });
110
+
111
+ it("should correct errors in bad.c", () => {
112
+ expect(countErrorsAfterCorrection()).toBe(2);
113
+ });
114
+ });
@@ -2,8 +2,8 @@ import Query from "@specs-feup/lara/api/weaver/Query.js";
2
2
  import { countErrorsAfterCorrection, countMISRAErrors, registerSourceCode, TestFile } from "../utils.js";
3
3
  import { FileJp } from "@specs-feup/clava/api/Joinpoints.js";
4
4
 
5
- const passingCode =
6
- `void foo1( void ) {
5
+ const passingCode = `
6
+ static void foo1( void ) {
7
7
  int x, y;
8
8
  switch ( x )
9
9
  {
@@ -15,10 +15,11 @@ const passingCode =
15
15
  default:
16
16
  break;
17
17
  }
18
- }`;
18
+ }
19
+ `;
19
20
 
20
21
  const failingCode =
21
- `void foo2( void ) {
22
+ `static void foo2( void ) {
22
23
  int x, y;
23
24
  switch ( x )
24
25
  {
@@ -32,7 +33,8 @@ const failingCode =
32
33
  default:
33
34
  break;
34
35
  }
35
- }`;
36
+ }
37
+ `;
36
38
 
37
39
  const files: TestFile[] = [
38
40
  { name: "bad.c", code: failingCode },