adlint 2.6.14 → 3.0.0

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 (401) hide show
  1. data/AUTHORS +1 -3
  2. data/ChangeLog +511 -0
  3. data/INSTALL +1 -1
  4. data/MANIFEST +57 -37
  5. data/NEWS +36 -7
  6. data/README +2 -2
  7. data/Rakefile +6 -6
  8. data/TODO +1 -1
  9. data/bin/adlint +25 -16
  10. data/bin/adlint_chk +22 -12
  11. data/bin/adlint_cma +17 -12
  12. data/bin/adlint_sma +22 -12
  13. data/bin/adlintize +98 -17
  14. data/etc/conf.d/fallback/cinit.erb +1 -1
  15. data/etc/conf.d/fallback/traits.erb +37 -37
  16. data/etc/conf.d/i686-cygwin/cinit-gcc_4.3.4.erb +1 -1
  17. data/etc/conf.d/i686-cygwin/traits-gcc_4.3.4.erb +41 -41
  18. data/etc/conf.d/i686-devkit/cinit-gcc_4.5.2.erb +1 -1
  19. data/etc/conf.d/i686-devkit/traits-gcc_4.5.2.erb +40 -40
  20. data/etc/conf.d/i686-linux/cinit-gcc_4.5.1.erb +1 -1
  21. data/etc/conf.d/i686-linux/traits-gcc_4.5.1.erb +40 -40
  22. data/etc/conf.d/i686-mingw/cinit-gcc_4.6.1.erb +1 -1
  23. data/etc/conf.d/i686-mingw/traits-gcc_4.6.1.erb +40 -40
  24. data/etc/conf.d/noarch/GNUmakefile.erb +1 -1
  25. data/etc/conf.d/noarch/adlint_all_bat.erb +1 -1
  26. data/etc/conf.d/noarch/adlint_all_sh.erb +1 -1
  27. data/etc/conf.d/noarch/pinit.erb +1 -1
  28. data/etc/conf.d/x86_64-ubuntu_12.04/cinit-gcc_4.6.3.erb +1 -1
  29. data/etc/conf.d/x86_64-ubuntu_12.04/traits-gcc_4.6.3.erb +42 -42
  30. data/etc/mesg.d/c_builtin/en_US/messages.yml +33 -33
  31. data/etc/mesg.d/c_builtin/ja_JP/messages.yml +5 -5
  32. data/etc/mesg.d/core/en_US/messages.yml +2 -2
  33. data/etc/mesg.d/core/ja_JP/messages.yml +2 -2
  34. data/features/code_check/W0018.feature +197 -0
  35. data/features/code_check/W0019.feature +79 -0
  36. data/features/code_check/W0021.feature +81 -0
  37. data/features/code_check/W0023.feature +203 -0
  38. data/features/code_check/W0024.feature +226 -0
  39. data/features/code_check/W0025.feature +5 -0
  40. data/features/code_check/W0088.feature +2 -2
  41. data/features/code_check/W0109.feature +2 -2
  42. data/features/code_check/W0477.feature +0 -3
  43. data/features/code_check/W0478.feature +0 -1
  44. data/features/code_check/W0582.feature +3 -3
  45. data/features/code_check/W0583.feature +4 -7
  46. data/features/code_check/W0646.feature +0 -1
  47. data/features/code_check/W0695.feature +0 -1
  48. data/features/code_check/W0705.feature +8 -0
  49. data/features/code_check/W0723.feature +0 -1
  50. data/features/code_check/W0745.feature +1 -0
  51. data/features/code_check/W0781.feature +1 -0
  52. data/features/code_check/W1057.feature +141 -0
  53. data/features/code_check/W1058.feature +93 -0
  54. data/features/code_check/W1059.feature +86 -0
  55. data/features/code_check/W1060.feature +77 -0
  56. data/features/code_check/W1061.feature +143 -0
  57. data/features/code_check/W1062.feature +162 -0
  58. data/features/code_check/W1063.feature +123 -0
  59. data/features/code_check/W1064.feature +83 -0
  60. data/features/code_check/W1065.feature +82 -0
  61. data/features/code_check/W9003.feature +2 -0
  62. data/features/step_definitions/code_check_steps.rb +1 -0
  63. data/features/support/env.rb +16 -13
  64. data/lib/adlint.rb +7 -4
  65. data/lib/adlint/analyzer.rb +131 -157
  66. data/lib/adlint/annot.rb +149 -0
  67. data/lib/adlint/cc1.rb +57 -0
  68. data/lib/adlint/{c → cc1}/branch.rb +74 -62
  69. data/lib/adlint/{c → cc1}/builtin.rb +21 -21
  70. data/lib/adlint/{c → cc1}/const.rb +119 -117
  71. data/lib/adlint/{c → cc1}/conv.rb +76 -78
  72. data/lib/adlint/{c → cc1}/ctrlexpr.rb +69 -86
  73. data/lib/adlint/cc1/domain.rb +8103 -0
  74. data/lib/adlint/{c → cc1}/enum.rb +3 -3
  75. data/lib/adlint/{c → cc1}/environ.rb +21 -21
  76. data/lib/adlint/{c → cc1}/expr.rb +232 -218
  77. data/lib/adlint/{c → cc1}/format.rb +305 -342
  78. data/lib/adlint/{c → cc1}/interp.rb +269 -220
  79. data/lib/adlint/cc1/lexer.rb +246 -0
  80. data/lib/adlint/{c → cc1}/mediator.rb +78 -84
  81. data/lib/adlint/{c → cc1}/object.rb +261 -264
  82. data/lib/adlint/{c → cc1}/operator.rb +7 -7
  83. data/lib/adlint/{c → cc1}/option.rb +4 -3
  84. data/lib/adlint/{c → cc1}/parser.rb +274 -506
  85. data/lib/adlint/{c → cc1}/parser.y +69 -301
  86. data/lib/adlint/cc1/phase.rb +138 -0
  87. data/lib/adlint/{c → cc1}/resolver.rb +66 -78
  88. data/lib/adlint/{c → cc1}/scanner.rb +57 -49
  89. data/lib/adlint/{c → cc1}/scope.rb +3 -3
  90. data/lib/adlint/{c → cc1}/seqp.rb +13 -5
  91. data/lib/adlint/{c → cc1}/syntax.rb +819 -1122
  92. data/lib/adlint/{c → cc1}/type.rb +1498 -1479
  93. data/lib/adlint/{c → cc1}/util.rb +20 -12
  94. data/lib/adlint/{c → cc1}/value.rb +699 -642
  95. data/lib/adlint/code.rb +163 -164
  96. data/lib/adlint/cpp.rb +2 -2
  97. data/lib/adlint/cpp/asm.rb +13 -14
  98. data/lib/adlint/cpp/constexpr.rb +42 -38
  99. data/lib/adlint/cpp/constexpr.y +44 -40
  100. data/lib/adlint/cpp/eval.rb +435 -435
  101. data/lib/adlint/cpp/lexer.rb +343 -340
  102. data/lib/adlint/cpp/macro.rb +188 -190
  103. data/lib/adlint/cpp/phase.rb +66 -45
  104. data/lib/adlint/cpp/scanner.rb +14 -17
  105. data/lib/adlint/cpp/source.rb +49 -55
  106. data/lib/adlint/cpp/subst.rb +65 -65
  107. data/lib/adlint/cpp/syntax.rb +155 -275
  108. data/lib/adlint/cpp/util.rb +22 -19
  109. data/lib/adlint/driver.rb +86 -93
  110. data/lib/adlint/error.rb +33 -52
  111. data/lib/adlint/exam.rb +158 -24
  112. data/lib/adlint/exam/c_builtin.rb +7 -7
  113. data/lib/adlint/exam/c_builtin/cc1_check.rb +20522 -0
  114. data/lib/adlint/exam/c_builtin/cc1_check_shima.rb +957 -0
  115. data/lib/adlint/exam/c_builtin/cc1_code.rb +459 -0
  116. data/lib/adlint/exam/c_builtin/cc1_metric.rb +794 -0
  117. data/lib/adlint/exam/c_builtin/cpp_check.rb +486 -441
  118. data/lib/adlint/exam/c_builtin/cpp_check_shima.rb +36 -39
  119. data/lib/adlint/exam/c_builtin/cpp_code.rb +63 -65
  120. data/lib/adlint/exam/c_builtin/ld_check.rb +136 -129
  121. data/lib/adlint/exam/c_builtin/ld_metric.rb +11 -11
  122. data/lib/adlint/lang.rb +25 -25
  123. data/lib/adlint/ld.rb +2 -2
  124. data/lib/adlint/ld/object.rb +220 -188
  125. data/lib/adlint/ld/phase.rb +94 -63
  126. data/lib/adlint/ld/typedef.rb +22 -11
  127. data/lib/adlint/ld/util.rb +43 -35
  128. data/lib/adlint/lexer.rb +59 -56
  129. data/lib/adlint/location.rb +140 -0
  130. data/lib/adlint/memo.rb +157 -0
  131. data/lib/adlint/message.rb +207 -156
  132. data/lib/adlint/metric.rb +139 -217
  133. data/lib/adlint/monitor.rb +45 -43
  134. data/lib/adlint/phase.rb +56 -29
  135. data/lib/adlint/prelude.rb +66 -54
  136. data/lib/adlint/report.rb +253 -332
  137. data/lib/adlint/source.rb +26 -27
  138. data/lib/adlint/supp.rb +131 -0
  139. data/lib/adlint/symbol.rb +14 -16
  140. data/lib/adlint/token.rb +19 -91
  141. data/lib/adlint/traits.rb +242 -226
  142. data/lib/adlint/util.rb +116 -205
  143. data/lib/adlint/version.rb +8 -8
  144. data/share/HEADER +2 -2
  145. data/share/doc/developers_guide_ja.html +148 -19
  146. data/share/doc/developers_guide_ja.texi +141 -11
  147. data/share/doc/samples/GNUmakefile +1 -1
  148. data/share/doc/samples/adlint_traits.yml +45 -36
  149. data/share/doc/users_guide_en.html +1321 -1252
  150. data/share/doc/users_guide_en.texi +475 -408
  151. data/share/doc/users_guide_ja.html +1932 -1878
  152. data/share/doc/users_guide_ja.texi +324 -273
  153. data/share/sample/bison-2.5/adlint/GNUmakefile +5 -1
  154. data/share/sample/bison-2.5/adlint/adlint_traits.yml +38 -38
  155. data/share/sample/bison-2.5/adlint/lib/GNUmakefile +1 -1
  156. data/share/sample/bison-2.5/adlint/lib/adlint_cinit.h +1 -1
  157. data/share/sample/bison-2.5/adlint/lib/adlint_pinit.h +1 -1
  158. data/share/sample/bison-2.5/adlint/lib/adlint_traits.yml +50 -42
  159. data/share/sample/bison-2.5/adlint/src/GNUmakefile +1 -1
  160. data/share/sample/bison-2.5/adlint/src/adlint_cinit.h +1 -1
  161. data/share/sample/bison-2.5/adlint/src/adlint_pinit.h +1 -1
  162. data/share/sample/bison-2.5/adlint/src/adlint_traits.yml +50 -42
  163. data/share/sample/ctags-5.8/adlint/GNUmakefile +1 -1
  164. data/share/sample/ctags-5.8/adlint/adlint_cinit.h +1 -1
  165. data/share/sample/ctags-5.8/adlint/adlint_pinit.h +1 -1
  166. data/share/sample/ctags-5.8/adlint/adlint_traits.yml +50 -42
  167. data/share/sample/flex-2.5.35/adlint/GNUmakefile +1 -1
  168. data/share/sample/flex-2.5.35/adlint/adlint_cinit.h +1 -1
  169. data/share/sample/flex-2.5.35/adlint/adlint_pinit.h +1 -1
  170. data/share/sample/flex-2.5.35/adlint/adlint_traits.yml +50 -42
  171. data/share/sample/ruby-1.9.3-p0/adlint/GNUmakefile +1 -1
  172. data/share/sample/ruby-1.9.3-p0/adlint/adlint_traits.yml +46 -38
  173. data/share/sample/ruby-1.9.3-p0/adlint/core/GNUmakefile +1 -1
  174. data/share/sample/ruby-1.9.3-p0/adlint/core/adlint_cinit.h +1 -1
  175. data/share/sample/ruby-1.9.3-p0/adlint/core/adlint_pinit.h +1 -1
  176. data/share/sample/ruby-1.9.3-p0/adlint/core/adlint_traits.yml +50 -42
  177. data/share/sample/ruby-1.9.3-p0/adlint/enc-trans/GNUmakefile +1 -1
  178. data/share/sample/ruby-1.9.3-p0/adlint/enc-trans/adlint_cinit.h +1 -1
  179. data/share/sample/ruby-1.9.3-p0/adlint/enc-trans/adlint_pinit.h +1 -1
  180. data/share/sample/ruby-1.9.3-p0/adlint/enc-trans/adlint_traits.yml +50 -42
  181. data/share/sample/ruby-1.9.3-p0/adlint/enc/GNUmakefile +1 -1
  182. data/share/sample/ruby-1.9.3-p0/adlint/enc/adlint_cinit.h +1 -1
  183. data/share/sample/ruby-1.9.3-p0/adlint/enc/adlint_pinit.h +1 -1
  184. data/share/sample/ruby-1.9.3-p0/adlint/enc/adlint_traits.yml +50 -42
  185. data/share/sample/ruby-1.9.3-p0/adlint/ext-bigdecimal/GNUmakefile +1 -1
  186. data/share/sample/ruby-1.9.3-p0/adlint/ext-bigdecimal/adlint_cinit.h +1 -1
  187. data/share/sample/ruby-1.9.3-p0/adlint/ext-bigdecimal/adlint_pinit.h +1 -1
  188. data/share/sample/ruby-1.9.3-p0/adlint/ext-bigdecimal/adlint_traits.yml +50 -42
  189. data/share/sample/ruby-1.9.3-p0/adlint/ext-continuation/GNUmakefile +1 -1
  190. data/share/sample/ruby-1.9.3-p0/adlint/ext-continuation/adlint_cinit.h +1 -1
  191. data/share/sample/ruby-1.9.3-p0/adlint/ext-continuation/adlint_pinit.h +1 -1
  192. data/share/sample/ruby-1.9.3-p0/adlint/ext-continuation/adlint_traits.yml +50 -42
  193. data/share/sample/ruby-1.9.3-p0/adlint/ext-coverage/GNUmakefile +1 -1
  194. data/share/sample/ruby-1.9.3-p0/adlint/ext-coverage/adlint_cinit.h +1 -1
  195. data/share/sample/ruby-1.9.3-p0/adlint/ext-coverage/adlint_pinit.h +1 -1
  196. data/share/sample/ruby-1.9.3-p0/adlint/ext-coverage/adlint_traits.yml +50 -42
  197. data/share/sample/ruby-1.9.3-p0/adlint/ext-curses/GNUmakefile +1 -1
  198. data/share/sample/ruby-1.9.3-p0/adlint/ext-curses/adlint_cinit.h +1 -1
  199. data/share/sample/ruby-1.9.3-p0/adlint/ext-curses/adlint_pinit.h +1 -1
  200. data/share/sample/ruby-1.9.3-p0/adlint/ext-curses/adlint_traits.yml +50 -42
  201. data/share/sample/ruby-1.9.3-p0/adlint/ext-date/GNUmakefile +1 -1
  202. data/share/sample/ruby-1.9.3-p0/adlint/ext-date/adlint_cinit.h +1 -1
  203. data/share/sample/ruby-1.9.3-p0/adlint/ext-date/adlint_pinit.h +1 -1
  204. data/share/sample/ruby-1.9.3-p0/adlint/ext-date/adlint_traits.yml +50 -42
  205. data/share/sample/ruby-1.9.3-p0/adlint/ext-dbm/GNUmakefile +1 -1
  206. data/share/sample/ruby-1.9.3-p0/adlint/ext-dbm/adlint_cinit.h +1 -1
  207. data/share/sample/ruby-1.9.3-p0/adlint/ext-dbm/adlint_pinit.h +1 -1
  208. data/share/sample/ruby-1.9.3-p0/adlint/ext-dbm/adlint_traits.yml +50 -42
  209. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-bubblebabble/GNUmakefile +1 -1
  210. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-bubblebabble/adlint_cinit.h +1 -1
  211. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-bubblebabble/adlint_pinit.h +1 -1
  212. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-bubblebabble/adlint_traits.yml +50 -42
  213. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-md5/GNUmakefile +1 -1
  214. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-md5/adlint_cinit.h +1 -1
  215. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-md5/adlint_pinit.h +1 -1
  216. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-md5/adlint_traits.yml +50 -42
  217. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-rmd160/GNUmakefile +1 -1
  218. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-rmd160/adlint_cinit.h +1 -1
  219. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-rmd160/adlint_pinit.h +1 -1
  220. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-rmd160/adlint_traits.yml +50 -42
  221. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha1/GNUmakefile +1 -1
  222. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha1/adlint_cinit.h +1 -1
  223. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha1/adlint_pinit.h +1 -1
  224. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha1/adlint_traits.yml +50 -42
  225. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha2/GNUmakefile +1 -1
  226. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha2/adlint_cinit.h +1 -1
  227. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha2/adlint_pinit.h +1 -1
  228. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha2/adlint_traits.yml +50 -42
  229. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest/GNUmakefile +1 -1
  230. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest/adlint_cinit.h +1 -1
  231. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest/adlint_pinit.h +1 -1
  232. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest/adlint_traits.yml +50 -42
  233. data/share/sample/ruby-1.9.3-p0/adlint/ext-dl-callback/GNUmakefile +1 -1
  234. data/share/sample/ruby-1.9.3-p0/adlint/ext-dl-callback/adlint_cinit.h +1 -1
  235. data/share/sample/ruby-1.9.3-p0/adlint/ext-dl-callback/adlint_pinit.h +1 -1
  236. data/share/sample/ruby-1.9.3-p0/adlint/ext-dl-callback/adlint_traits.yml +50 -42
  237. data/share/sample/ruby-1.9.3-p0/adlint/ext-dl/GNUmakefile +1 -1
  238. data/share/sample/ruby-1.9.3-p0/adlint/ext-dl/adlint_cinit.h +1 -1
  239. data/share/sample/ruby-1.9.3-p0/adlint/ext-dl/adlint_pinit.h +1 -1
  240. data/share/sample/ruby-1.9.3-p0/adlint/ext-dl/adlint_traits.yml +50 -42
  241. data/share/sample/ruby-1.9.3-p0/adlint/ext-etc/GNUmakefile +1 -1
  242. data/share/sample/ruby-1.9.3-p0/adlint/ext-etc/adlint_cinit.h +1 -1
  243. data/share/sample/ruby-1.9.3-p0/adlint/ext-etc/adlint_pinit.h +1 -1
  244. data/share/sample/ruby-1.9.3-p0/adlint/ext-etc/adlint_traits.yml +50 -42
  245. data/share/sample/ruby-1.9.3-p0/adlint/ext-fcntl/GNUmakefile +1 -1
  246. data/share/sample/ruby-1.9.3-p0/adlint/ext-fcntl/adlint_cinit.h +1 -1
  247. data/share/sample/ruby-1.9.3-p0/adlint/ext-fcntl/adlint_pinit.h +1 -1
  248. data/share/sample/ruby-1.9.3-p0/adlint/ext-fcntl/adlint_traits.yml +50 -42
  249. data/share/sample/ruby-1.9.3-p0/adlint/ext-fiber/GNUmakefile +1 -1
  250. data/share/sample/ruby-1.9.3-p0/adlint/ext-fiber/adlint_cinit.h +1 -1
  251. data/share/sample/ruby-1.9.3-p0/adlint/ext-fiber/adlint_pinit.h +1 -1
  252. data/share/sample/ruby-1.9.3-p0/adlint/ext-fiber/adlint_traits.yml +50 -42
  253. data/share/sample/ruby-1.9.3-p0/adlint/ext-fiddle/GNUmakefile +1 -1
  254. data/share/sample/ruby-1.9.3-p0/adlint/ext-fiddle/adlint_cinit.h +1 -1
  255. data/share/sample/ruby-1.9.3-p0/adlint/ext-fiddle/adlint_pinit.h +1 -1
  256. data/share/sample/ruby-1.9.3-p0/adlint/ext-fiddle/adlint_traits.yml +50 -42
  257. data/share/sample/ruby-1.9.3-p0/adlint/ext-gdbm/GNUmakefile +1 -1
  258. data/share/sample/ruby-1.9.3-p0/adlint/ext-gdbm/adlint_cinit.h +1 -1
  259. data/share/sample/ruby-1.9.3-p0/adlint/ext-gdbm/adlint_pinit.h +1 -1
  260. data/share/sample/ruby-1.9.3-p0/adlint/ext-gdbm/adlint_traits.yml +50 -42
  261. data/share/sample/ruby-1.9.3-p0/adlint/ext-iconv/GNUmakefile +1 -1
  262. data/share/sample/ruby-1.9.3-p0/adlint/ext-iconv/adlint_cinit.h +1 -1
  263. data/share/sample/ruby-1.9.3-p0/adlint/ext-iconv/adlint_pinit.h +1 -1
  264. data/share/sample/ruby-1.9.3-p0/adlint/ext-iconv/adlint_traits.yml +50 -42
  265. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-console/GNUmakefile +1 -1
  266. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-console/adlint_cinit.h +1 -1
  267. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-console/adlint_pinit.h +1 -1
  268. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-console/adlint_traits.yml +50 -42
  269. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-nonblock/GNUmakefile +1 -1
  270. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-nonblock/adlint_cinit.h +1 -1
  271. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-nonblock/adlint_pinit.h +1 -1
  272. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-nonblock/adlint_traits.yml +50 -42
  273. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-wait/GNUmakefile +1 -1
  274. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-wait/adlint_cinit.h +1 -1
  275. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-wait/adlint_pinit.h +1 -1
  276. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-wait/adlint_traits.yml +50 -42
  277. data/share/sample/ruby-1.9.3-p0/adlint/ext-json-generator/GNUmakefile +1 -1
  278. data/share/sample/ruby-1.9.3-p0/adlint/ext-json-generator/adlint_cinit.h +1 -1
  279. data/share/sample/ruby-1.9.3-p0/adlint/ext-json-generator/adlint_pinit.h +1 -1
  280. data/share/sample/ruby-1.9.3-p0/adlint/ext-json-generator/adlint_traits.yml +50 -42
  281. data/share/sample/ruby-1.9.3-p0/adlint/ext-json-parser/GNUmakefile +1 -1
  282. data/share/sample/ruby-1.9.3-p0/adlint/ext-json-parser/adlint_cinit.h +1 -1
  283. data/share/sample/ruby-1.9.3-p0/adlint/ext-json-parser/adlint_pinit.h +1 -1
  284. data/share/sample/ruby-1.9.3-p0/adlint/ext-json-parser/adlint_traits.yml +50 -42
  285. data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-complex/GNUmakefile +1 -1
  286. data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-complex/adlint_cinit.h +1 -1
  287. data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-complex/adlint_pinit.h +1 -1
  288. data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-complex/adlint_traits.yml +50 -42
  289. data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-rational/GNUmakefile +1 -1
  290. data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-rational/adlint_cinit.h +1 -1
  291. data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-rational/adlint_pinit.h +1 -1
  292. data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-rational/adlint_traits.yml +50 -42
  293. data/share/sample/ruby-1.9.3-p0/adlint/ext-nkf/GNUmakefile +1 -1
  294. data/share/sample/ruby-1.9.3-p0/adlint/ext-nkf/adlint_cinit.h +1 -1
  295. data/share/sample/ruby-1.9.3-p0/adlint/ext-nkf/adlint_pinit.h +1 -1
  296. data/share/sample/ruby-1.9.3-p0/adlint/ext-nkf/adlint_traits.yml +50 -42
  297. data/share/sample/ruby-1.9.3-p0/adlint/ext-openssl/GNUmakefile +1 -1
  298. data/share/sample/ruby-1.9.3-p0/adlint/ext-openssl/adlint_cinit.h +1 -1
  299. data/share/sample/ruby-1.9.3-p0/adlint/ext-openssl/adlint_pinit.h +1 -1
  300. data/share/sample/ruby-1.9.3-p0/adlint/ext-openssl/adlint_traits.yml +50 -42
  301. data/share/sample/ruby-1.9.3-p0/adlint/ext-pathname/GNUmakefile +1 -1
  302. data/share/sample/ruby-1.9.3-p0/adlint/ext-pathname/adlint_cinit.h +1 -1
  303. data/share/sample/ruby-1.9.3-p0/adlint/ext-pathname/adlint_pinit.h +1 -1
  304. data/share/sample/ruby-1.9.3-p0/adlint/ext-pathname/adlint_traits.yml +50 -42
  305. data/share/sample/ruby-1.9.3-p0/adlint/ext-psych/GNUmakefile +1 -1
  306. data/share/sample/ruby-1.9.3-p0/adlint/ext-psych/adlint_cinit.h +1 -1
  307. data/share/sample/ruby-1.9.3-p0/adlint/ext-psych/adlint_pinit.h +1 -1
  308. data/share/sample/ruby-1.9.3-p0/adlint/ext-psych/adlint_traits.yml +50 -42
  309. data/share/sample/ruby-1.9.3-p0/adlint/ext-pty/GNUmakefile +1 -1
  310. data/share/sample/ruby-1.9.3-p0/adlint/ext-pty/adlint_cinit.h +1 -1
  311. data/share/sample/ruby-1.9.3-p0/adlint/ext-pty/adlint_pinit.h +1 -1
  312. data/share/sample/ruby-1.9.3-p0/adlint/ext-pty/adlint_traits.yml +50 -42
  313. data/share/sample/ruby-1.9.3-p0/adlint/ext-racc-cparse/GNUmakefile +1 -1
  314. data/share/sample/ruby-1.9.3-p0/adlint/ext-racc-cparse/adlint_cinit.h +1 -1
  315. data/share/sample/ruby-1.9.3-p0/adlint/ext-racc-cparse/adlint_pinit.h +1 -1
  316. data/share/sample/ruby-1.9.3-p0/adlint/ext-racc-cparse/adlint_traits.yml +50 -42
  317. data/share/sample/ruby-1.9.3-p0/adlint/ext-readline/GNUmakefile +1 -1
  318. data/share/sample/ruby-1.9.3-p0/adlint/ext-readline/adlint_cinit.h +1 -1
  319. data/share/sample/ruby-1.9.3-p0/adlint/ext-readline/adlint_pinit.h +1 -1
  320. data/share/sample/ruby-1.9.3-p0/adlint/ext-readline/adlint_traits.yml +50 -42
  321. data/share/sample/ruby-1.9.3-p0/adlint/ext-ripper/GNUmakefile +1 -1
  322. data/share/sample/ruby-1.9.3-p0/adlint/ext-ripper/adlint_cinit.h +1 -1
  323. data/share/sample/ruby-1.9.3-p0/adlint/ext-ripper/adlint_pinit.h +1 -1
  324. data/share/sample/ruby-1.9.3-p0/adlint/ext-ripper/adlint_traits.yml +50 -42
  325. data/share/sample/ruby-1.9.3-p0/adlint/ext-sdbm/GNUmakefile +1 -1
  326. data/share/sample/ruby-1.9.3-p0/adlint/ext-sdbm/adlint_cinit.h +1 -1
  327. data/share/sample/ruby-1.9.3-p0/adlint/ext-sdbm/adlint_pinit.h +1 -1
  328. data/share/sample/ruby-1.9.3-p0/adlint/ext-sdbm/adlint_traits.yml +50 -42
  329. data/share/sample/ruby-1.9.3-p0/adlint/ext-socket/GNUmakefile +1 -1
  330. data/share/sample/ruby-1.9.3-p0/adlint/ext-socket/adlint_cinit.h +1 -1
  331. data/share/sample/ruby-1.9.3-p0/adlint/ext-socket/adlint_pinit.h +1 -1
  332. data/share/sample/ruby-1.9.3-p0/adlint/ext-socket/adlint_traits.yml +50 -42
  333. data/share/sample/ruby-1.9.3-p0/adlint/ext-stringio/GNUmakefile +1 -1
  334. data/share/sample/ruby-1.9.3-p0/adlint/ext-stringio/adlint_cinit.h +1 -1
  335. data/share/sample/ruby-1.9.3-p0/adlint/ext-stringio/adlint_pinit.h +1 -1
  336. data/share/sample/ruby-1.9.3-p0/adlint/ext-stringio/adlint_traits.yml +50 -42
  337. data/share/sample/ruby-1.9.3-p0/adlint/ext-strscan/GNUmakefile +1 -1
  338. data/share/sample/ruby-1.9.3-p0/adlint/ext-strscan/adlint_cinit.h +1 -1
  339. data/share/sample/ruby-1.9.3-p0/adlint/ext-strscan/adlint_pinit.h +1 -1
  340. data/share/sample/ruby-1.9.3-p0/adlint/ext-strscan/adlint_traits.yml +50 -42
  341. data/share/sample/ruby-1.9.3-p0/adlint/ext-syck/GNUmakefile +1 -1
  342. data/share/sample/ruby-1.9.3-p0/adlint/ext-syck/adlint_cinit.h +1 -1
  343. data/share/sample/ruby-1.9.3-p0/adlint/ext-syck/adlint_pinit.h +1 -1
  344. data/share/sample/ruby-1.9.3-p0/adlint/ext-syck/adlint_traits.yml +50 -42
  345. data/share/sample/ruby-1.9.3-p0/adlint/ext-syslog/GNUmakefile +1 -1
  346. data/share/sample/ruby-1.9.3-p0/adlint/ext-syslog/adlint_cinit.h +1 -1
  347. data/share/sample/ruby-1.9.3-p0/adlint/ext-syslog/adlint_pinit.h +1 -1
  348. data/share/sample/ruby-1.9.3-p0/adlint/ext-syslog/adlint_traits.yml +50 -42
  349. data/share/sample/ruby-1.9.3-p0/adlint/ext-zlib/GNUmakefile +1 -1
  350. data/share/sample/ruby-1.9.3-p0/adlint/ext-zlib/adlint_cinit.h +1 -1
  351. data/share/sample/ruby-1.9.3-p0/adlint/ext-zlib/adlint_pinit.h +1 -1
  352. data/share/sample/ruby-1.9.3-p0/adlint/ext-zlib/adlint_traits.yml +50 -42
  353. data/share/sample/screen-4.0.3/adlint/GNUmakefile +1 -1
  354. data/share/sample/screen-4.0.3/adlint/adlint_cinit.h +1 -1
  355. data/share/sample/screen-4.0.3/adlint/adlint_pinit.h +1 -1
  356. data/share/sample/screen-4.0.3/adlint/adlint_traits.yml +50 -42
  357. data/share/sample/vim-7.3/adlint/vim/GNUmakefile +1 -1
  358. data/share/sample/vim-7.3/adlint/vim/adlint_cinit.h +1 -1
  359. data/share/sample/vim-7.3/adlint/vim/adlint_pinit.h +1 -1
  360. data/share/sample/vim-7.3/adlint/vim/adlint_traits.yml +50 -42
  361. data/share/sample/vim-7.3/adlint/xxd/GNUmakefile +1 -1
  362. data/share/sample/vim-7.3/adlint/xxd/adlint_cinit.h +1 -1
  363. data/share/sample/vim-7.3/adlint/xxd/adlint_pinit.h +1 -1
  364. data/share/sample/vim-7.3/adlint/xxd/adlint_traits.yml +49 -41
  365. data/share/sample/zsh-4.3.15/adlint/GNUmakefile +1 -1
  366. data/share/sample/zsh-4.3.15/adlint/adlint_traits.yml +46 -38
  367. data/share/sample/zsh-4.3.15/adlint/builtins/GNUmakefile +1 -1
  368. data/share/sample/zsh-4.3.15/adlint/builtins/adlint_cinit.h +1 -1
  369. data/share/sample/zsh-4.3.15/adlint/builtins/adlint_pinit.h +1 -1
  370. data/share/sample/zsh-4.3.15/adlint/builtins/adlint_traits.yml +50 -42
  371. data/share/sample/zsh-4.3.15/adlint/core/GNUmakefile +1 -1
  372. data/share/sample/zsh-4.3.15/adlint/core/adlint_cinit.h +1 -1
  373. data/share/sample/zsh-4.3.15/adlint/core/adlint_pinit.h +1 -1
  374. data/share/sample/zsh-4.3.15/adlint/core/adlint_traits.yml +50 -42
  375. data/share/sample/zsh-4.3.15/adlint/modules/GNUmakefile +1 -1
  376. data/share/sample/zsh-4.3.15/adlint/modules/adlint_cinit.h +1 -1
  377. data/share/sample/zsh-4.3.15/adlint/modules/adlint_pinit.h +1 -1
  378. data/share/sample/zsh-4.3.15/adlint/modules/adlint_traits.yml +50 -42
  379. data/share/sample/zsh-4.3.15/adlint/zle/GNUmakefile +1 -1
  380. data/share/sample/zsh-4.3.15/adlint/zle/adlint_cinit.h +1 -1
  381. data/share/sample/zsh-4.3.15/adlint/zle/adlint_pinit.h +1 -1
  382. data/share/sample/zsh-4.3.15/adlint/zle/adlint_traits.yml +50 -42
  383. data/spec/adlint/{c → cc1}/ctrlexpr_spec.rb +51 -49
  384. data/spec/adlint/{c → cc1}/domain_spec.rb +210 -179
  385. data/spec/adlint/{c → cc1}/operator_spec.rb +3 -3
  386. data/spec/adlint/{c → cc1}/syntax_spec.rb +10 -12
  387. data/spec/adlint/{c → cc1}/type_spec.rb +61 -68
  388. data/{lib/adlint/c.rb → spec/adlint/location_spec.rb} +24 -29
  389. data/spec/conf.d/default_traits.yml +38 -37
  390. data/spec/conf.d/empty_cinit.h +1 -1
  391. data/spec/conf.d/empty_pinit.h +1 -1
  392. data/spec/conf.d/project/foo.c +0 -0
  393. data/spec/spec_helper.rb +2 -2
  394. metadata +60 -40
  395. data/lib/adlint/c/domain.rb +0 -7931
  396. data/lib/adlint/c/lexer.rb +0 -252
  397. data/lib/adlint/c/phase.rb +0 -135
  398. data/lib/adlint/exam/c_builtin/c_check.rb +0 -20745
  399. data/lib/adlint/exam/c_builtin/c_check_shima.rb +0 -983
  400. data/lib/adlint/exam/c_builtin/c_code.rb +0 -477
  401. data/lib/adlint/exam/c_builtin/c_metric.rb +0 -818
