@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,54 @@
1
+ import { Program, TypedefDecl } from "@specs-feup/clava/api/Joinpoints.js";
2
+ import { getIdentifierName, isIdentifierDuplicated, isIdentifierNameDeclaredBefore } from "../../utils/IdentifierUtils.js";
3
+ import { getTypeDefDecl } from "../../utils/TypeDeclUtils.js";
4
+ import Query from "@specs-feup/lara/api/weaver/Query.js";
5
+ import { isTagDecl } from "../../utils/JoinpointUtils.js";
6
+ import { getIdentifierDecls } from "../../utils/ProgramUtils.js";
7
+ import IdentifierRenameRule from "./IdentifierRenameRule.js";
8
+ import { AnalysisType } from "../../MISRA.js";
9
+ /**
10
+ * MISRA-C Rule 5.6: A typedef name shall be a unique identifier.
11
+ *
12
+ * Exception: The typedef name may be the same as the structure, union or enumeration tag name associated with the typedef.
13
+ */
14
+ export default class Rule_5_6_UniqueTypedefNames extends IdentifierRenameRule {
15
+ /**
16
+ * Scope of analysis
17
+ */
18
+ analysisType = AnalysisType.SYSTEM;
19
+ /**
20
+ * @returns Rule identifier according to MISRA-C:2012
21
+ */
22
+ get name() {
23
+ return "5.6";
24
+ }
25
+ /**
26
+ *
27
+ * @param $jp - Joinpoint to analyze
28
+ * @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
29
+ * @returns Returns true if the joinpoint violates the rule, false otherwise
30
+ */
31
+ match($jp, logErrors = false) {
32
+ if (!($jp instanceof Program))
33
+ return false;
34
+ const typedefDecls = Query.search(TypedefDecl).get();
35
+ this.invalidIdentifiers = getIdentifierDecls().filter((identifierJp) => {
36
+ if (isTagDecl(identifierJp)) {
37
+ return typedefDecls.filter((decl) => getIdentifierName(identifierJp) === getIdentifierName(decl) &&
38
+ getTypeDefDecl(identifierJp)?.astId !== decl.astId).length > 0;
39
+ }
40
+ else if (identifierJp instanceof TypedefDecl) {
41
+ return isIdentifierNameDeclaredBefore(identifierJp, typedefDecls);
42
+ }
43
+ return isIdentifierDuplicated(identifierJp, typedefDecls);
44
+ });
45
+ const nonCompliant = this.invalidIdentifiers.length > 0;
46
+ if (nonCompliant && logErrors) {
47
+ this.invalidIdentifiers.forEach(identifierJp => {
48
+ this.logMISRAError(identifierJp, `Identifier '${getIdentifierName(identifierJp)}' is also the name of a typedef. Typedef identifiers must not be reused.`);
49
+ });
50
+ }
51
+ return nonCompliant;
52
+ }
53
+ }
54
+ //# sourceMappingURL=Rule_5_6_UniqueTypedefNames.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rule_5_6_UniqueTypedefNames.js","sourceRoot":"","sources":["../../../src/rules/Section5_Identifiers/Rule_5_6_UniqueTypedefNames.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AACtF,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,8BAA8B,EAAE,MAAM,gCAAgC,CAAC;AAC3H,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,KAAK,MAAM,sCAAsC,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,oBAAoB,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,2BAA4B,SAAQ,oBAAoB;IACzE;;OAEG;IACM,YAAY,GAAG,YAAY,CAAC,MAAM,CAAC;IAE5C;;OAEG;IACH,IAAa,IAAI;QACb,OAAO,KAAK,CAAC;IACjB,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,GAAc,EAAE,YAAqB,KAAK;QAC5C,IAAI,CAAC,CAAC,GAAG,YAAY,OAAO,CAAC;YAAE,OAAO,KAAK,CAAC;QAE5C,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,GAAG,EAAE,CAAC;QAErD,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,EAAE,CAAC,MAAM,CAAC,CAAC,YAAY,EAAE,EAAE;YAEnE,IAAI,SAAS,CAAC,YAAY,CAAC,EAAE,CAAC;gBAC1B,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAChC,iBAAiB,CAAC,YAAY,CAAC,KAAK,iBAAiB,CAAC,IAAI,CAAC;oBAC3D,cAAc,CAAC,YAAY,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC,KAAK,CACrD,CAAC,MAAM,GAAG,CAAC,CAAA;YAChB,CAAC;iBACI,IAAI,YAAY,YAAY,WAAW,EAAE,CAAC;gBAC3C,OAAO,8BAA8B,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;YACtE,CAAC;YACD,OAAO,sBAAsB,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;QAC9D,CAAC,CAAC,CAAC;QAEH,MAAM,YAAY,GAAG,IAAI,CAAC,kBAAkB,CAAC,MAAM,GAAG,CAAC,CAAC;QAExD,IAAI,YAAY,IAAI,SAAS,EAAE,CAAC;YAC5B,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE;gBAC3C,IAAI,CAAC,aAAa,CAAC,YAAY,EAAE,eAAe,iBAAiB,CAAC,YAAY,CAAC,0EAA0E,CAAC,CAAC;YAC/J,CAAC,CAAC,CAAA;QACN,CAAC;QACD,OAAO,YAAY,CAAC;IACxB,CAAC;CACJ"}
@@ -0,0 +1,27 @@
1
+ import { Joinpoint } from "@specs-feup/clava/api/Joinpoints.js";
2
+ import IdentifierRenameRule from "./IdentifierRenameRule.js";
3
+ import { AnalysisType } from "../../MISRA.js";
4
+ /**
5
+ * MISRA-C Rule 5.7: A tag name shall be a unique identifier.
6
+ *
7
+ * Exception: The tag name may be the same as the typedef name with which it is associated.
8
+ */
9
+ export default class Rule_5_7_UniqueTagNames extends IdentifierRenameRule {
10
+ /**
11
+ * Scope of analysis
12
+ */
13
+ readonly analysisType = AnalysisType.SYSTEM;
14
+ /**
15
+ * @returns Rule identifier according to MISRA-C:2012
16
+ */
17
+ get name(): string;
18
+ /**
19
+ * Checks whether the given joinpoint represents an identifier that has the same name as any tag (i.e., enum, union or struct)
20
+ *
21
+ * @param $jp - Joinpoint to analyze
22
+ * @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
23
+ * @returns Returns true if the joinpoint violates the rule, false otherwise
24
+ */
25
+ match($jp: Joinpoint, logErrors?: boolean): boolean;
26
+ }
27
+ //# sourceMappingURL=Rule_5_7_UniqueTagNames.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rule_5_7_UniqueTagNames.d.ts","sourceRoot":"","sources":["../../../src/rules/Section5_Identifiers/Rule_5_7_UniqueTagNames.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAwB,MAAM,qCAAqC,CAAC;AAMtF,OAAO,oBAAoB,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,uBAAwB,SAAQ,oBAAoB;IACrE;;OAEG;IACH,QAAQ,CAAC,YAAY,uBAAuB;IAE5C;;OAEG;IACH,IAAa,IAAI,IAAI,MAAM,CAE1B;IAED;;;;;;OAMG;IACH,KAAK,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,GAAE,OAAe,GAAG,OAAO;CA0B7D"}
@@ -0,0 +1,55 @@
1
+ import { Joinpoint, Program, TypedefDecl } from "@specs-feup/clava/api/Joinpoints.js";
2
+ import { getIdentifierName, isIdentifierDuplicated, isIdentifierNameDeclaredBefore } from "../../utils/IdentifierUtils.js";
3
+ import { getTypeDefDecl } from "../../utils/TypeDeclUtils.js";
4
+ import Query from "@specs-feup/lara/api/weaver/Query.js";
5
+ import { isTagDecl } from "../../utils/JoinpointUtils.js";
6
+ import { getIdentifierDecls } from "../../utils/ProgramUtils.js";
7
+ import IdentifierRenameRule from "./IdentifierRenameRule.js";
8
+ import { AnalysisType } from "../../MISRA.js";
9
+ /**
10
+ * MISRA-C Rule 5.7: A tag name shall be a unique identifier.
11
+ *
12
+ * Exception: The tag name may be the same as the typedef name with which it is associated.
13
+ */
14
+ export default class Rule_5_7_UniqueTagNames extends IdentifierRenameRule {
15
+ /**
16
+ * Scope of analysis
17
+ */
18
+ analysisType = AnalysisType.SYSTEM;
19
+ /**
20
+ * @returns Rule identifier according to MISRA-C:2012
21
+ */
22
+ get name() {
23
+ return "5.7";
24
+ }
25
+ /**
26
+ * Checks whether the given joinpoint represents an identifier that has the same name as any tag (i.e., enum, union or struct)
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, logErrors = false) {
33
+ if (!($jp instanceof Program))
34
+ return false;
35
+ const tagDecls = Query.search(Joinpoint, (jp => { return isTagDecl(jp); })).get();
36
+ this.invalidIdentifiers = getIdentifierDecls().filter((identifierJp) => {
37
+ if (identifierJp instanceof TypedefDecl) {
38
+ return tagDecls.filter((tag) => getIdentifierName(identifierJp) === getIdentifierName(tag) &&
39
+ getTypeDefDecl(tag)?.ast !== identifierJp.ast).length > 0;
40
+ }
41
+ else if (isTagDecl(identifierJp)) {
42
+ return isIdentifierNameDeclaredBefore(identifierJp, tagDecls);
43
+ }
44
+ return isIdentifierDuplicated(identifierJp, tagDecls);
45
+ });
46
+ const nonCompliant = this.invalidIdentifiers.length > 0;
47
+ if (nonCompliant && logErrors) {
48
+ this.invalidIdentifiers.forEach(identifierJp => {
49
+ this.logMISRAError(identifierJp, `Identifier '${getIdentifierName(identifierJp)}' is also the name of a tag. Tag identifiers must not be reused.`);
50
+ });
51
+ }
52
+ return nonCompliant;
53
+ }
54
+ }
55
+ //# sourceMappingURL=Rule_5_7_UniqueTagNames.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rule_5_7_UniqueTagNames.js","sourceRoot":"","sources":["../../../src/rules/Section5_Identifiers/Rule_5_7_UniqueTagNames.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AACtF,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,8BAA8B,EAAE,MAAM,gCAAgC,CAAC;AAC3H,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,KAAK,MAAM,sCAAsC,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,oBAAoB,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,uBAAwB,SAAQ,oBAAoB;IACrE;;OAEG;IACM,YAAY,GAAG,YAAY,CAAC,MAAM,CAAC;IAE5C;;OAEG;IACH,IAAa,IAAI;QACb,OAAO,KAAK,CAAC;IACjB,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,GAAc,EAAE,YAAqB,KAAK;QAC5C,IAAI,CAAC,CAAC,GAAG,YAAY,OAAO,CAAC;YAAE,OAAO,KAAK,CAAC;QAE5C,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,EAAE,CAAC,EAAE,GAAE,OAAO,SAAS,CAAC,EAAE,CAAC,CAAA,CAAA,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;QAC/E,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,EAAE,CAAC,MAAM,CAAC,CAAC,YAAY,EAAE,EAAE;YAEnE,IAAI,YAAY,YAAY,WAAW,EAAE,CAAC;gBACtC,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAC3B,iBAAiB,CAAC,YAAY,CAAC,KAAK,iBAAiB,CAAC,GAAG,CAAC;oBAC1D,cAAc,CAAC,GAAG,CAAC,EAAE,GAAG,KAAK,YAAY,CAAC,GAAG,CAChD,CAAC,MAAM,GAAG,CAAC,CAAC;YACjB,CAAC;iBACI,IAAI,SAAS,CAAC,YAAY,CAAC,EAAE,CAAC;gBAC/B,OAAO,8BAA8B,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;YAClE,CAAC;YACD,OAAO,sBAAsB,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;QAC1D,CAAC,CAAC,CAAC;QACH,MAAM,YAAY,GAAG,IAAI,CAAC,kBAAkB,CAAC,MAAM,GAAG,CAAC,CAAC;QAExD,IAAI,YAAY,IAAI,SAAS,EAAE,CAAC;YAC5B,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE;gBAC3C,IAAI,CAAC,aAAa,CAAC,YAAY,EAAE,eAAe,iBAAiB,CAAC,YAAY,CAAC,kEAAkE,CAAC,CAAC;YACvJ,CAAC,CAAC,CAAA;QACN,CAAC;QACD,OAAO,YAAY,CAAC;IACxB,CAAC;CACJ"}
@@ -0,0 +1,24 @@
1
+ import { Joinpoint } from "@specs-feup/clava/api/Joinpoints.js";
2
+ import IdentifierRenameRule from "./IdentifierRenameRule.js";
3
+ import { AnalysisType } from "../../MISRA.js";
4
+ /**
5
+ * MISRA-C Rule 5.8: Identifiers that define objects or functions with external linkage shall be unique
6
+ */
7
+ export default class Rule_5_8_UniqueExternalLinkIdentifiers extends IdentifierRenameRule {
8
+ /**
9
+ * Scope of analysis
10
+ */
11
+ readonly analysisType = AnalysisType.SYSTEM;
12
+ /**
13
+ * @returns Rule identifier according to MISRA-C:2012
14
+ */
15
+ get name(): string;
16
+ /**
17
+ *
18
+ * @param $jp - Joinpoint to analyze
19
+ * @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
20
+ * @returns Returns true if the joinpoint violates the rule, false otherwise
21
+ */
22
+ match($jp: Joinpoint, logErrors?: boolean): boolean;
23
+ }
24
+ //# sourceMappingURL=Rule_5_8_UniqueExternalLinkIdentifiers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rule_5_8_UniqueExternalLinkIdentifiers.d.ts","sourceRoot":"","sources":["../../../src/rules/Section5_Identifiers/Rule_5_8_UniqueExternalLinkIdentifiers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAW,MAAM,qCAAqC,CAAC;AAGzE,OAAO,oBAAoB,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,sCAAuC,SAAQ,oBAAoB;IACpF;;OAEG;IACH,QAAQ,CAAC,YAAY,uBAAuB;IAE3C;;MAEE;IACH,IAAa,IAAI,IAAI,MAAM,CAE1B;IAED;;;;;OAKG;IACH,KAAK,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,GAAE,OAAe,GAAG,OAAO;CAkB7D"}
@@ -0,0 +1,42 @@
1
+ import { Program } from "@specs-feup/clava/api/Joinpoints.js";
2
+ import { getIdentifierName, isExternalLinkageIdentifier, isIdentifierDuplicated, isIdentifierNameDeclaredBefore } from "../../utils/IdentifierUtils.js";
3
+ import { getExternalLinkageIdentifiers, getIdentifierDecls } from "../../utils/ProgramUtils.js";
4
+ import IdentifierRenameRule from "./IdentifierRenameRule.js";
5
+ import { AnalysisType } from "../../MISRA.js";
6
+ /**
7
+ * MISRA-C Rule 5.8: Identifiers that define objects or functions with external linkage shall be unique
8
+ */
9
+ export default class Rule_5_8_UniqueExternalLinkIdentifiers extends IdentifierRenameRule {
10
+ /**
11
+ * Scope of analysis
12
+ */
13
+ analysisType = AnalysisType.SYSTEM;
14
+ /**
15
+ * @returns Rule identifier according to MISRA-C:2012
16
+ */
17
+ get name() {
18
+ return "5.8";
19
+ }
20
+ /**
21
+ *
22
+ * @param $jp - Joinpoint to analyze
23
+ * @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
24
+ * @returns Returns true if the joinpoint violates the rule, false otherwise
25
+ */
26
+ match($jp, logErrors = false) {
27
+ if (!($jp instanceof Program))
28
+ return false;
29
+ const externalLinkageIdentifiers = getExternalLinkageIdentifiers();
30
+ this.invalidIdentifiers = getIdentifierDecls().filter((identifierJp) => isExternalLinkageIdentifier(identifierJp) ?
31
+ isIdentifierNameDeclaredBefore(identifierJp, externalLinkageIdentifiers) :
32
+ isIdentifierDuplicated(identifierJp, externalLinkageIdentifiers));
33
+ const nonCompliant = this.invalidIdentifiers.length > 0;
34
+ if (nonCompliant && logErrors) {
35
+ this.invalidIdentifiers.forEach(identifierJp => {
36
+ this.logMISRAError(identifierJp, `Identifier '${getIdentifierName(identifierJp)}' is already defined with external linkage in this or other file.`);
37
+ });
38
+ }
39
+ return nonCompliant;
40
+ }
41
+ }
42
+ //# sourceMappingURL=Rule_5_8_UniqueExternalLinkIdentifiers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rule_5_8_UniqueExternalLinkIdentifiers.js","sourceRoot":"","sources":["../../../src/rules/Section5_Identifiers/Rule_5_8_UniqueExternalLinkIdentifiers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,OAAO,EAAE,MAAM,qCAAqC,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,2BAA2B,EAAE,sBAAsB,EAAE,8BAA8B,EAAE,MAAM,gCAAgC,CAAC;AACxJ,OAAO,EAAE,6BAA6B,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAChG,OAAO,oBAAoB,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,sCAAuC,SAAQ,oBAAoB;IACpF;;OAEG;IACM,YAAY,GAAG,YAAY,CAAC,MAAM,CAAC;IAE3C;;MAEE;IACH,IAAa,IAAI;QACb,OAAO,KAAK,CAAC;IACjB,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,GAAc,EAAE,YAAqB,KAAK;QAC5C,IAAI,CAAC,CAAC,GAAG,YAAY,OAAO,CAAC;YAAE,OAAO,KAAK,CAAC;QAE5C,MAAM,0BAA0B,GAAG,6BAA6B,EAAE,CAAC;QACnE,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,EAAE,CAAC,MAAM,CAAC,CAAC,YAAY,EAAE,EAAE,CACrE,2BAA2B,CAAC,YAAY,CAAC,CAAC,CAAC;YACzC,8BAA8B,CAAC,YAAY,EAAE,0BAA0B,CAAC,CAAC,CAAC;YAC1E,sBAAsB,CAAC,YAAY,EAAE,0BAA0B,CAAC,CACnE,CAAC;QAEF,MAAM,YAAY,GAAG,IAAI,CAAC,kBAAkB,CAAC,MAAM,GAAG,CAAC,CAAC;QACxD,IAAI,YAAY,IAAI,SAAS,EAAE,CAAC;YAC5B,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE;gBAC3C,IAAI,CAAC,aAAa,CAAC,YAAY,EAAE,eAAe,iBAAiB,CAAC,YAAY,CAAC,mEAAmE,CAAC,CAAC;YACxJ,CAAC,CAAC,CAAA;QACN,CAAC;QACD,OAAO,YAAY,CAAC;IACxB,CAAC;CACJ"}
@@ -0,0 +1,24 @@
1
+ import { Joinpoint } from "@specs-feup/clava/api/Joinpoints.js";
2
+ import IdentifierRenameRule from "./IdentifierRenameRule.js";
3
+ import { AnalysisType } from "../../MISRA.js";
4
+ /**
5
+ * MISRA-C Rule 5.9: Identifiers that define objects or functions with internal linkage should be unique
6
+ */
7
+ export default class Rule_5_9_UniqueInternalLinkIdentifiers extends IdentifierRenameRule {
8
+ /**
9
+ * Scope of analysis
10
+ */
11
+ readonly analysisType = AnalysisType.SYSTEM;
12
+ /**
13
+ * @returns Rule identifier according to MISRA-C:2012
14
+ */
15
+ get name(): string;
16
+ /**
17
+ *
18
+ * @param $jp - Joinpoint to analyze
19
+ * @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
20
+ * @returns Returns true if the joinpoint violates the rule, false otherwise
21
+ */
22
+ match($jp: Joinpoint, logErrors?: boolean): boolean;
23
+ }
24
+ //# sourceMappingURL=Rule_5_9_UniqueInternalLinkIdentifiers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rule_5_9_UniqueInternalLinkIdentifiers.d.ts","sourceRoot":"","sources":["../../../src/rules/Section5_Identifiers/Rule_5_9_UniqueInternalLinkIdentifiers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAU,MAAM,qCAAqC,CAAC;AAGvE,OAAO,oBAAoB,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,sCAAuC,SAAQ,oBAAoB;IACpF;;OAEG;IACH,QAAQ,CAAC,YAAY,uBAAuB;IAE5C;;OAEG;IACH,IAAa,IAAI,IAAI,MAAM,CAE1B;IAED;;;;;OAKG;IACH,KAAK,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,GAAE,OAAe,GAAG,OAAO;CAkB7D"}
@@ -0,0 +1,42 @@
1
+ import { 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
+ * MISRA-C Rule 5.9: Identifiers that define objects or functions with internal linkage should be unique
8
+ */
9
+ export default class Rule_5_9_UniqueInternalLinkIdentifiers extends IdentifierRenameRule {
10
+ /**
11
+ * Scope of analysis
12
+ */
13
+ analysisType = AnalysisType.SYSTEM;
14
+ /**
15
+ * @returns Rule identifier according to MISRA-C:2012
16
+ */
17
+ get name() {
18
+ return "5.9";
19
+ }
20
+ /**
21
+ *
22
+ * @param $jp - Joinpoint to analyze
23
+ * @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
24
+ * @returns Returns true if the joinpoint violates the rule, false otherwise
25
+ */
26
+ match($jp, logErrors = false) {
27
+ if (!($jp instanceof Program))
28
+ return false;
29
+ const internalLinkageIdentifiers = getInternalLinkageIdentifiers();
30
+ this.invalidIdentifiers = getIdentifierDecls().filter((identifierJp) => isInternalLinkageIdentifier(identifierJp) ?
31
+ isIdentifierNameDeclaredBefore(identifierJp, internalLinkageIdentifiers) :
32
+ isIdentifierDuplicated(identifierJp, internalLinkageIdentifiers));
33
+ const nonCompliant = this.invalidIdentifiers.length > 0;
34
+ if (nonCompliant && logErrors) {
35
+ this.invalidIdentifiers.forEach(identifierJp => {
36
+ this.logMISRAError(identifierJp, `Identifier '${getIdentifierName(identifierJp)}' is already defined with internal linkage in this or other file.`);
37
+ });
38
+ }
39
+ return nonCompliant;
40
+ }
41
+ }
42
+ //# sourceMappingURL=Rule_5_9_UniqueInternalLinkIdentifiers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rule_5_9_UniqueInternalLinkIdentifiers.js","sourceRoot":"","sources":["../../../src/rules/Section5_Identifiers/Rule_5_9_UniqueInternalLinkIdentifiers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,OAAO,EAAC,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,6BAA6B,EAAE,MAAM,6BAA6B,CAAC;AAChG,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,8BAA8B,EAAE,2BAA2B,EAAE,MAAM,gCAAgC,CAAC;AACxJ,OAAO,oBAAoB,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,sCAAuC,SAAQ,oBAAoB;IACpF;;OAEG;IACM,YAAY,GAAG,YAAY,CAAC,MAAM,CAAC;IAE5C;;OAEG;IACH,IAAa,IAAI;QACb,OAAO,KAAK,CAAC;IACjB,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,GAAc,EAAE,YAAqB,KAAK;QAC5C,IAAI,CAAC,CAAC,GAAG,YAAY,OAAO,CAAC;YAAE,OAAO,KAAK,CAAC;QAE5C,MAAM,0BAA0B,GAAG,6BAA6B,EAAE,CAAC;QACnE,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,EAAE,CAAC,MAAM,CAAC,CAAC,YAAY,EAAE,EAAE,CACnE,2BAA2B,CAAC,YAAY,CAAC,CAAC,CAAC;YACvC,8BAA8B,CAAC,YAAY,EAAE,0BAA0B,CAAC,CAAC,CAAC;YAC1E,sBAAsB,CAAC,YAAY,EAAE,0BAA0B,CAAC,CACvE,CAAC;QAEF,MAAM,YAAY,GAAG,IAAI,CAAC,kBAAkB,CAAC,MAAM,GAAG,CAAC,CAAC;QACxD,IAAI,YAAY,IAAI,SAAS,EAAE,CAAC;YAC5B,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE;gBAC3C,IAAI,CAAC,aAAa,CAAC,YAAY,EAAE,eAAe,iBAAiB,CAAC,YAAY,CAAC,mEAAmE,CAAC,CAAC;YACxJ,CAAC,CAAC,CAAA;QACN,CAAC;QACD,OAAO,YAAY,CAAC;IACxB,CAAC;CACJ"}
@@ -0,0 +1,35 @@
1
+ import { Joinpoint } from "@specs-feup/clava/api/Joinpoints.js";
2
+ import MISRARule from "../../MISRARule.js";
3
+ import { AnalysisType, MISRATransformationReport } from "../../MISRA.js";
4
+ /**
5
+ * MISRA-C Rule 8.6: An identifier with external linkage shall have exactly one external definition
6
+ */
7
+ export default class Rule_8_6_SingleExternalDefinition extends MISRARule {
8
+ #private;
9
+ /**
10
+ * Scope of analysis
11
+ */
12
+ readonly analysisType = AnalysisType.SYSTEM;
13
+ /**
14
+ * A positive integer starting from 1 that indicates the rule's priority, determining the order in which rules are applied.
15
+ */
16
+ readonly priority = 2;
17
+ /**
18
+ * @returns Rule identifier according to MISRA-C:2012
19
+ */
20
+ get name(): string;
21
+ /**
22
+ *
23
+ * @param $jp - Joinpoint to analyze
24
+ * @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
25
+ * @returns Returns true if the joinpoint violates the rule, false otherwise
26
+ */
27
+ match($jp: Joinpoint, logErrors?: boolean): boolean;
28
+ /**
29
+ *
30
+ * @param $jp - Joinpoint to transform
31
+ * @returns Report detailing the transformation result
32
+ */
33
+ apply($jp: Joinpoint): MISRATransformationReport;
34
+ }
35
+ //# sourceMappingURL=Rule_8_6_SingleExternalDefinition.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rule_8_6_SingleExternalDefinition.d.ts","sourceRoot":"","sources":["../../../src/rules/Section8_DeclarationsAndDefinitions/Rule_8_6_SingleExternalDefinition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,SAAS,EAAkC,MAAM,qCAAqC,CAAC;AACxG,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,yBAAyB,EAA2B,MAAM,gBAAgB,CAAC;AAOlG;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,iCAAkC,SAAQ,SAAS;;IACpE;;OAEG;IACH,QAAQ,CAAC,YAAY,uBAAuB;IAE5C;;OAEG;IACH,QAAQ,CAAC,QAAQ,KAAK;IAItB;;OAEG;IACH,IAAa,IAAI,IAAI,MAAM,CAE1B;IAED;;;;;OAKG;IACH,KAAK,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,GAAE,OAAe,GAAG,OAAO;IAuB1D;;;;OAIG;IACH,KAAK,CAAC,GAAG,EAAE,SAAS,GAAG,yBAAyB;CAmDnD"}
@@ -0,0 +1,98 @@
1
+ import { FileJp, Program, StorageClass } 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 } 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
+ * MISRA-C Rule 8.6: An identifier with external linkage shall have exactly one external definition
11
+ */
12
+ export default class Rule_8_6_SingleExternalDefinition extends MISRARule {
13
+ /**
14
+ * Scope of analysis
15
+ */
16
+ analysisType = AnalysisType.SYSTEM;
17
+ /**
18
+ * A positive integer starting from 1 that indicates the rule's priority, determining the order in which rules are applied.
19
+ */
20
+ priority = 2;
21
+ #invalidDecls = [];
22
+ /**
23
+ * @returns Rule identifier according to MISRA-C:2012
24
+ */
25
+ get name() {
26
+ return "8.6";
27
+ }
28
+ /**
29
+ *
30
+ * @param $jp - Joinpoint to analyze
31
+ * @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
32
+ * @returns Returns true if the joinpoint violates the rule, false otherwise
33
+ */
34
+ match($jp, logErrors = false) {
35
+ if (!($jp instanceof Program)) {
36
+ return false;
37
+ }
38
+ const externalLinkageVars = getExternalLinkageVars();
39
+ this.#invalidDecls = externalLinkageVars.filter((decl1) => externalLinkageVars.some((decl2) => isSameVarDecl(decl1, decl2) &&
40
+ decl1.getAncestor("file").ast !== decl2.getAncestor("file").ast &&
41
+ compareLocation(decl2, decl1) < 0));
42
+ const nonCompliant = this.#invalidDecls.length > 0;
43
+ if (nonCompliant && logErrors) {
44
+ this.#invalidDecls.forEach(identifierJp => {
45
+ this.logMISRAError(identifierJp, `Identifier '${getIdentifierName(identifierJp)}' with external linkage is defined in multiple files.`);
46
+ });
47
+ }
48
+ return nonCompliant;
49
+ }
50
+ /**
51
+ *
52
+ * @param $jp - Joinpoint to transform
53
+ * @returns Report detailing the transformation result
54
+ */
55
+ apply($jp) {
56
+ if (!this.match($jp)) {
57
+ return new MISRATransformationReport(MISRATransformationType.NoChange);
58
+ }
59
+ let solved = false;
60
+ const uniqueDecls = this.#invalidDecls.reduce((acc, decl1) => acc.some(decl2 => isSameVarDecl(decl1, decl2)) ? acc : [...acc, decl1], []);
61
+ for (const decl of uniqueDecls) {
62
+ if (this.context.getRuleResult(this.ruleID, decl) === MISRATransformationType.NoChange) {
63
+ continue;
64
+ }
65
+ const filesWithInitialization = Query.search(FileJp, (fileJp) => {
66
+ return fileJp.descendants.some((jp) => isSameVarDecl(jp, decl) && jp.init !== undefined);
67
+ }).get();
68
+ if (filesWithInitialization.length > 1) {
69
+ const other = this.#invalidDecls.filter(identifier => isSameVarDecl(identifier, decl));
70
+ for (const varDecl of other) {
71
+ this.logMISRAError(varDecl, `Identifier '${getIdentifierName(varDecl)}' with external linkage has multiple definitions across files. Automatic correction cannot be applied due to multiple initializations.`);
72
+ this.context.addRuleResult(this.ruleID, varDecl, MISRATransformationType.NoChange);
73
+ }
74
+ }
75
+ else if (filesWithInitialization.length === 0) {
76
+ const other = this.#invalidDecls.filter(identifier => isSameVarDecl(decl, identifier));
77
+ other.forEach(varDecl => {
78
+ varDecl.setStorageClass(StorageClass.EXTERN);
79
+ });
80
+ solved = true;
81
+ }
82
+ else {
83
+ const other = getExternalLinkageVars().filter(identifierJp => isSameVarDecl(decl, identifierJp) &&
84
+ (identifierJp.getAncestor("file").ast !== filesWithInitialization[0].ast));
85
+ other.forEach(varDecl => {
86
+ varDecl.setStorageClass(StorageClass.EXTERN);
87
+ });
88
+ solved = true;
89
+ }
90
+ }
91
+ if (solved) {
92
+ resetCaches();
93
+ return new MISRATransformationReport(MISRATransformationType.DescendantChange);
94
+ }
95
+ return new MISRATransformationReport(MISRATransformationType.NoChange);
96
+ }
97
+ }
98
+ //# sourceMappingURL=Rule_8_6_SingleExternalDefinition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rule_8_6_SingleExternalDefinition.js","sourceRoot":"","sources":["../../../src/rules/Section8_DeclarationsAndDefinitions/Rule_8_6_SingleExternalDefinition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAa,OAAO,EAAE,YAAY,EAAW,MAAM,qCAAqC,CAAC;AACxG,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,yBAAyB,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAClG,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAE,WAAW,EAAwB,MAAM,6BAA6B,CAAC;AACxG,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,MAAM,sCAAsC,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,iCAAkC,SAAQ,SAAS;IACpE;;OAEG;IACM,YAAY,GAAG,YAAY,CAAC,MAAM,CAAC;IAE5C;;OAEG;IACM,QAAQ,GAAG,CAAC,CAAC;IAEtB,aAAa,GAAc,EAAE,CAAC;IAE9B;;OAEG;IACH,IAAa,IAAI;QACb,OAAO,KAAK,CAAC;IACjB,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,GAAc,EAAE,YAAqB,KAAK;QAC5C,IAAI,CAAC,CAAC,GAAG,YAAY,OAAO,CAAC,EAAE,CAAC;YAC5B,OAAO,KAAK,CAAC;QACjB,CAAC;QAED,MAAM,mBAAmB,GAAG,sBAAsB,EAAE,CAAC;QACrD,IAAI,CAAC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CAAA;gBAChD,CAAC,CAAC,CAAC;gBACH,MAAM,GAAG,IAAI,CAAC;YAClB,CAAC;iBACI,CAAC;gBACF,MAAM,KAAK,GAAG,sBAAsB,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CACzD,aAAa,CAAC,IAAI,EAAE,YAAY,CAAC;oBACjC,CAAC,YAAY,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,uBAAuB,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAC5E,CAAC;gBACF,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;oBACpB,OAAO,CAAC,eAAe,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;gBACjD,CAAC,CAAC,CAAC;gBACH,MAAM,GAAG,IAAI,CAAC;YAClB,CAAC;QACL,CAAC;QACD,IAAI,MAAM,EAAE,CAAC;YACT,WAAW,EAAE,CAAC;YACd,OAAO,IAAI,yBAAyB,CAAC,uBAAuB,CAAC,gBAAgB,CAAC,CAAC;QACnF,CAAC;QACD,OAAO,IAAI,yBAAyB,CAAC,uBAAuB,CAAC,QAAQ,CAAC,CAAC;IAC3E,CAAC;CACJ"}
@@ -0,0 +1,35 @@
1
+ import { Joinpoint } from "@specs-feup/clava/api/Joinpoints.js";
2
+ import MISRARule from "../../MISRARule.js";
3
+ import { AnalysisType, MISRATransformationReport } from "../../MISRA.js";
4
+ /**
5
+ * MISRA-C Rule 8.7: Functions and objects should not be defined with external linkage if they are referenced in only one translation unit
6
+ */
7
+ export default class Rule_8_7_RestrictExternalLinkage extends MISRARule {
8
+ #private;
9
+ /**
10
+ * Scope of analysis
11
+ */
12
+ readonly analysisType = AnalysisType.SYSTEM;
13
+ /**
14
+ * @returns Rule identifier according to MISRA-C:2012
15
+ */
16
+ get name(): string;
17
+ /**
18
+ *
19
+ * @param $jp - Joinpoint to analyze
20
+ * @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
21
+ * @returns Returns true if the joinpoint violates the rule, false otherwise
22
+ */
23
+ match($jp: Joinpoint, logErrors?: boolean): boolean;
24
+ /**
25
+ *
26
+ * @param $jp - Joinpoint to transform
27
+ * @returns Report detailing the transformation result
28
+ */
29
+ apply($jp: Joinpoint): MISRATransformationReport;
30
+ /**
31
+ * Removes unused external declarations (`extern`) of the current identifier found in other source files.
32
+ */
33
+ private removeExternalDeclarations;
34
+ }
35
+ //# sourceMappingURL=Rule_8_7_RestrictExternalLinkage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rule_8_7_RestrictExternalLinkage.d.ts","sourceRoot":"","sources":["../../../src/rules/Section8_DeclarationsAndDefinitions/Rule_8_7_RestrictExternalLinkage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,SAAS,EAA0C,MAAM,qCAAqC,CAAC;AACpH,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,yBAAyB,EAA2B,MAAM,gBAAgB,CAAC;AAMlG;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,gCAAiC,SAAQ,SAAS;;IACnE;;OAEG;IACH,QAAQ,CAAC,YAAY,uBAAuB;IAE5C;;OAEG;IACH,IAAa,IAAI,IAAI,MAAM,CAE1B;IAOD;;;;;OAKG;IACH,KAAK,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,GAAE,OAAe,GAAG,OAAO;IAkB1D;;;;OAIG;IACH,KAAK,CAAC,GAAG,EAAE,SAAS,GAAG,yBAAyB;IAqBhD;;OAEG;IACH,OAAO,CAAC,0BAA0B;CAMrC"}
@@ -0,0 +1,76 @@
1
+ import { FunctionJp, 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, 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
+ * MISRA-C Rule 8.7: Functions and objects should not be defined with external linkage if they are referenced in only one translation unit
10
+ */
11
+ export default class Rule_8_7_RestrictExternalLinkage extends MISRARule {
12
+ /**
13
+ * Scope of analysis
14
+ */
15
+ analysisType = AnalysisType.SYSTEM;
16
+ /**
17
+ * @returns Rule identifier according to MISRA-C:2012
18
+ */
19
+ get name() {
20
+ return "8.7";
21
+ }
22
+ /**
23
+ * External declarations (`extern`) of the current identifier found in other source files.
24
+ */
25
+ #externalDecls = [];
26
+ /**
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, logErrors = false) {
33
+ if (!isExternalLinkageIdentifier($jp) || ($jp instanceof FunctionJp && $jp.name === "main")) {
34
+ return false;
35
+ }
36
+ this.#externalDecls = $jp instanceof Vardecl ? findExternalVarRefs($jp) : findExternalFunctionDecl($jp);
37
+ const isUsed = this.#externalDecls.some(decl => decl instanceof Vardecl ? isVarUsed(decl) : isFunctionUsed(decl));
38
+ const nonCompliant = this.#externalDecls.length === 0 || !isUsed;
39
+ if (nonCompliant && logErrors) {
40
+ this.logMISRAError($jp, `${$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.`);
41
+ 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.`));
42
+ }
43
+ return nonCompliant;
44
+ }
45
+ /**
46
+ *
47
+ * @param $jp - Joinpoint to transform
48
+ * @returns Report detailing the transformation result
49
+ */
50
+ apply($jp) {
51
+ const previousResult = this.context.getRuleResult(this.ruleID, $jp);
52
+ if (previousResult === MISRATransformationType.NoChange || !this.match($jp)) {
53
+ return new MISRATransformationReport(MISRATransformationType.NoChange);
54
+ }
55
+ this.removeExternalDeclarations();
56
+ if ($jp instanceof Vardecl && hasMultipleExternalLinkDeclarations($jp)) {
57
+ this.logMISRAError($jp, `${$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.`);
58
+ this.context.addRuleResult(this.ruleID, $jp, MISRATransformationType.NoChange);
59
+ return new MISRATransformationReport(MISRATransformationType.NoChange);
60
+ }
61
+ const identifierJp = $jp;
62
+ identifierJp.setStorageClass(StorageClass.STATIC);
63
+ resetCaches();
64
+ return new MISRATransformationReport(MISRATransformationType.DescendantChange);
65
+ }
66
+ /**
67
+ * Removes unused external declarations (`extern`) of the current identifier found in other source files.
68
+ */
69
+ removeExternalDeclarations() {
70
+ if (this.#externalDecls.length > 0 && this.#externalDecls[0] instanceof Vardecl) {
71
+ resetExternalVarRefs();
72
+ }
73
+ this.#externalDecls.forEach(decl => decl instanceof FunctionJp ? decl.detach() : decl.parent.detach());
74
+ }
75
+ }
76
+ //# sourceMappingURL=Rule_8_7_RestrictExternalLinkage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rule_8_7_RestrictExternalLinkage.js","sourceRoot":"","sources":["../../../src/rules/Section8_DeclarationsAndDefinitions/Rule_8_7_RestrictExternalLinkage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAsB,YAAY,EAAE,OAAO,EAAU,MAAM,qCAAqC,CAAC;AACpH,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,yBAAyB,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAClG,OAAO,EAAE,iBAAiB,EAAE,2BAA2B,EAAE,MAAM,gCAAgC,CAAC;AAChG,OAAO,E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AAC,gBAAgB,CAAC,CAAC;IACnF,CAAC;IAED;;OAEG;IACK,0BAA0B;QAC9B,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,YAAY,OAAO,EAAE,CAAC;YAC9E,oBAAoB,EAAE,CAAC;QAC3B,CAAC;QACD,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,YAAY,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IAC3G,CAAC;CACJ"}
@@ -0,0 +1,32 @@
1
+ import { Joinpoint } from "@specs-feup/clava/api/Joinpoints.js";
2
+ import MISRARule from "../../MISRARule.js";
3
+ import { AnalysisType, MISRATransformationReport } from "../../MISRA.js";
4
+ /**
5
+ * MISRA-C Rule 8.9: An object should be defined at block scope if its identifier only appears in a single function
6
+ */
7
+ export default class Rule_8_9_BlockScopeDefinition extends MISRARule {
8
+ /**
9
+ * Scope of analysis
10
+ */
11
+ readonly analysisType = AnalysisType.SYSTEM;
12
+ /**
13
+ * @returns Rule identifier according to MISRA-C:2012
14
+ */
15
+ get name(): string;
16
+ /**
17
+ * Checks if the provided joinpoint represents an object definition with internal linkage, whose identifier only appears in a single function.
18
+ *
19
+ * @param $jp - Joinpoint to analyze
20
+ * @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
21
+ * @returns Returns true if the joinpoint violates the rule, false otherwise
22
+ */
23
+ match($jp: Joinpoint, logErrors?: boolean): boolean;
24
+ /**
25
+ * 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.
26
+ *
27
+ * @param $jp - Joinpoint to transform
28
+ * @returns Report detailing the transformation result
29
+ */
30
+ apply($jp: Joinpoint): MISRATransformationReport;
31
+ }
32
+ //# sourceMappingURL=Rule_8_9_BlockScopeDefinition.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rule_8_9_BlockScopeDefinition.d.ts","sourceRoot":"","sources":["../../../src/rules/Section8_DeclarationsAndDefinitions/Rule_8_9_BlockScopeDefinition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,SAAS,EAAW,MAAM,qCAAqC,CAAC;AAClF,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,yBAAyB,EAA2B,MAAM,gBAAgB,CAAC;AAMlG;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,6BAA8B,SAAQ,SAAS;IAChE;;OAEG;IACH,QAAQ,CAAC,YAAY,uBAAuB;IAE5C;;OAEG;IACH,IAAa,IAAI,IAAI,MAAM,CAE1B;IAED;;;;;;OAMG;IACH,KAAK,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,GAAE,OAAe,GAAG,OAAO;IAa1D;;;;;OAKG;IACH,KAAK,CAAC,GAAG,EAAE,SAAS,GAAG,yBAAyB;CAcnD"}