@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,63 @@
1
+ import { PointerType, ArrayType, RecordJp, EnumDecl, QualType, Include } from "@specs-feup/clava/api/Joinpoints.js";
2
+ export function isTagDecl($jp) {
3
+ return $jp instanceof RecordJp || $jp instanceof EnumDecl;
4
+ }
5
+ /**
6
+ * Checks if the provided node has a defined type
7
+ * @param $jp The joinpoint to check its type
8
+ * @returns true if the joinpoint has a defined type, otherwise false
9
+ */
10
+ export function hasDefinedType($jp) {
11
+ return $jp.hasType && $jp.type !== null && $jp.type !== undefined;
12
+ }
13
+ /**
14
+ * Retrieves the base type of the provided joinpoint.
15
+ * @param $jp The joinpoint to retrieve its type
16
+ * @returns The base type of the joinpoint, or undefined if the joinpoint does not have a type
17
+ */
18
+ export function getBaseType($jp) {
19
+ if (!hasDefinedType($jp))
20
+ return undefined;
21
+ let jpType = $jp.type instanceof QualType ? $jp.type.unqualifiedType : $jp.type;
22
+ while (jpType instanceof PointerType || jpType instanceof ArrayType) {
23
+ jpType = jpType instanceof PointerType ? jpType.pointee : jpType.elementType;
24
+ }
25
+ return jpType;
26
+ }
27
+ /**
28
+ * Gets the file path of the given join point.
29
+ * @param $jp The join point
30
+ * @returns The file path string
31
+ */
32
+ export function getFilepath($jp) {
33
+ return $jp instanceof Include ? $jp.parent.filepath : $jp.filepath;
34
+ }
35
+ /**
36
+ * Returns the exact location of a given join point
37
+ * @param $jp The joinpoint to evaluate
38
+ * @returns A location string containing the filepath, line and column in the format "filepath@line:column"
39
+ */
40
+ export function getFileLocation($jp) {
41
+ if ($jp instanceof Include && $jp.line === undefined) {
42
+ return `${$jp.parent?.filepath}`;
43
+ }
44
+ return `${$jp.filepath}@${$jp.line}:${$jp.column}`;
45
+ }
46
+ /**
47
+ * Orders two join points by their source location: filepath, line, and column
48
+ *
49
+ * @param $jp1 The first join point
50
+ * @param $jp2 The second join point
51
+ * @returns A negative value if $jp1 comes before $jp2, positive if after, or 0 if equal.
52
+ */
53
+ export function compareLocation($jp1, $jp2) {
54
+ const filepath1 = getFilepath($jp1), filepath2 = getFilepath($jp2);
55
+ if (filepath1 !== filepath2)
56
+ return getFileLocation($jp1).localeCompare(getFileLocation($jp2));
57
+ if (($jp1 instanceof Include) && !($jp2 instanceof Include))
58
+ return -1;
59
+ if (!($jp1 instanceof Include) && ($jp2 instanceof Include))
60
+ return 1;
61
+ return $jp1.line !== $jp2.line ? $jp1.line - $jp2.line : $jp1.column - $jp2.column;
62
+ }
63
+ //# sourceMappingURL=JoinpointUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JoinpointUtils.js","sourceRoot":"","sources":["../../src/utils/JoinpointUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAqB,QAAQ,EAAE,OAAO,EAAE,MAAM,qCAAqC,CAAC;AAIxJ,MAAM,UAAU,SAAS,CAAC,GAAc;IACpC,OAAO,GAAG,YAAY,QAAQ,IAAI,GAAG,YAAY,QAAQ,CAAC;AAC9D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,GAAc;IACzC,OAAO,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,IAAI,KAAK,IAAI,IAAI,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC;AACtE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,GAAc;IACtC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC;QAAE,OAAO,SAAS,CAAC;IAC3C,IAAI,MAAM,GAAG,GAAG,CAAC,IAAI,YAAY,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC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AEtE,OAAO,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;AACvF,CAAC"}
@@ -0,0 +1,39 @@
1
+ import { Vardecl, FunctionJp } from "@specs-feup/clava/api/Joinpoints.js";
2
+ /**
3
+ * Clears all cached identifiers and variable references
4
+ */
5
+ export declare function resetCaches(): void;
6
+ /**
7
+ * Clears the cache of external variable references
8
+ */
9
+ export declare function resetExternalVarRefs(): void;
10
+ /**
11
+ * Retrieves all variables and functions that are eligible for `extern` linkage, i.e.,
12
+ * elements with storage classes that are not `STATIC` or `EXTERN`
13
+ *
14
+ * @returns Array of functions and variables that can be declared as external
15
+ */
16
+ export declare function getExternalLinkageIdentifiers(): (FunctionJp | Vardecl)[];
17
+ /**
18
+ * Gets identifiers with internal linkage
19
+ *
20
+ * @returns List of functions and variable declarations with internal linkage
21
+ */
22
+ export declare function getInternalLinkageIdentifiers(): (FunctionJp | Vardecl)[];
23
+ /**
24
+ * Gets identifiers with external linkage
25
+ *
26
+ * @returns List of functions and variable declarations with external linkage
27
+ */
28
+ export declare function getExternalLinkageVars(): Vardecl[];
29
+ /**
30
+ * Gets all variable declared with 'extern'
31
+ *
32
+ * @returns List of variable declarations with extern storage class
33
+ */
34
+ export declare function getExternalVarRefs(): Vardecl[];
35
+ /**
36
+ * Gets all named declarations and labels
37
+ */
38
+ export declare function getIdentifierDecls(): any[];
39
+ //# sourceMappingURL=ProgramUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProgramUtils.d.ts","sourceRoot":"","sources":["../../src/utils/ProgramUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAsC,MAAM,qCAAqC,CAAC;AAU9G;;GAEG;AACH,wBAAgB,WAAW,SAM1B;AAED;;GAEG;AACH,wBAAgB,oBAAoB,SAEnC;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,EAAE,CAaxE;AAED;;;;GAIG;AACH,wBAAgB,6BAA6B,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,EAAE,CAYxE;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,IAAI,OAAO,EAAE,CAMlD;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,IAAI,OAAO,EAAE,CAM9C;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,GAAG,EAAE,CAS1C"}
@@ -0,0 +1,97 @@
1
+ import { Vardecl, FunctionJp, LabelStmt, NamedDecl, StorageClass } from "@specs-feup/clava/api/Joinpoints.js";
2
+ import Query from "@specs-feup/lara/api/weaver/Query.js";
3
+ import { isExternalLinkageIdentifier, isIdentifierDecl, isInternalLinkageIdentifier } from "./IdentifierUtils.js";
4
+ let cachedInternalLinkageIdentifiers = null;
5
+ let cachedExternalLinkageIdentifiers = null;
6
+ let cachedExternalLinkageVars = null;
7
+ let cachedExternalVarRefs = null;
8
+ let cachedIdentifierDecls = null;
9
+ /**
10
+ * Clears all cached identifiers and variable references
11
+ */
12
+ export function resetCaches() {
13
+ cachedInternalLinkageIdentifiers = null;
14
+ cachedExternalLinkageIdentifiers = null;
15
+ cachedExternalLinkageVars = null;
16
+ cachedExternalVarRefs = null;
17
+ cachedIdentifierDecls = null;
18
+ }
19
+ /**
20
+ * Clears the cache of external variable references
21
+ */
22
+ export function resetExternalVarRefs() {
23
+ cachedExternalVarRefs = null;
24
+ }
25
+ /**
26
+ * Retrieves all variables and functions that are eligible for `extern` linkage, i.e.,
27
+ * elements with storage classes that are not `STATIC` or `EXTERN`
28
+ *
29
+ * @returns Array of functions and variables that can be declared as external
30
+ */
31
+ export function getExternalLinkageIdentifiers() {
32
+ if (cachedExternalLinkageIdentifiers !== null) {
33
+ return cachedExternalLinkageIdentifiers;
34
+ }
35
+ const externalLinkageVarDecls = getExternalLinkageVars();
36
+ const externalLinkageFunctions = Query.search(FunctionJp, (varDeclJp) => isExternalLinkageIdentifier(varDeclJp)).get();
37
+ cachedExternalLinkageIdentifiers = [
38
+ ...externalLinkageFunctions,
39
+ ...externalLinkageVarDecls
40
+ ];
41
+ return cachedExternalLinkageIdentifiers;
42
+ }
43
+ /**
44
+ * Gets identifiers with internal linkage
45
+ *
46
+ * @returns List of functions and variable declarations with internal linkage
47
+ */
48
+ export function getInternalLinkageIdentifiers() {
49
+ if (cachedInternalLinkageIdentifiers !== null) {
50
+ return cachedInternalLinkageIdentifiers;
51
+ }
52
+ const internalLinkageVarsDecls = Query.search(Vardecl, (decl) => isInternalLinkageIdentifier(decl)).get();
53
+ const internalLinkageFunctions = Query.search(FunctionJp, (decl) => isInternalLinkageIdentifier(decl)).get();
54
+ cachedInternalLinkageIdentifiers = [
55
+ ...internalLinkageFunctions,
56
+ ...internalLinkageVarsDecls
57
+ ];
58
+ return cachedInternalLinkageIdentifiers;
59
+ }
60
+ /**
61
+ * Gets identifiers with external linkage
62
+ *
63
+ * @returns List of functions and variable declarations with external linkage
64
+ */
65
+ export function getExternalLinkageVars() {
66
+ if (cachedExternalLinkageVars != null) {
67
+ return cachedExternalLinkageVars;
68
+ }
69
+ cachedExternalLinkageVars = Query.search(Vardecl, (varDeclJp) => isExternalLinkageIdentifier(varDeclJp)).get();
70
+ return cachedExternalLinkageVars;
71
+ }
72
+ /**
73
+ * Gets all variable declared with 'extern'
74
+ *
75
+ * @returns List of variable declarations with extern storage class
76
+ */
77
+ export function getExternalVarRefs() {
78
+ if (cachedExternalVarRefs !== null) {
79
+ return cachedExternalVarRefs;
80
+ }
81
+ cachedExternalVarRefs = Query.search(Vardecl, { storageClass: StorageClass.EXTERN }).get();
82
+ return cachedExternalVarRefs;
83
+ }
84
+ /**
85
+ * Gets all named declarations and labels
86
+ */
87
+ export function getIdentifierDecls() {
88
+ if (cachedIdentifierDecls !== null) {
89
+ return cachedIdentifierDecls;
90
+ }
91
+ cachedIdentifierDecls = [
92
+ ...Query.search(NamedDecl).get(),
93
+ ...Query.search(LabelStmt).get(),
94
+ ].filter((jp) => isIdentifierDecl(jp));
95
+ return cachedIdentifierDecls;
96
+ }
97
+ //# sourceMappingURL=ProgramUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProgramUtils.js","sourceRoot":"","sources":["../../src/utils/ProgramUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AAC9G,OAAO,KAAK,MAAM,sCAAsC,CAAC;AACzD,OAAO,EAAE,2BAA2B,EAAE,gBAAgB,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AAElH,IAAI,gCAAgC,GAAoC,IAAI,CAAC;AAC7E,IAAI,gCAAgC,GAAoC,IAAI,CAAC;AAC7E,IAAI,yBAAyB,GAAuB,IAAI,CAAC;AACzD,IAAI,qBAAqB,GAAuB,IAAI,CAAC;AACrD,IAAI,qBAAqB,GAAiB,IAAI,CAAC;AAE/C;;GAEG;AACH,MAAM,UAAU,WAAW;IACvB,gCAAgC,GAAG,IAAI,CAAC;IACxC,gCAAgC,GAAG,IAAI,CAAC;IACxC,yBAAyB,GAAG,IAAI,CAAC;IACjC,qBAAqB,GAAG,IAAI,CAAC;IAC7B,qBAAqB,GAAG,IAAI,CAAC;AACjC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB;IAChC,qBAAqB,GAAG,IAAI,CAAC;AACjC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,6BAA6B;IACzC,IAAI,gCAAgC,KAAK,IAAI,EAAE,CAAC;QAC5C,OAAO,gCAAgC,CAAC;IAC5C,CAAC;IAED,MAAM,uBAAuB,GAAG,sBAAsB,EAAE,CAAC;IACzD,MAAM,wBAAwB,GAAG,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE,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,YAAY,EAAE,YAAY,CAAC,MAAM,EAAC,CAAC,CAAC,GAAG,EAAE,CAAC;IACzF,OAAO,qBAAqB,CAAC;AACjC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB;IAC9B,IAAI,qBAAqB,KAAK,IAAI,EAAE,CAAC;QACjC,OAAO,qBAAqB,CAAC;IACjC,CAAC;IACD,qBAAqB,GAAG;QACpB,GAAG,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE;QAChC,GAAG,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE;KACnC,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC,CAAC;IACvC,OAAO,qBAAqB,CAAC;AACjC,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { Case, Joinpoint, Switch } from "@specs-feup/clava/api/Joinpoints.js";
2
+ /**
3
+ * Retrieves the last statement of the given case
4
+ * @param $jp - The case to retrieve the last statement from
5
+ * @returns The last statement of the case or undefined if there are no statements or it has a consecutive case.
6
+ */
7
+ export declare function getLastStmtOfCase($jp: Case): Joinpoint | undefined;
8
+ /**
9
+ * Retrieves the number of switch clauses with instructions in the provided switch statement
10
+ * @param $jp - The switch statement to analyze
11
+ * @returns The number of switch clauses with instructions
12
+ */
13
+ export declare function countSwitchClauses($jp: Switch): number;
14
+ /**
15
+ * Checks if the provided switch statement contains any conditional break
16
+ *
17
+ * @param switchStmt - The switch statement to analyze
18
+ * @returns Returns true if the switch statement contains a conditional break, otherwise false
19
+ */
20
+ export declare function hasConditionalBreak(switchStmt: Switch): boolean;
21
+ //# sourceMappingURL=SwitchUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SwitchUtils.d.ts","sourceRoot":"","sources":["../../src/utils/SwitchUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgC,IAAI,EAAE,SAAS,EAAE,MAAM,EAAW,MAAM,qCAAqC,CAAC;AAIrH;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,IAAI,GAAG,SAAS,GAAG,SAAS,CAelE;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAUtD;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAE/D"}
@@ -0,0 +1,47 @@
1
+ import { Break, Case } from "@specs-feup/clava/api/Joinpoints.js";
2
+ import Query from "@specs-feup/lara/api/weaver/Query.js";
3
+ /**
4
+ * Retrieves the last statement of the given case
5
+ * @param $jp - The case to retrieve the last statement from
6
+ * @returns The last statement of the case or undefined if there are no statements or it has a consecutive case.
7
+ */
8
+ export function getLastStmtOfCase($jp) {
9
+ if ($jp.instructions.length === 0) { // Has a consecutive case
10
+ return undefined;
11
+ }
12
+ let caseScopeStmts = [];
13
+ for (const stmt of $jp.siblingsRight) {
14
+ if (stmt instanceof Case) {
15
+ break;
16
+ }
17
+ caseScopeStmts.push(stmt);
18
+ }
19
+ return !caseScopeStmts.some(stmt => stmt instanceof Break) ?
20
+ caseScopeStmts[caseScopeStmts.length - 1] :
21
+ caseScopeStmts.find(stmt => stmt instanceof Break);
22
+ }
23
+ /**
24
+ * Retrieves the number of switch clauses with instructions in the provided switch statement
25
+ * @param $jp - The switch statement to analyze
26
+ * @returns The number of switch clauses with instructions
27
+ */
28
+ export function countSwitchClauses($jp) {
29
+ let firstStatements = [];
30
+ for (const caseLabel of $jp.cases) {
31
+ if (caseLabel.instructions.length === 0) { // Has a consecutive case
32
+ continue;
33
+ }
34
+ firstStatements.push(caseLabel.instructions[0]);
35
+ }
36
+ return firstStatements.length;
37
+ }
38
+ /**
39
+ * Checks if the provided switch statement contains any conditional break
40
+ *
41
+ * @param switchStmt - The switch statement to analyze
42
+ * @returns Returns true if the switch statement contains a conditional break, otherwise false
43
+ */
44
+ export function hasConditionalBreak(switchStmt) {
45
+ return Query.searchFrom(switchStmt, Break, { currentRegion: region => region.astId !== switchStmt.astId, enclosingStmt: jp => jp.astId === switchStmt.astId }).get().length > 0;
46
+ }
47
+ //# sourceMappingURL=SwitchUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SwitchUtils.js","sourceRoot":"","sources":["../../src/utils/SwitchUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,EAAe,IAAI,EAA8B,MAAM,qCAAqC,CAAC;AACrH,OAAO,KAAK,MAAM,sCAAsC,CAAC;AAGzD;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,GAAS;IACvC,IAAI,GAAG,CAAC,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC,CAAC,yBAAyB;QAC1D,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,IAAI,cAAc,GAAgB,EAAE,CAAC;IACrC,KAAK,MAAM,IAAI,IAAI,GAAG,CAAC,aAAa,EAAE,CAAC;QACnC,IAAI,IAAI,YAAY,IAAI,EAAE,CAAC;YACvB,MAAM;QACV,CAAC;QACD,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IACD,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,YAAY,KAAK,CAAC,CAAC,CAAC;QAChD,cAAc,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;QAC3C,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,YAAY,KAAK,CAAC,CAAC;AACnE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAW;IAC1C,IAAI,eAAe,GAAG,EAAE,CAAA;IAExB,KAAK,MAAM,SAAS,IAAI,GAAG,CAAC,KAAK,EAAE,CAAC;QAChC,IAAI,SAAS,CAAC,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC,CAAC,yBAAyB;YAChE,SAAS;QACb,CAAC;QACD,eAAe,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA;IACnD,CAAC;IACD,OAAO,eAAe,CAAC,MAAM,CAAC;AAClC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,UAAkB;IAClD,OAAO,KAAK,CAAC,UAAU,CAAC,UAAU,EAAE,KAAK,EAAE,EAAE,aAAa,EAAE,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,KAAK,UAAU,CAAC,KAAK,EAAE,aAAa,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,KAAK,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;AACpL,CAAC"}
@@ -0,0 +1,35 @@
1
+ import { Joinpoint, TypedefDecl } from "@specs-feup/clava/api/Joinpoints.js";
2
+ import { TagDecl } from "./JoinpointUtils.js";
3
+ /**
4
+ * Retrieves the typedef declaration for the provided joinpoint, if available
5
+ * @param $jp The joinpoint to analyze
6
+ * @returns The typedef declaration if found, or undefined if not
7
+ */
8
+ export declare function getTypeDefDecl($jp: Joinpoint): TypedefDecl | undefined;
9
+ /**
10
+ * Checks if the provided joinpoint declares a type (typedef)
11
+ * @param $jp The joinpoint to check
12
+ * @returns Returns true if the joinpoint declares a typedef, otherwise false
13
+ */
14
+ export declare function hasTypeDefDecl($jp: Joinpoint): boolean;
15
+ /**
16
+ * Checks if a given joinpoint uses the specified typedef declaration.
17
+ * @param jp - The joinpoint to check
18
+ * @param typeDecl - The typedef declaration to check against
19
+ * @returns Returns true if the joinpoint uses the given typedef declaration, false otherwise
20
+ */
21
+ export declare function jpUsesTypedef(jp: Joinpoint, typeDecl: TypedefDecl): boolean;
22
+ /**
23
+ * Checks if a given joinpoint uses the specified tag declaration
24
+ * @param $jp The joinpoint to analyze
25
+ * @param tag The tag to check against
26
+ * @returns Returns true if the joinpoint uses the given tag, false otherwise
27
+ */
28
+ export declare function jpUsesTag($jp: Joinpoint, tag: TagDecl): boolean;
29
+ /**
30
+ * Checks if the provided typedef or tag declaration is used in any part of the program
31
+ * @param decl - typedef or tag declaration to verify
32
+ * @returns Returns true if the declaration is used, false otherwise
33
+ */
34
+ export declare function isTypeDeclUsed(decl: TypedefDecl | TagDecl): boolean;
35
+ //# sourceMappingURL=TypeDeclUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TypeDeclUtils.d.ts","sourceRoot":"","sources":["../../src/utils/TypeDeclUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAA4F,MAAM,qCAAqC,CAAC;AAGvK,OAAO,EAAa,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAGzD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,SAAS,GAAG,WAAW,GAAG,SAAS,CAStE;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,SAAS,GAAG,OAAO,CAEtD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,GAAG,OAAO,CAO3E;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,GAAG,OAAO,CAc/D;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,GAAG,OAAO,CAcnE"}
@@ -0,0 +1,78 @@
1
+ import { TypedefDecl, DeclStmt, TypedefType, ElaboratedType, TagType, EnumDecl, EnumeratorDecl, Varref } from "@specs-feup/clava/api/Joinpoints.js";
2
+ import Query from "@specs-feup/lara/api/weaver/Query.js";
3
+ import { getBaseType } from "./JoinpointUtils.js";
4
+ import { isTagDecl } from "./JoinpointUtils.js";
5
+ import { findFilesReferencingHeader } from "./FileUtils.js";
6
+ /**
7
+ * Retrieves the typedef declaration for the provided joinpoint, if available
8
+ * @param $jp The joinpoint to analyze
9
+ * @returns The typedef declaration if found, or undefined if not
10
+ */
11
+ export function getTypeDefDecl($jp) {
12
+ if ($jp instanceof DeclStmt && $jp.children.length === 1 && $jp.children[0] instanceof TypedefDecl)
13
+ return $jp.children[0];
14
+ if (isTagDecl($jp)) {
15
+ const typeDecls = Query.searchFrom($jp, TypedefDecl).get();
16
+ if (typeDecls.length === 1)
17
+ return typeDecls[0];
18
+ }
19
+ }
20
+ /**
21
+ * Checks if the provided joinpoint declares a type (typedef)
22
+ * @param $jp The joinpoint to check
23
+ * @returns Returns true if the joinpoint declares a typedef, otherwise false
24
+ */
25
+ export function hasTypeDefDecl($jp) {
26
+ return getTypeDefDecl($jp) !== undefined;
27
+ }
28
+ /**
29
+ * Checks if a given joinpoint uses the specified typedef declaration.
30
+ * @param jp - The joinpoint to check
31
+ * @param typeDecl - The typedef declaration to check against
32
+ * @returns Returns true if the joinpoint uses the given typedef declaration, false otherwise
33
+ */
34
+ export function jpUsesTypedef(jp, typeDecl) {
35
+ const jpType = getBaseType(jp);
36
+ return !jpType?.isBuiltin && ((jpType instanceof TypedefType && jpType.decl.astId === typeDecl.astId) ||
37
+ (jpType instanceof ElaboratedType && jpType.namedType instanceof TypedefType && jpType.namedType.decl.astId === typeDecl.astId));
38
+ }
39
+ /**
40
+ * Checks if a given joinpoint uses the specified tag declaration
41
+ * @param $jp The joinpoint to analyze
42
+ * @param tag The tag to check against
43
+ * @returns Returns true if the joinpoint uses the given tag, false otherwise
44
+ */
45
+ export function jpUsesTag($jp, tag) {
46
+ if (tag instanceof EnumDecl && $jp instanceof Varref && getTypeDefDecl(tag) === undefined) {
47
+ const enumeratorsIDs = tag.enumerators.map(enumerator => enumerator.astId);
48
+ const decl = $jp.getValue("decl");
49
+ if (decl instanceof EnumeratorDecl && enumeratorsIDs.includes(decl.astId)) {
50
+ return true;
51
+ }
52
+ }
53
+ const jpType = getBaseType($jp);
54
+ return jpType instanceof ElaboratedType &&
55
+ jpType.namedType instanceof TagType &&
56
+ jpType.namedType.decl.astId === tag.astId &&
57
+ $jp.astId !== getTypeDefDecl(tag)?.astId;
58
+ }
59
+ /**
60
+ * Checks if the provided typedef or tag declaration is used in any part of the program
61
+ * @param decl - typedef or tag declaration to verify
62
+ * @returns Returns true if the declaration is used, false otherwise
63
+ */
64
+ export function isTypeDeclUsed(decl) {
65
+ const fileJp = decl.getAncestor("file");
66
+ let jps = [];
67
+ if (fileJp.isHeader) {
68
+ const referencingFiles = findFilesReferencingHeader(fileJp.name);
69
+ jps = [...fileJp.descendants, ...referencingFiles.flatMap(file => file.descendants)];
70
+ }
71
+ else {
72
+ jps = fileJp.descendants;
73
+ }
74
+ return decl instanceof TypedefDecl ?
75
+ jps.some(jp => jpUsesTypedef(jp, decl)) :
76
+ jps.some(jp => jpUsesTag(jp, decl));
77
+ }
78
+ //# sourceMappingURL=TypeDeclUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TypeDeclUtils.js","sourceRoot":"","sources":["../../src/utils/TypeDeclUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,cAAc,EAAE,OAAO,EAAU,QAAQ,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AACvK,OAAO,KAAK,MAAM,sCAAsC,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAW,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,0BAA0B,EAAqB,MAAM,gBAAgB,CAAC;AAE/E;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,GAAc;IACzC,IAAI,GAAG,YAAY,QAAQ,IAAI,GAAG,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,YAAY,WAAW;QAC9F,OAAO,GAAG,CA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
3
+ * Retrieves all variable references qualified as "volatile" starting from the given joinpoint
4
+ * @param $jp Starting joinpoint
5
+ * @returns Array of variable references qualified as volatile
6
+ */
7
+ export declare function getVolatileVarRefs($jp: Joinpoint): Varref[];
8
+ /**
9
+ * Retrieves all external references of the given variable
10
+ *
11
+ * @param $varDecl variable to match by name.
12
+ * @returns Array of external references with the same name as the given variable.
13
+ */
14
+ export declare function findExternalVarRefs($varDecl: Vardecl): Vardecl[];
15
+ /**
16
+ * Identifies functions in the same file that reference the specified variable declaration
17
+ *
18
+ * @param $jp The variable declaration
19
+ * @returns An array of functions that reference the variable
20
+ */
21
+ export declare function findReferencingFunctions($jp: Vardecl): FunctionJp[];
22
+ /**
23
+ * Finds duplicate definitions of the given variable declaration among external linkage variables
24
+ *
25
+ * @param $jp The variable declaration to evaluate
26
+ * @returns An array of variable declarations representing duplicates
27
+ */
28
+ export declare function findDuplicateVarDefinition($jp: Vardecl): Vardecl[];
29
+ /**
30
+ * Checks whether two joinpoints represent the same variable declaration by comparing identifier name, type, and external linkage
31
+ *
32
+ * @param $jp1 The first join point
33
+ * @param $jp2 The second join point
34
+ * @returns True if both are equivalent external variable declarations, false otherwise
35
+ */
36
+ export declare function isSameVarDecl($jp1: Joinpoint, $jp2: Joinpoint): boolean;
37
+ /**
38
+ * Checks if the given variable has multiple external linkage declarations across different files
39
+ *
40
+ * @param $jp The variable declaration to evaluate
41
+ * @returns True if multiple external declarations exist, false otherwise
42
+ */
43
+ export declare function hasMultipleExternalLinkDeclarations($jp: Vardecl): boolean;
44
+ /**
45
+ * Checks whether the given variable declaration is used in its file or in files that include its header.
46
+ *
47
+ * @param varDecl The variable declaration to check
48
+ * @returns True if the variable is referenced, false otherwise
49
+ */
50
+ export declare function isVarUsed(varDecl: Vardecl): boolean;
51
+ //# sourceMappingURL=VarUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VarUtils.d.ts","sourceRoot":"","sources":["../../src/utils/VarUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,UAAU,EAAE,SAAS,EAA0B,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAM7H;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,SAAS,GAAG,MAAM,EAAE,CAQ3D;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,OAAO,GAAG,OAAO,EAAE,CAEhE;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,OAAO,GAAG,UAAU,EAAE,CAQnE;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,EAAE,CAElE;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAKvE;AAED;;;;;GAKG;AAEH,wBAAgB,mCAAmC,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAIzE;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAWnD"}
@@ -0,0 +1,91 @@
1
+ import { FunctionJp, QualType, Vardecl, Varref } from "@specs-feup/clava/api/Joinpoints.js";
2
+ import Query from "@specs-feup/lara/api/weaver/Query.js";
3
+ import { getIdentifierName, isExternalLinkageIdentifier } from "./IdentifierUtils.js";
4
+ import { getExternalLinkageIdentifiers, getExternalLinkageVars, getExternalVarRefs } from "./ProgramUtils.js";
5
+ import { findFilesReferencingHeader } from "./FileUtils.js";
6
+ /**
7
+ * Retrieves all variable references qualified as "volatile" starting from the given joinpoint
8
+ * @param $jp Starting joinpoint
9
+ * @returns Array of variable references qualified as volatile
10
+ */
11
+ export function getVolatileVarRefs($jp) {
12
+ return Query.searchFromInclusive($jp, Varref, (ref) => {
13
+ try {
14
+ return ref.type instanceof QualType && ref.type.qualifiers?.includes("volatile");
15
+ }
16
+ catch (error) {
17
+ return false;
18
+ }
19
+ }).get();
20
+ }
21
+ /**
22
+ * Retrieves all external references of the given variable
23
+ *
24
+ * @param $varDecl variable to match by name.
25
+ * @returns Array of external references with the same name as the given variable.
26
+ */
27
+ export function findExternalVarRefs($varDecl) {
28
+ return getExternalVarRefs().filter(ref => ref.name === $varDecl.name);
29
+ }
30
+ /**
31
+ * Identifies functions in the same file that reference the specified variable declaration
32
+ *
33
+ * @param $jp The variable declaration
34
+ * @returns An array of functions that reference the variable
35
+ */
36
+ export function findReferencingFunctions($jp) {
37
+ const fileJp = $jp.getAncestor("file");
38
+ const functionsJp = Query.searchFrom(fileJp, FunctionJp).get();
39
+ return functionsJp
40
+ .filter(funcJp => Query.searchFrom(funcJp, Varref, { decl: (declJp) => declJp?.astId === $jp.astId }).get().length > 0);
41
+ }
42
+ /**
43
+ * Finds duplicate definitions of the given variable declaration among external linkage variables
44
+ *
45
+ * @param $jp The variable declaration to evaluate
46
+ * @returns An array of variable declarations representing duplicates
47
+ */
48
+ export function findDuplicateVarDefinition($jp) {
49
+ return getExternalLinkageVars().filter((varDeclJp) => varDeclJp.astId !== $jp.astId && isSameVarDecl(varDeclJp, $jp));
50
+ }
51
+ /**
52
+ * Checks whether two joinpoints represent the same variable declaration by comparing identifier name, type, and external linkage
53
+ *
54
+ * @param $jp1 The first join point
55
+ * @param $jp2 The second join point
56
+ * @returns True if both are equivalent external variable declarations, false otherwise
57
+ */
58
+ export function isSameVarDecl($jp1, $jp2) {
59
+ return $jp1 instanceof Vardecl && $jp2 instanceof Vardecl &&
60
+ isExternalLinkageIdentifier($jp1) && isExternalLinkageIdentifier($jp2) &&
61
+ getIdentifierName($jp1) === getIdentifierName($jp2) &&
62
+ $jp1.type.code === $jp2.type.code;
63
+ }
64
+ /**
65
+ * Checks if the given variable has multiple external linkage declarations across different files
66
+ *
67
+ * @param $jp The variable declaration to evaluate
68
+ * @returns True if multiple external declarations exist, false otherwise
69
+ */
70
+ export function hasMultipleExternalLinkDeclarations($jp) {
71
+ return getExternalLinkageIdentifiers().some(identifier => isSameVarDecl(identifier, $jp) && identifier.getAncestor("file").ast !== $jp.getAncestor("file").ast);
72
+ }
73
+ /**
74
+ * Checks whether the given variable declaration is used in its file or in files that include its header.
75
+ *
76
+ * @param varDecl The variable declaration to check
77
+ * @returns True if the variable is referenced, false otherwise
78
+ */
79
+ export function isVarUsed(varDecl) {
80
+ const fileJp = varDecl.getAncestor("file");
81
+ let referencingFiles;
82
+ if (fileJp.isHeader) {
83
+ const filesWithInclude = findFilesReferencingHeader(fileJp.name);
84
+ referencingFiles = [fileJp, ...filesWithInclude];
85
+ }
86
+ else {
87
+ referencingFiles = [fileJp];
88
+ }
89
+ return referencingFiles.some(fileJp => Query.searchFrom(fileJp, Varref, { name: varDecl.name, decl: (declJp) => declJp?.astId === varDecl.astId }).get().length > 0);
90
+ }
91
+ //# sourceMappingURL=VarUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VarUtils.js","sourceRoot":"","sources":["../../src/utils/VarUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,UAAU,EAAa,QAAQ,EAAgB,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAC7H,OAAO,KAAK,MAAM,sCAAsC,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AACtF,OAAO,EAAE,6BAA6B,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC9G,OAAO,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AAE5D;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAc;IAC7C,OAAO,KAAK,CAAC,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE;QAClD,IAAI,CAAC;YACD,OAAO,GAAG,CAAC,IAAI,YAAY,QAAQ,IAAI,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,UAAU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"@specs-feup/clava-misra",
3
- "version": "1.0.2",
4
- "author": "L. Sousa",
3
+ "version": "1.0.4",
4
+ "author": "Milena Gouveia",
5
5
  "description": "Clava library to automatically detect and correct violations of the MISRA-C:2012 standard in C code",