@@ -0,0 +1,794 @@
1
+ # Metric measurements (cc1-phase) of adlint-exam-c_builtin package.
2
+ #
3
+ # Author:: Yutaka Yanoh <mailto:yanoh@users.sourceforge.net>
4
+ # Copyright:: Copyright (C) 2010-2013, OGIS-RI Co.,Ltd.
5
+ # License:: GPLv3+: GNU General Public License version 3 or later
6
+ #
7
+ # Owner:: Yutaka Yanoh <mailto:yanoh@users.sourceforge.net>
8
+
9
+ #--
10
+ # ___ ____ __ ___ _________
11
+ # / | / _ |/ / / / | / /__ __/ Source Code Static Analyzer
12
+ # / /| | / / / / / / / |/ / / / AdLint - Advanced Lint
13
+ # / __ |/ /_/ / /___/ / /| / / /
14
+ # /_/ |_|_____/_____/_/_/ |_/ /_/ Copyright (C) 2010-2013, OGIS-RI Co.,Ltd.
15
+ #
16
+ # This file is part of AdLint.
17
+ #
18
+ # AdLint is free software: you can redistribute it and/or modify it under the
19
+ # terms of the GNU General Public License as published by the Free Software
20
+ # Foundation, either version 3 of the License, or (at your option) any later
21
+ # version.
22
+ #
23
+ # AdLint is distributed in the hope that it will be useful, but WITHOUT ANY
24
+ # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
25
+ # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
26
+ #
27
+ # You should have received a copy of the GNU General Public License along with
28
+ # AdLint. If not, see <http://www.gnu.org/licenses/>.
29
+ #
30
+ #++
31
+
32
+ require "adlint/exam"
33
+ require "adlint/report"
34
+ require "adlint/cc1/phase"
35
+ require "adlint/cc1/syntax"
36
+
37
+ module AdLint #:nodoc:
38
+ module Exam #:nodoc:
39
+ module CBuiltin #:nodoc:
40
+
41
+ class FL_STMT < MetricMeasurement
42
+ def_registrant_phase Cc1::Prepare2Phase
43
+
44
+ def initialize(phase_ctxt)
45
+ super
46
+ @fpath = phase_ctxt[:sources].first.fpath
47
+ visitor = phase_ctxt[:cc1_visitor]
48
+ visitor.enter_error_statement += T(:count_statement)
49
+ visitor.enter_generic_labeled_statement += T(:count_statement)
50
+ visitor.enter_case_labeled_statement += T(:count_statement)
51
+ visitor.enter_default_labeled_statement += T(:count_statement)
52
+ visitor.enter_expression_statement += T(:count_statement)
53
+ visitor.enter_if_statement += T(:count_statement)
54
+ visitor.enter_if_else_statement += T(:count_statement)
55
+ visitor.enter_switch_statement += T(:count_statement)
56
+ visitor.enter_while_statement += T(:count_statement)
57
+ visitor.enter_do_statement += T(:count_statement)
58
+ visitor.enter_for_statement += T(:count_statement)
59
+ visitor.enter_c99_for_statement += T(:count_statement)
60
+ visitor.enter_goto_statement += T(:count_statement)
61
+ visitor.enter_continue_statement += T(:count_statement)
62
+ visitor.enter_break_statement += T(:count_statement)
63
+ visitor.enter_return_statement += T(:count_statement)
64
+ visitor.leave_translation_unit += M(:measure)
65
+ @stmt_cnt = 0
66
+ end
67
+
68
+ private
69
+ def do_prepare(*) end
70
+ def do_execute(*) end
71
+
72
+ def count_statement(stmt)
73
+ if @fpath == stmt.location.fpath
74
+ @stmt_cnt += 1
75
+ end
76
+ end
77
+
78
+ def measure(*)
79
+ FL_STMT(@fpath, @stmt_cnt)
80
+ end
81
+ end
82
+
83
+ class FL_FUNC < MetricMeasurement
84
+ def_registrant_phase Cc1::Prepare2Phase
85
+
86
+ def initialize(phase_ctxt)
87
+ super
88
+ @fpath = phase_ctxt[:sources].first.fpath
89
+ visitor = phase_ctxt[:cc1_visitor]
90
+ visitor.enter_ansi_function_definition += T(:count_function)
91
+ visitor.enter_kandr_function_definition += T(:count_function)
92
+ visitor.leave_translation_unit += M(:measure)
93
+ @fun_cnt = 0
94
+ end
95
+
96
+ private
97
+ def do_prepare(*) end
98
+ def do_execute(*) end
99
+
100
+ def count_function(fun_def)
101
+ if @fpath == fun_def.location.fpath
102
+ @fun_cnt += 1
103
+ end
104
+ end
105
+
106
+ def measure(*)
107
+ FL_FUNC(@fpath, @fun_cnt)
108
+ end
109
+ end
110
+
111
+ class FN_STMT < MetricMeasurement
112
+ def_registrant_phase Cc1::Prepare2Phase
113
+
114
+ def initialize(phase_ctxt)
115
+ super
116
+ @fpath = phase_ctxt[:sources].first.fpath
117
+ visitor = phase_ctxt[:cc1_visitor]
118
+ visitor.enter_ansi_function_definition += T(:enter_function)
119
+ visitor.leave_ansi_function_definition += T(:leave_function)
120
+ visitor.enter_kandr_function_definition += T(:enter_function)
121
+ visitor.leave_kandr_function_definition += T(:leave_function)
122
+ visitor.enter_error_statement += T(:count_statement)
123
+ visitor.enter_generic_labeled_statement += T(:count_statement)
124
+ visitor.enter_case_labeled_statement += T(:count_statement)
125
+ visitor.enter_default_labeled_statement += T(:count_statement)
126
+ visitor.enter_expression_statement += T(:count_statement)
127
+ visitor.enter_if_statement += T(:count_statement)
128
+ visitor.enter_if_else_statement += T(:count_statement)
129
+ visitor.enter_switch_statement += T(:count_statement)
130
+ visitor.enter_while_statement += T(:count_statement)
131
+ visitor.enter_do_statement += T(:count_statement)
132
+ visitor.enter_for_statement += T(:count_statement)
133
+ visitor.enter_c99_for_statement += T(:count_statement)
134
+ visitor.enter_goto_statement += T(:count_statement)
135
+ visitor.enter_continue_statement += T(:count_statement)
136
+ visitor.enter_break_statement += T(:count_statement)
137
+ visitor.enter_return_statement += T(:count_statement)
138
+ @cur_fun = nil
139
+ @stmt_cnt = 0
140
+ end
141
+
142
+ private
143
+ def do_prepare(*) end
144
+ def do_execute(*) end
145
+
146
+ def enter_function(fun_def)
147
+ if @fpath == fun_def.location.fpath
148
+ @cur_fun = fun_def
149
+ @stmt_cnt = 0
150
+ end
151
+ end
152
+
153
+ def leave_function(*)
154
+ if @cur_fun
155
+ FN_STMT(FunctionId.new(@cur_fun.identifier.value,
156
+ @cur_fun.signature.to_s),
157
+ @cur_fun.location, @stmt_cnt)
158
+
159
+ @cur_fun = nil
160
+ @stmt_cnt = 0
161
+ end
162
+ end
163
+
164
+ def count_statement(*)
165
+ @stmt_cnt += 1 if @cur_fun
166
+ end
167
+ end
168
+
169
+ class FN_UNRC < MetricMeasurement
170
+ def_registrant_phase Cc1::Prepare2Phase
171
+
172
+ def initialize(phase_ctxt)
173
+ super
174
+ @fpath = phase_ctxt[:sources].first.fpath
175
+ visitor = phase_ctxt[:cc1_visitor]
176
+ visitor.enter_ansi_function_definition += T(:enter_function)
177
+ visitor.leave_ansi_function_definition += T(:leave_function)
178
+ visitor.enter_kandr_function_definition += T(:enter_function)
179
+ visitor.leave_kandr_function_definition += T(:leave_function)
180
+ visitor.enter_error_statement += T(:count_statement)
181
+ visitor.enter_generic_labeled_statement += T(:count_statement)
182
+ visitor.enter_case_labeled_statement += T(:count_statement)
183
+ visitor.enter_default_labeled_statement += T(:count_statement)
184
+ visitor.enter_expression_statement += T(:count_statement)
185
+ visitor.enter_if_statement += T(:count_statement)
186
+ visitor.enter_if_else_statement += T(:count_statement)
187
+ visitor.enter_switch_statement += T(:count_statement)
188
+ visitor.enter_while_statement += T(:count_statement)
189
+ visitor.enter_do_statement += T(:count_statement)
190
+ visitor.enter_for_statement += T(:count_statement)
191
+ visitor.enter_c99_for_statement += T(:count_statement)
192
+ visitor.enter_goto_statement += T(:count_statement)
193
+ visitor.enter_continue_statement += T(:count_statement)
194
+ visitor.enter_break_statement += T(:count_statement)
195
+ visitor.enter_return_statement += T(:count_statement)
196
+ @cur_fun = nil
197
+ @unreached_stmt_cnt = 0
198
+ end
199
+
200
+ private
201
+ def do_prepare(*) end
202
+ def do_execute(*) end
203
+
204
+ def enter_function(fun_def)
205
+ if @fpath == fun_def.location.fpath
206
+ @cur_fun = fun_def
207
+ @unreached_stmt_cnt = 0
208
+ end
209
+ end
210
+
211
+ def leave_function(*)
212
+ if @cur_fun
213
+ FN_UNRC(FunctionId.new(@cur_fun.identifier.value,
214
+ @cur_fun.signature.to_s),
215
+ @cur_fun.location, @unreached_stmt_cnt)
216
+ @cur_fun = nil
217
+ @unreached_stmt_cnt = 0
218
+ end
219
+ end
220
+
221
+ def count_statement(stmt)
222
+ if @cur_fun
223
+ @unreached_stmt_cnt += 1 unless stmt.executed?
224
+ end
225
+ end
226
+ end
227
+
228
+ class FN_LINE < MetricMeasurement
229
+ def_registrant_phase Cc1::Prepare2Phase
230
+
231
+ def initialize(phase_ctxt)
232
+ super
233
+ @fpath = phase_ctxt[:sources].first.fpath
234
+ visitor = phase_ctxt[:cc1_visitor]
235
+ visitor.enter_ansi_function_definition += T(:measure)
236
+ visitor.enter_kandr_function_definition += T(:measure)
237
+ end
238
+
239
+ private
240
+ def do_prepare(*) end
241
+ def do_execute(*) end
242
+
243
+ def measure(fun_def)
244
+ if @fpath == fun_def.location.fpath
245
+ FN_LINE(FunctionId.new(fun_def.identifier.value,
246
+ fun_def.signature.to_s),
247
+ fun_def.location, fun_def.lines)
248
+ end
249
+ end
250
+ end
251
+
252
+ class FN_PARA < MetricMeasurement
253
+ def_registrant_phase Cc1::Prepare2Phase
254
+
255
+ def initialize(phase_ctxt)
256
+ super
257
+ @fpath = phase_ctxt[:sources].first.fpath
258
+ visitor = phase_ctxt[:cc1_visitor]
259
+ visitor.enter_ansi_function_definition += T(:measure_ansi_function)
260
+ visitor.enter_kandr_function_definition += T(:measure_kandr_function)
261
+ end
262
+
263
+ private
264
+ def do_prepare(*) end
265
+ def do_execute(*) end
266
+
267
+ def measure_ansi_function(fun_def)
268
+ if @fpath == fun_def.location.fpath
269
+ # TODO: Determine how many parameters if function has va_list.
270
+ if fun_def.parameter_type_list
271
+ params = fun_def.parameter_definitions
272
+ FN_PARA(FunctionId.new(fun_def.identifier.value,
273
+ fun_def.signature.to_s),
274
+ fun_def.location, params.count { |param| !param.type.void? })
275
+ else
276
+ # TODO: Determine how many parameters if signature is abbreviated.
277
+ FN_PARA(FunctionId.new(fun_def.identifier.value,
278
+ fun_def.signature.to_s),
279
+ fun_def.location, 0)
280
+ end
281
+ end
282
+ end
283
+
284
+ def measure_kandr_function(fun_def)
285
+ if @fpath == fun_def.location.fpath
286
+ FN_PARA(FunctionId.new(fun_def.identifier.value,
287
+ fun_def.signature.to_s),
288
+ fun_def.location, fun_def.identifier_list.size)
289
+ end
290
+ end
291
+ end
292
+
293
+ class FN_UNUV < MetricMeasurement
294
+ def_registrant_phase Cc1::Prepare2Phase
295
+
296
+ def initialize(phase_ctxt)
297
+ super
298
+ @fpath = phase_ctxt[:sources].first.fpath
299
+ interp = phase_ctxt[:cc1_interpreter]
300
+ interp.on_function_started += T(:enter_function)
301
+ interp.on_function_ended += T(:leave_function)
302
+ interp.on_variable_defined += T(:define_variable)
303
+ interp.on_parameter_defined += T(:define_variable)
304
+ interp.on_variable_referred += T(:refer_variable)
305
+ interp.on_variable_value_referred += T(:read_variable)
306
+ interp.on_variable_value_updated += T(:write_variable)
307
+ @cur_fun = nil
308
+ @vars = nil
309
+ end
310
+
311
+ private
312
+ def do_prepare(*) end
313
+ def do_execute(*) end
314
+
315
+ def enter_function(fun_def, *)
316
+ if @fpath == fun_def.location.fpath
317
+ @cur_fun = fun_def
318
+ @vars = {}
319
+ end
320
+ end
321
+
322
+ def leave_function(*)
323
+ if @cur_fun
324
+ useless_cnt = @vars.each_value.reduce(0) { |cnt, read_cnt|
325
+ read_cnt == 0 ? cnt + 1 : cnt
326
+ }
327
+
328
+ FN_UNUV(FunctionId.new(@cur_fun.identifier.value,
329
+ @cur_fun.signature.to_s),
330
+ @cur_fun.location, useless_cnt)
331
+ @cur_fun = nil
332
+ @vars = nil
333
+ end
334
+ end
335
+
336
+ def define_variable(*, var)
337
+ if @cur_fun
338
+ @vars[var.name] = 0
339
+ end
340
+ end
341
+
342
+ def refer_variable(*, var)
343
+ if @cur_fun
344
+ @vars[var.name] += 1 if var.named? && @vars[var.name]
345
+ end
346
+ end
347
+
348
+ def read_variable(*, var)
349
+ if @cur_fun
350
+ @vars[var.name] += 1 if var.named? && @vars[var.name]
351
+ end
352
+ end
353
+
354
+ def write_variable(*, var)
355
+ if @cur_fun
356
+ @vars[var.name] = 0 if var.named? && @vars[var.name]
357
+ end
358
+ end
359
+ end
360
+
361
+ class FN_CSUB < MetricMeasurement
362
+ def_registrant_phase Cc1::Prepare2Phase
363
+
364
+ def initialize(phase_ctxt)
365
+ super
366
+ @fpath = phase_ctxt[:sources].first.fpath
367
+ visitor = phase_ctxt[:cc1_visitor]
368
+ visitor.enter_ansi_function_definition += T(:enter_function)
369
+ visitor.leave_ansi_function_definition += T(:leave_function)
370
+ visitor.enter_kandr_function_definition += T(:enter_function)
371
+ visitor.leave_kandr_function_definition += T(:leave_function)
372
+ visitor.enter_function_call_expression += T(:count_function_call)
373
+ @cur_fun = nil
374
+ @funcall_cnt = 0
375
+ end
376
+
377
+ private
378
+ def do_prepare(*) end
379
+ def do_execute(*) end
380
+
381
+ def enter_function(fun_def)
382
+ if @fpath == fun_def.location.fpath
383
+ @cur_fun = fun_def
384
+ @funcall_cnt = 0
385
+ end
386
+ end
387
+
388
+ def leave_function(*)
389
+ if @cur_fun
390
+ FN_CSUB(FunctionId.new(@cur_fun.identifier.value,
391
+ @cur_fun.signature.to_s),
392
+ @cur_fun.location, @funcall_cnt)
393
+ @cur_fun = nil
394
+ @funcall_cnt = 0
395
+ end
396
+ end
397
+
398
+ def count_function_call(*)
399
+ if @cur_fun
400
+ @funcall_cnt += 1
401
+ end
402
+ end
403
+ end
404
+
405
+ class FN_GOTO < MetricMeasurement
406
+ def_registrant_phase Cc1::Prepare2Phase
407
+
408
+ def initialize(phase_ctxt)
409
+ super
410
+ @fpath = phase_ctxt[:sources].first.fpath
411
+ visitor = phase_ctxt[:cc1_visitor]
412
+ visitor.enter_ansi_function_definition += T(:enter_function)
413
+ visitor.leave_ansi_function_definition += T(:leave_function)
414
+ visitor.enter_kandr_function_definition += T(:enter_function)
415
+ visitor.leave_kandr_function_definition += T(:leave_function)
416
+ visitor.enter_goto_statement += T(:count_goto)
417
+ @cur_fun = nil
418
+ @goto_cnt = 0
419
+ end
420
+
421
+ private
422
+ def do_prepare(*) end
423
+ def do_execute(*) end
424
+
425
+ def enter_function(fun_def)
426
+ if @fpath == fun_def.location.fpath
427
+ @cur_fun = fun_def
428
+ @goto_cnt = 0
429
+ end
430
+ end
431
+
432
+ def leave_function(*)
433
+ if @cur_fun
434
+ FN_GOTO(FunctionId.new(@cur_fun.identifier.value,
435
+ @cur_fun.signature.to_s),
436
+ @cur_fun.location, @goto_cnt)
437
+ @cur_fun = nil
438
+ @goto_cnt = 0
439
+ end
440
+ end
441
+
442
+ def count_goto(*)
443
+ if @cur_fun
444
+ @goto_cnt += 1
445
+ end
446
+ end
447
+ end
448
+
449
+ class FN_RETN < MetricMeasurement
450
+ def_registrant_phase Cc1::Prepare2Phase
451
+
452
+ def initialize(phase_ctxt)
453
+ super
454
+ @fpath = phase_ctxt[:sources].first.fpath
455
+ visitor = phase_ctxt[:cc1_visitor]
456
+ visitor.enter_ansi_function_definition += T(:enter_function)
457
+ visitor.leave_ansi_function_definition += T(:leave_function)
458
+ visitor.enter_kandr_function_definition += T(:enter_function)
459
+ visitor.leave_kandr_function_definition += T(:leave_function)
460
+ visitor.enter_error_statement += T(:enter_statement)
461
+ visitor.enter_generic_labeled_statement += T(:enter_statement)
462
+ visitor.enter_case_labeled_statement += T(:enter_statement)
463
+ visitor.enter_default_labeled_statement += T(:enter_statement)
464
+ visitor.enter_expression_statement += T(:enter_statement)
465
+ visitor.enter_if_statement += T(:enter_statement)
466
+ visitor.enter_if_else_statement += T(:enter_statement)
467
+ visitor.enter_switch_statement += T(:enter_statement)
468
+ visitor.enter_while_statement += T(:enter_statement)
469
+ visitor.enter_do_statement += T(:enter_statement)
470
+ visitor.enter_for_statement += T(:enter_statement)
471
+ visitor.enter_c99_for_statement += T(:enter_statement)
472
+ visitor.enter_goto_statement += T(:enter_statement)
473
+ visitor.enter_continue_statement += T(:enter_statement)
474
+ visitor.enter_break_statement += T(:enter_statement)
475
+ visitor.enter_return_statement += T(:count_return)
476
+ @cur_fun = nil
477
+ @retn_cnt = 0
478
+ @last_stmt = nil
479
+ end
480
+
481
+ private
482
+ def do_prepare(*) end
483
+ def do_execute(*) end
484
+
485
+ def enter_function(fun_def)
486
+ if @fpath == fun_def.location.fpath
487
+ @cur_fun = fun_def
488
+ @retn_cnt = 0
489
+ @last_stmt = nil
490
+ end
491
+ end
492
+
493
+ def leave_function(*)
494
+ if @cur_fun
495
+ if @cur_fun.type.return_type.void? &&
496
+ !(@last_stmt.kind_of?(Cc1::ReturnStatement))
497
+ FN_RETN(FunctionId.new(@cur_fun.identifier.value,
498
+ @cur_fun.signature.to_s),
499
+ @cur_fun.location, @retn_cnt + 1)
500
+ else
501
+ FN_RETN(FunctionId.new(@cur_fun.identifier.value,
502
+ @cur_fun.signature.to_s),
503
+ @cur_fun.location, @retn_cnt)
504
+ end
505
+ @cur_fun = nil
506
+ @retn_cnt = 0
507
+ @last_stmt = nil
508
+ end
509
+ end
510
+
511
+ def enter_statement(node)
512
+ if @cur_fun
513
+ @last_stmt = node if node.executed?
514
+ end
515
+ end
516
+
517
+ def count_return(node)
518
+ if @cur_fun
519
+ @retn_cnt += 1
520
+ @last_stmt = node
521
+ end
522
+ end
523
+ end
524
+
525
+ class FN_UELS < MetricMeasurement
526
+ def_registrant_phase Cc1::Prepare2Phase
527
+
528
+ def initialize(phase_ctxt)
529
+ super
530
+ @fpath = phase_ctxt[:sources].first.fpath
531
+ visitor = phase_ctxt[:cc1_visitor]
532
+ visitor.enter_ansi_function_definition += T(:enter_function)
533
+ visitor.leave_ansi_function_definition += T(:leave_function)
534
+ visitor.enter_kandr_function_definition += T(:enter_function)
535
+ visitor.leave_kandr_function_definition += T(:leave_function)
536
+ visitor.enter_if_else_statement += T(:enter_if_else_statement)
537
+ visitor.leave_if_else_statement += T(:leave_if_else_statement)
538
+ @cur_fun = nil
539
+ @if_else_stmt_chain = 0
540
+ @incomplete_if_else_stmt_cnt = 0
541
+ end
542
+
543
+ private
544
+ def do_prepare(*) end
545
+ def do_execute(*) end
546
+
547
+ def enter_function(fun_def)
548
+ if @fpath == fun_def.location.fpath
549
+ @cur_fun = fun_def
550
+ @if_else_stmt_chain = 0
551
+ @incomplete_if_else_stmt_cnt = 0
552
+ end
553
+ end
554
+
555
+ def leave_function(*)
556
+ if @cur_fun
557
+ FN_UELS(FunctionId.new(@cur_fun.identifier.value,
558
+ @cur_fun.signature.to_s),
559
+ @cur_fun.location, @incomplete_if_else_stmt_cnt)
560
+ @cur_fun = nil
561
+ @if_else_stmt_chain = 0
562
+ @incomplete_if_else_stmt_cnt = 0
563
+ end
564
+ end
565
+
566
+ def enter_if_else_statement(node)
567
+ @if_else_stmt_chain += 1
568
+
569
+ if @cur_fun && @if_else_stmt_chain > 0
570
+ if node.else_statement.kind_of?(Cc1::IfStatement)
571
+ @incomplete_if_else_stmt_cnt += 1
572
+ end
573
+ end
574
+ end
575
+
576
+ def leave_if_else_statement(*)
577
+ @if_else_stmt_chain -= 1
578
+ end
579
+ end
580
+
581
+ class FN_NEST < MetricMeasurement
582
+ def_registrant_phase Cc1::Prepare2Phase
583
+
584
+ def initialize(phase_ctxt)
585
+ super
586
+ @fpath = phase_ctxt[:sources].first.fpath
587
+ visitor = phase_ctxt[:cc1_visitor]
588
+ visitor.enter_ansi_function_definition += T(:enter_function)
589
+ visitor.leave_ansi_function_definition += T(:leave_function)
590
+ visitor.enter_kandr_function_definition += T(:enter_function)
591
+ visitor.leave_kandr_function_definition += T(:leave_function)
592
+ visitor.enter_compound_statement += T(:enter_block)
593
+ visitor.leave_compound_statement += T(:leave_block)
594
+ visitor.enter_if_statement += T(:check_statement)
595
+ visitor.enter_if_else_statement += T(:check_statement)
596
+ visitor.enter_while_statement += T(:check_statement)
597
+ visitor.enter_do_statement += T(:check_statement)
598
+ visitor.enter_for_statement += T(:check_statement)
599
+ visitor.enter_c99_for_statement += T(:check_statement)
600
+ @cur_fun = nil
601
+ end
602
+
603
+ private
604
+ def do_prepare(*) end
605
+ def do_execute(*) end
606
+
607
+ def enter_function(fun_def)
608
+ if @fpath == fun_def.location.fpath
609
+ @cur_fun = fun_def
610
+ # NOTE: Nest level of the top of the function is 0.
611
+ # Function definition must have a compound-statement as the
612
+ # function body.
613
+ @max_nest_level = @cur_nest_level = -1
614
+ end
615
+ end
616
+
617
+ def leave_function(fun_def)
618
+ if @cur_fun
619
+ FN_NEST(FunctionId.new(@cur_fun.identifier.value,
620
+ @cur_fun.signature.to_s),
621
+ @cur_fun.location, @max_nest_level)
622
+ @cur_fun = nil
623
+ end
624
+ end
625
+
626
+ def enter_block(*)
627
+ if @cur_fun
628
+ @cur_nest_level += 1
629
+ @max_nest_level = [@max_nest_level, @cur_nest_level].max
630
+ end
631
+ end
632
+
633
+ def leave_block(*)
634
+ if @cur_fun
635
+ @cur_nest_level -= 1
636
+ end
637
+ end
638
+
639
+ def check_statement(stmt)
640
+ if @cur_fun
641
+ case stmt
642
+ when Cc1::IfStatement
643
+ sub_statement = stmt.statement
644
+ when Cc1::IfElseStatement
645
+ if stmt.then_statement.kind_of?(Cc1::CompoundStatement)
646
+ sub_statement = stmt.else_statement
647
+ else
648
+ sub_statement = stmt.then_statement
649
+ end
650
+ when Cc1::WhileStatement, Cc1::DoStatement
651
+ sub_statement = stmt.statement
652
+ when Cc1::ForStatement, Cc1::C99ForStatement
653
+ sub_statement = stmt.body_statement
654
+ end
655
+
656
+ case sub_statement
657
+ when Cc1::CompoundStatement, Cc1::IfStatement, Cc1::IfElseStatement
658
+ else
659
+ @cur_nest_level += 1
660
+ @max_nest_level = [@max_nest_level, @cur_nest_level].max
661
+ end
662
+ end
663
+ end
664
+ end
665
+
666
+ class FN_PATH < MetricMeasurement
667
+ def_registrant_phase Cc1::Prepare2Phase
668
+
669
+ def initialize(phase_ctxt)
670
+ super
671
+ @fpath = phase_ctxt[:sources].first.fpath
672
+ interp = phase_ctxt[:cc1_interpreter]
673
+ interp.on_function_started += T(:enter_function)
674
+ interp.on_function_ended += T(:leave_function)
675
+ interp.on_branch_started += M(:enter_branch)
676
+ interp.on_branch_ended += M(:leave_branch)
677
+ @cur_fun = nil
678
+ end
679
+
680
+ private
681
+ def do_prepare(*) end
682
+ def do_execute(*) end
683
+
684
+ def enter_function(fun_def, *)
685
+ if @fpath == fun_def.location.fpath
686
+ @cur_fun = fun_def
687
+
688
+ # NOTE: Number of paths in the current function.
689
+ @paths_in_fun = 1
690
+ # NOTE: Stack of the number of paths to enter the current branch group.
691
+ @paths_to_enter_branch_group = [@paths_in_fun]
692
+ # NOTE: Stack of the number of paths in the current branch.
693
+ @paths_in_branch = [@paths_in_fun]
694
+ # NOTE: Stack of the number of paths in the current branch group.
695
+ @paths_in_branch_group = [@paths_in_fun]
696
+ end
697
+ end
698
+
699
+ def leave_function(*)
700
+ if @cur_fun
701
+ FN_PATH(FunctionId.new(@cur_fun.identifier.value,
702
+ @cur_fun.signature.to_s),
703
+ @cur_fun.location, @paths_in_fun)
704
+ @cur_fun = nil
705
+ end
706
+ end
707
+
708
+ def enter_branch(branch)
709
+ if @cur_fun
710
+ # NOTE: Entering into new branch group.
711
+ if branch.first?
712
+ @paths_in_fun -= @paths_in_branch.last
713
+ @paths_to_enter_branch_group.push(@paths_in_branch.last)
714
+ @paths_in_branch_group.push(0)
715
+ end
716
+
717
+ # NOTE: Entering into new branch.
718
+ @paths_in_branch.push(@paths_to_enter_branch_group.last)
719
+ @paths_in_fun += @paths_to_enter_branch_group.last
720
+ end
721
+ end
722
+
723
+ def leave_branch(branch)
724
+ if @cur_fun
725
+ paths_in_this_branch = @paths_in_branch.pop
726
+
727
+ # NOTE: Leaving from the current branch whose paths are not terminated.
728
+ unless branch.break_with_return?
729
+ @paths_in_branch_group[-1] += paths_in_this_branch
730
+ end
731
+
732
+ # NOTE: Leaving from the current branch group.
733
+ if branch.final?
734
+ paths_to_enter_this_branch_group = @paths_to_enter_branch_group.pop
735
+ paths_in_this_branch_group = @paths_in_branch_group.pop
736
+
737
+ @paths_in_branch[-1] = paths_in_this_branch_group
738
+
739
+ # NOTE: The current branch group is an incomplete branch group.
740
+ unless branch.group.complete?
741
+ @paths_in_fun += paths_to_enter_this_branch_group
742
+ @paths_in_branch[-1] += paths_to_enter_this_branch_group
743
+ end
744
+ end
745
+ end
746
+ end
747
+ end
748
+
749
+ class FN_CYCM < MetricMeasurement
750
+ def_registrant_phase Cc1::Prepare2Phase
751
+
752
+ def initialize(phase_ctxt)
753
+ super
754
+ @fpath = phase_ctxt[:sources].first.fpath
755
+ visitor = phase_ctxt[:cc1_visitor]
756
+ visitor.enter_ansi_function_definition += T(:enter_function)
757
+ visitor.leave_ansi_function_definition += T(:leave_function)
758
+ visitor.enter_kandr_function_definition += T(:enter_function)
759
+ visitor.leave_kandr_function_definition += T(:leave_function)
760
+ visitor.enter_if_statement += T(:enter_selection)
761
+ visitor.enter_if_else_statement += T(:enter_selection)
762
+ visitor.enter_case_labeled_statement += T(:enter_selection)
763
+ @cur_fun = nil
764
+ @cycl_compl = 0
765
+ end
766
+
767
+ private
768
+ def do_prepare(*) end
769
+ def do_execute(*) end
770
+
771
+ def enter_function(fun_def)
772
+ if @fpath == fun_def.location.fpath
773
+ @cur_fun = fun_def
774
+ @cycl_compl = 0
775
+ end
776
+ end
777
+
778
+ def leave_function(*)
779
+ if @cur_fun
780
+ FN_CYCM(FunctionId.new(@cur_fun.identifier.value,
781
+ @cur_fun.signature.to_s),
782
+ @cur_fun.location, @cycl_compl + 1)
783
+ @cur_fun = nil
784
+ end
785
+ end
786
+
787
+ def enter_selection(*)
788
+ @cycl_compl += 1 if @cur_fun
789
+ end
790
+ end
791
+
792
+ end
793
+ end
794
+ end