6
6
  "type": "module",
7
+ "exports": {
8
+ "./*": {
9
+ "types": "./dist/*.d.ts",
10
+ "default": "./dist/*.js"
11
+ }
12
+ },
7
13
  "files": [
8
14
  "dist",
9
15
  "src",
@@ -35,14 +41,17 @@
35
41
  "url": "git+https://github.com/specs-feup/clava-misra.git"
36
42
  },
37
43
  "dependencies": {
38
- "@specs-feup/clava": "^3.0.11",
39
- "@specs-feup/clava-visualization": "^1.0.5",
40
- "@specs-feup/lara": "^3.0.5"
44
+ "@specs-feup/clava": "3.0.26",
45
+ "@specs-feup/lara": "^3.0.11",
46
+ "@specs-feup/clava-flow": "^1.0.1",
47
+ "@specs-feup/flow": "^1.0.3"
41
48
  },
42
49
  "devDependencies": {
43
50
  "@jest/globals": "^29.7.0",
44
- "@specs-feup/clava": "^3.0.11",
45
- "@specs-feup/lara": "^3.0.4",
51
+ "@specs-feup/clava": "3.0.26",
52
+ "@specs-feup/lara": "^3.0.11",
53
+ "@specs-feup/clava-flow": "^1.0.1",
54
+ "@specs-feup/flow": "^1.0.3",
46
55
  "@types/jest": "^29.5.14",
47
56
  "@typescript-eslint/eslint-plugin": "^7.16.0",
48
57
  "@typescript-eslint/parser": "^7.16.0",