adlint 1.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 (465) hide show
  1. data/AUTHORS +27 -0
  2. data/COPYING +674 -0
  3. data/ChangeLog +820 -0
  4. data/INSTALL +78 -0
  5. data/MANIFEST +464 -0
  6. data/NEWS +38 -0
  7. data/README +74 -0
  8. data/Rakefile +167 -0
  9. data/TODO +29 -0
  10. data/bin/adlint +141 -0
  11. data/bin/adlint_chk +129 -0
  12. data/bin/adlint_cma +122 -0
  13. data/bin/adlint_sma +129 -0
  14. data/bin/adlintize +286 -0
  15. data/etc/conf.d/fallback/cinit.erb +11 -0
  16. data/etc/conf.d/fallback/traits.erb +216 -0
  17. data/etc/conf.d/i686-cygwin/cinit-gcc_4.3.4.erb +149 -0
  18. data/etc/conf.d/i686-cygwin/traits-gcc_4.3.4.erb +227 -0
  19. data/etc/conf.d/i686-devkit/cinit-gcc_4.5.2.erb +224 -0
  20. data/etc/conf.d/i686-devkit/traits-gcc_4.5.2.erb +226 -0
  21. data/etc/conf.d/i686-linux/cinit-gcc_4.5.1.erb +219 -0
  22. data/etc/conf.d/i686-linux/traits-gcc_4.5.1.erb +224 -0
  23. data/etc/conf.d/i686-mingw/cinit-gcc_4.6.1.erb +234 -0
  24. data/etc/conf.d/i686-mingw/traits-gcc_4.6.1.erb +226 -0
  25. data/etc/conf.d/noarch/GNUmakefile.erb +119 -0
  26. data/etc/conf.d/noarch/adlint_all_bat.erb +9 -0
  27. data/etc/conf.d/noarch/adlint_all_sh.erb +10 -0
  28. data/etc/conf.d/noarch/pinit.erb +11 -0
  29. data/etc/mesg.d/en_US/messages.yml +784 -0
  30. data/etc/mesg.d/ja_JP/messages.yml +784 -0
  31. data/lib/adlint/analyzer.rb +294 -0
  32. data/lib/adlint/c/branch.rb +251 -0
  33. data/lib/adlint/c/builtin.rb +92 -0
  34. data/lib/adlint/c/code.rb +490 -0
  35. data/lib/adlint/c/const.rb +465 -0
  36. data/lib/adlint/c/conv.rb +212 -0
  37. data/lib/adlint/c/ctrlexpr.rb +949 -0
  38. data/lib/adlint/c/domain.rb +7499 -0
  39. data/lib/adlint/c/environ.rb +133 -0
  40. data/lib/adlint/c/expr.rb +1725 -0
  41. data/lib/adlint/c/format.rb +3209 -0
  42. data/lib/adlint/c/interp.rb +1740 -0
  43. data/lib/adlint/c/lexer.rb +241 -0
  44. data/lib/adlint/c/mediator.rb +313 -0
  45. data/lib/adlint/c/message.rb +13597 -0
  46. data/lib/adlint/c/metric.rb +765 -0
  47. data/lib/adlint/c/object.rb +1018 -0
  48. data/lib/adlint/c/parser.rb +3800 -0
  49. data/lib/adlint/c/parser.y +2054 -0
  50. data/lib/adlint/c/phase.rb +712 -0
  51. data/lib/adlint/c/resolver.rb +270 -0
  52. data/lib/adlint/c/scanner.rb +248 -0
  53. data/lib/adlint/c/scope.rb +74 -0
  54. data/lib/adlint/c/syntax.rb +4279 -0
  55. data/lib/adlint/c/type.rb +7506 -0
  56. data/lib/adlint/c/util.rb +91 -0
  57. data/lib/adlint/c/value.rb +2310 -0
  58. data/lib/adlint/c.rb +56 -0
  59. data/lib/adlint/code.rb +500 -0
  60. data/lib/adlint/cpp/code.rb +189 -0
  61. data/lib/adlint/cpp/constexpr.rb +721 -0
  62. data/lib/adlint/cpp/constexpr.y +389 -0
  63. data/lib/adlint/cpp/eval.rb +1012 -0
  64. data/lib/adlint/cpp/lexer.rb +860 -0
  65. data/lib/adlint/cpp/macro.rb +637 -0
  66. data/lib/adlint/cpp/message.rb +992 -0
  67. data/lib/adlint/cpp/phase.rb +176 -0
  68. data/lib/adlint/cpp/scanner.rb +93 -0
  69. data/lib/adlint/cpp/source.rb +169 -0
  70. data/lib/adlint/cpp/subst.rb +300 -0
  71. data/lib/adlint/cpp/syntax.rb +1412 -0
  72. data/lib/adlint/cpp/util.rb +97 -0
  73. data/lib/adlint/cpp.rb +43 -0
  74. data/lib/adlint/driver.rb +147 -0
  75. data/lib/adlint/error.rb +179 -0
  76. data/lib/adlint/lang.rb +97 -0
  77. data/lib/adlint/ld/message.rb +259 -0
  78. data/lib/adlint/ld/metric.rb +57 -0
  79. data/lib/adlint/ld/object.rb +542 -0
  80. data/lib/adlint/ld/phase.rb +193 -0
  81. data/lib/adlint/ld/typedef.rb +109 -0
  82. data/lib/adlint/ld/util.rb +88 -0
  83. data/lib/adlint/ld.rb +37 -0
  84. data/lib/adlint/lexer.rb +293 -0
  85. data/lib/adlint/message.rb +368 -0
  86. data/lib/adlint/metric.rb +805 -0
  87. data/lib/adlint/monitor.rb +144 -0
  88. data/lib/adlint/phase.rb +90 -0
  89. data/lib/adlint/prelude.rb +314 -0
  90. data/lib/adlint/report.rb +617 -0
  91. data/lib/adlint/source.rb +155 -0
  92. data/lib/adlint/symbol.rb +127 -0
  93. data/lib/adlint/token.rb +215 -0
  94. data/lib/adlint/traits.rb +643 -0
  95. data/lib/adlint/util.rb +524 -0
  96. data/lib/adlint/version.rb +71 -0
  97. data/lib/adlint.rb +66 -0
  98. data/share/HEADER +45 -0
  99. data/share/demo/Makefile +110 -0
  100. data/share/demo/ambig_operator/ambig_operator.c +289 -0
  101. data/share/demo/arg_points_unset/arg_points_unset.c +37 -0
  102. data/share/demo/array_range/array_range.c +62 -0
  103. data/share/demo/bad_bitfields/bad_bitfields.c +74 -0
  104. data/share/demo/bad_brace/bad_brace.c +19 -0
  105. data/share/demo/bad_charset/abcde$.h +0 -0
  106. data/share/demo/bad_charset/bad_charset.c +22 -0
  107. data/share/demo/bad_comment/bad_comment.c +3 -0
  108. data/share/demo/bad_const/bad_const.c +19 -0
  109. data/share/demo/bad_conv/bad_conv.c +48 -0
  110. data/share/demo/bad_indent/bad_indent.c +50 -0
  111. data/share/demo/bad_init/bad_init.c +49 -0
  112. data/share/demo/bad_macro/bad_macro.c +97 -0
  113. data/share/demo/bitwise_expr/bitwise_expr.c +19 -0
  114. data/share/demo/call_by_value/call_by_value.c +26 -0
  115. data/share/demo/cross_ref/cross_ref.c +21 -0
  116. data/share/demo/dangling_else/dangling_else.c +20 -0
  117. data/share/demo/dead_code/dead_code.c +237 -0
  118. data/share/demo/deep_nest/deep_nest.c +57 -0
  119. data/share/demo/dense_switch/dense_switch.c +62 -0
  120. data/share/demo/direct_recur/direct_recur.c +15 -0
  121. data/share/demo/div_by_zero/div_by_zero.c +35 -0
  122. data/share/demo/dos_source/dos_source.c +7 -0
  123. data/share/demo/funptr_cast/funptr_cast.c +26 -0
  124. data/share/demo/goto_stmt/goto_stmt.c +19 -0
  125. data/share/demo/id_hiding/id_hiding.c +19 -0
  126. data/share/demo/ill_defined/ill_defined.c +13 -0
  127. data/share/demo/implicit_conv/implicit_conv.c +60 -0
  128. data/share/demo/implicit_int/implicit_int.c +14 -0
  129. data/share/demo/incomplete_type/incomplete_type.c +49 -0
  130. data/share/demo/indirect_recur/indirect_recur_1.c +14 -0
  131. data/share/demo/indirect_recur/indirect_recur_1.h +7 -0
  132. data/share/demo/indirect_recur/indirect_recur_2.c +12 -0
  133. data/share/demo/indirect_recur/indirect_recur_2.h +6 -0
  134. data/share/demo/indirect_recur/indirect_recur_3.c +6 -0
  135. data/share/demo/indirect_recur/indirect_recur_3.h +6 -0
  136. data/share/demo/indirect_recur/indirect_recur_4.c +25 -0
  137. data/share/demo/intro_demo/intro_demo.c +76 -0
  138. data/share/demo/intro_demo/intro_demo.h +12 -0
  139. data/share/demo/intro_demo/useless_header.h +5 -0
  140. data/share/demo/invalid_call/invalid_call.c +32 -0
  141. data/share/demo/kandr_fundef/kandr_fundef.c +10 -0
  142. data/share/demo/line_comment/line_comment.c +12 -0
  143. data/share/demo/local_decl/local_decl.c +9 -0
  144. data/share/demo/logical_trick/logical_trick.c +36 -0
  145. data/share/demo/long_sym/long_sym.c +5 -0
  146. data/share/demo/loop_var/loop_var.c +92 -0
  147. data/share/demo/malloc_or_die/malloc_or_die.c +43 -0
  148. data/share/demo/may_be_null/may_be_null.c +52 -0
  149. data/share/demo/may_be_null_arith/may_be_null_arith.c +15 -0
  150. data/share/demo/may_be_unset/may_be_unset.c +34 -0
  151. data/share/demo/mmapped_io/mmapped_io.c +23 -0
  152. data/share/demo/multi_break/multi_break.c +33 -0
  153. data/share/demo/multi_decl/multi_decl_1.c +17 -0
  154. data/share/demo/multi_decl/multi_decl_1.h +6 -0
  155. data/share/demo/multi_decl/multi_decl_2.c +13 -0
  156. data/share/demo/multi_decl/multi_decl_2.h +6 -0
  157. data/share/demo/multi_decl/multi_decl_3.c +22 -0
  158. data/share/demo/multi_def/multi_def_1.c +36 -0
  159. data/share/demo/multi_def/multi_def_1.h +6 -0
  160. data/share/demo/multi_def/multi_def_2.c +22 -0
  161. data/share/demo/multi_def/multi_def_2.h +6 -0
  162. data/share/demo/multi_def/multi_def_3.c +6 -0
  163. data/share/demo/multi_typedef/multi_typedef.c +11 -0
  164. data/share/demo/multi_typedef/multi_typedef_1.h +1 -0
  165. data/share/demo/multi_typedef/multi_typedef_2.h +1 -0
  166. data/share/demo/must_be_false/must_be_false.c +53 -0
  167. data/share/demo/must_be_null/must_be_null.c +13 -0
  168. data/share/demo/must_be_null_arith/must_be_null_arith.c +14 -0
  169. data/share/demo/must_be_true/must_be_true.c +21 -0
  170. data/share/demo/no_eof_nl/no_eof_nl.c +4 -0
  171. data/share/demo/no_void_arg/no_void_arg.c +14 -0
  172. data/share/demo/null_stmt/null_stmt.c +19 -0
  173. data/share/demo/octal_const/octal_const.c +20 -0
  174. data/share/demo/output_by_param/output_by_param.c +17 -0
  175. data/share/demo/overflow/overflow.c +74 -0
  176. data/share/demo/press_release/press_release.c +40 -0
  177. data/share/demo/retn_lvar_addr/retn_lvar_addr.c +47 -0
  178. data/share/demo/shift_expr/shift_expr.c +14 -0
  179. data/share/demo/should_be_typedef/should_be_typedef.c +51 -0
  180. data/share/demo/static_paths/static_paths.c +153 -0
  181. data/share/demo/static_vars/static_vars.c +39 -0
  182. data/share/demo/tag_hiding/tag_hiding.c +18 -0
  183. data/share/demo/tricky_incdec/tricky_incdec.c +12 -0
  184. data/share/demo/undefined_macro/undefined_macro.c +17 -0
  185. data/share/demo/uninit_vars/uninit_vars.c +28 -0
  186. data/share/demo/union_type/union_type.c +23 -0
  187. data/share/demo/unmatch_decl/unmatch_decl_1.c +12 -0
  188. data/share/demo/unmatch_decl/unmatch_decl_1.h +8 -0
  189. data/share/demo/unmatch_decl/unmatch_decl_2.c +10 -0
  190. data/share/demo/unmatch_decl/unmatch_decl_2.h +8 -0
  191. data/share/demo/unmatch_decl/unmatch_decl_3.c +7 -0
  192. data/share/demo/unmatch_paren_macro/unmatch_paren_macro.c +15 -0
  193. data/share/demo/unreachable/unreachable.c +34 -0
  194. data/share/demo/useless_exp_funs/useless_exp_funs_1.c +14 -0
  195. data/share/demo/useless_exp_funs/useless_exp_funs_1.h +1 -0
  196. data/share/demo/useless_exp_funs/useless_exp_funs_2.c +6 -0
  197. data/share/demo/useless_exp_vars/useless_export_1.c +8 -0
  198. data/share/demo/useless_exp_vars/useless_export_1.h +1 -0
  199. data/share/demo/useless_exp_vars/useless_export_2.c +7 -0
  200. data/share/demo/useless_expr/useless_expr.c +17 -0
  201. data/share/demo/useless_funs/useless_funs_1.c +21 -0
  202. data/share/demo/useless_funs/useless_funs_1.h +8 -0
  203. data/share/demo/useless_funs/useless_funs_2.c +6 -0
  204. data/share/demo/useless_header/useless_header.c +9 -0
  205. data/share/demo/useless_header/useless_header_1.h +12 -0
  206. data/share/demo/useless_header/useless_header_2.h +6 -0
  207. data/share/demo/useless_header/useless_header_3.h +9 -0
  208. data/share/demo/useless_header/useless_header_4.h +3 -0
  209. data/share/demo/useless_vars/useless_vars.c +17 -0
  210. data/share/demo/va_funcall/va_funcall.c +25 -0
  211. data/share/demo/various_fundef/various_fundef.c +36 -0
  212. data/share/demo/wchar_wstring/wchar_wstring.c +7 -0
  213. data/share/demo/wrap_around/wrap_around.c +38 -0
  214. data/share/doc/Makefile +16 -0
  215. data/share/doc/adlint_on_adqua.png +0 -0
  216. data/share/doc/adlint_on_eclipse_en.png +0 -0
  217. data/share/doc/adlint_on_eclipse_ja.png +0 -0
  218. data/share/doc/adlint_on_vim_en.png +0 -0
  219. data/share/doc/adlint_on_vim_ja.png +0 -0
  220. data/share/doc/developers_guide_ja.html +171 -0
  221. data/share/doc/developers_guide_ja.texi +87 -0
  222. data/share/doc/gen_mesg_sections.rb +39 -0
  223. data/share/doc/samples/GNUmakefile +162 -0
  224. data/share/doc/samples/adlint_traits.yml +238 -0
  225. data/share/doc/texinfo.css +22 -0
  226. data/share/doc/users_guide_en.html +39975 -0
  227. data/share/doc/users_guide_en.texi +32640 -0
  228. data/share/doc/users_guide_ja.html +40505 -0
  229. data/share/doc/users_guide_ja.texi +33189 -0
  230. data/share/logo/adlint-110.png +0 -0
  231. data/share/logo/adlint-524.png +0 -0
  232. data/share/logo/adlint.svg +4637 -0
  233. data/share/sample/README +6 -0
  234. data/share/sample/bison-2.5/adlint/GNUmakefile +170 -0
  235. data/share/sample/bison-2.5/adlint/adlint_traits.yml +225 -0
  236. data/share/sample/bison-2.5/adlint/lib/GNUmakefile +198 -0
  237. data/share/sample/bison-2.5/adlint/lib/adlint_cinit.h +228 -0
  238. data/share/sample/bison-2.5/adlint/lib/adlint_pinit.h +21 -0
  239. data/share/sample/bison-2.5/adlint/lib/adlint_traits.yml +238 -0
  240. data/share/sample/bison-2.5/adlint/src/GNUmakefile +166 -0
  241. data/share/sample/bison-2.5/adlint/src/adlint_cinit.h +228 -0
  242. data/share/sample/bison-2.5/adlint/src/adlint_pinit.h +21 -0
  243. data/share/sample/bison-2.5/adlint/src/adlint_traits.yml +239 -0
  244. data/share/sample/ctags-5.8/adlint/GNUmakefile +169 -0
  245. data/share/sample/ctags-5.8/adlint/adlint_cinit.h +219 -0
  246. data/share/sample/ctags-5.8/adlint/adlint_pinit.h +13 -0
  247. data/share/sample/ctags-5.8/adlint/adlint_traits.yml +225 -0
  248. data/share/sample/flex-2.5.35/adlint/GNUmakefile +140 -0
  249. data/share/sample/flex-2.5.35/adlint/adlint_cinit.h +219 -0
  250. data/share/sample/flex-2.5.35/adlint/adlint_pinit.h +14 -0
  251. data/share/sample/flex-2.5.35/adlint/adlint_traits.yml +225 -0
  252. data/share/sample/ruby-1.9.3-p0/adlint/GNUmakefile +314 -0
  253. data/share/sample/ruby-1.9.3-p0/adlint/adlint_traits.yml +225 -0
  254. data/share/sample/ruby-1.9.3-p0/adlint/core/GNUmakefile +204 -0
  255. data/share/sample/ruby-1.9.3-p0/adlint/core/adlint_cinit.h +228 -0
  256. data/share/sample/ruby-1.9.3-p0/adlint/core/adlint_pinit.h +28 -0
  257. data/share/sample/ruby-1.9.3-p0/adlint/core/adlint_traits.yml +240 -0
  258. data/share/sample/ruby-1.9.3-p0/adlint/enc/GNUmakefile +163 -0
  259. data/share/sample/ruby-1.9.3-p0/adlint/enc/adlint_cinit.h +228 -0
  260. data/share/sample/ruby-1.9.3-p0/adlint/enc/adlint_pinit.h +24 -0
  261. data/share/sample/ruby-1.9.3-p0/adlint/enc/adlint_traits.yml +240 -0
  262. data/share/sample/ruby-1.9.3-p0/adlint/enc-trans/GNUmakefile +149 -0
  263. data/share/sample/ruby-1.9.3-p0/adlint/enc-trans/adlint_cinit.h +228 -0
  264. data/share/sample/ruby-1.9.3-p0/adlint/enc-trans/adlint_pinit.h +24 -0
  265. data/share/sample/ruby-1.9.3-p0/adlint/enc-trans/adlint_traits.yml +240 -0
  266. data/share/sample/ruby-1.9.3-p0/adlint/ext-bigdecimal/GNUmakefile +131 -0
  267. data/share/sample/ruby-1.9.3-p0/adlint/ext-bigdecimal/adlint_cinit.h +228 -0
  268. data/share/sample/ruby-1.9.3-p0/adlint/ext-bigdecimal/adlint_pinit.h +24 -0
  269. data/share/sample/ruby-1.9.3-p0/adlint/ext-bigdecimal/adlint_traits.yml +241 -0
  270. data/share/sample/ruby-1.9.3-p0/adlint/ext-continuation/GNUmakefile +131 -0
  271. data/share/sample/ruby-1.9.3-p0/adlint/ext-continuation/adlint_cinit.h +228 -0
  272. data/share/sample/ruby-1.9.3-p0/adlint/ext-continuation/adlint_pinit.h +24 -0
  273. data/share/sample/ruby-1.9.3-p0/adlint/ext-continuation/adlint_traits.yml +241 -0
  274. data/share/sample/ruby-1.9.3-p0/adlint/ext-coverage/GNUmakefile +131 -0
  275. data/share/sample/ruby-1.9.3-p0/adlint/ext-coverage/adlint_cinit.h +228 -0
  276. data/share/sample/ruby-1.9.3-p0/adlint/ext-coverage/adlint_pinit.h +24 -0
  277. data/share/sample/ruby-1.9.3-p0/adlint/ext-coverage/adlint_traits.yml +241 -0
  278. data/share/sample/ruby-1.9.3-p0/adlint/ext-curses/GNUmakefile +131 -0
  279. data/share/sample/ruby-1.9.3-p0/adlint/ext-curses/adlint_cinit.h +228 -0
  280. data/share/sample/ruby-1.9.3-p0/adlint/ext-curses/adlint_pinit.h +24 -0
  281. data/share/sample/ruby-1.9.3-p0/adlint/ext-curses/adlint_traits.yml +241 -0
  282. data/share/sample/ruby-1.9.3-p0/adlint/ext-date/GNUmakefile +134 -0
  283. data/share/sample/ruby-1.9.3-p0/adlint/ext-date/adlint_cinit.h +228 -0
  284. data/share/sample/ruby-1.9.3-p0/adlint/ext-date/adlint_pinit.h +24 -0
  285. data/share/sample/ruby-1.9.3-p0/adlint/ext-date/adlint_traits.yml +241 -0
  286. data/share/sample/ruby-1.9.3-p0/adlint/ext-dbm/GNUmakefile +131 -0
  287. data/share/sample/ruby-1.9.3-p0/adlint/ext-dbm/adlint_cinit.h +228 -0
  288. data/share/sample/ruby-1.9.3-p0/adlint/ext-dbm/adlint_pinit.h +24 -0
  289. data/share/sample/ruby-1.9.3-p0/adlint/ext-dbm/adlint_traits.yml +241 -0
  290. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest/GNUmakefile +131 -0
  291. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest/adlint_cinit.h +228 -0
  292. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest/adlint_pinit.h +24 -0
  293. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest/adlint_traits.yml +241 -0
  294. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-bubblebabble/GNUmakefile +131 -0
  295. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-bubblebabble/adlint_cinit.h +228 -0
  296. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-bubblebabble/adlint_pinit.h +24 -0
  297. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-bubblebabble/adlint_traits.yml +242 -0
  298. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-md5/GNUmakefile +132 -0
  299. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-md5/adlint_cinit.h +228 -0
  300. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-md5/adlint_pinit.h +24 -0
  301. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-md5/adlint_traits.yml +242 -0
  302. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-rmd160/GNUmakefile +132 -0
  303. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-rmd160/adlint_cinit.h +228 -0
  304. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-rmd160/adlint_pinit.h +24 -0
  305. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-rmd160/adlint_traits.yml +242 -0
  306. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha1/GNUmakefile +132 -0
  307. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha1/adlint_cinit.h +228 -0
  308. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha1/adlint_pinit.h +24 -0
  309. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha1/adlint_traits.yml +242 -0
  310. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha2/GNUmakefile +132 -0
  311. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha2/adlint_cinit.h +228 -0
  312. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha2/adlint_pinit.h +24 -0
  313. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha2/adlint_traits.yml +242 -0
  314. data/share/sample/ruby-1.9.3-p0/adlint/ext-dl/GNUmakefile +134 -0
  315. data/share/sample/ruby-1.9.3-p0/adlint/ext-dl/adlint_cinit.h +228 -0
  316. data/share/sample/ruby-1.9.3-p0/adlint/ext-dl/adlint_pinit.h +24 -0
  317. data/share/sample/ruby-1.9.3-p0/adlint/ext-dl/adlint_traits.yml +241 -0
  318. data/share/sample/ruby-1.9.3-p0/adlint/ext-dl-callback/GNUmakefile +140 -0
  319. data/share/sample/ruby-1.9.3-p0/adlint/ext-dl-callback/adlint_cinit.h +228 -0
  320. data/share/sample/ruby-1.9.3-p0/adlint/ext-dl-callback/adlint_pinit.h +24 -0
  321. data/share/sample/ruby-1.9.3-p0/adlint/ext-dl-callback/adlint_traits.yml +242 -0
  322. data/share/sample/ruby-1.9.3-p0/adlint/ext-etc/GNUmakefile +131 -0
  323. data/share/sample/ruby-1.9.3-p0/adlint/ext-etc/adlint_cinit.h +228 -0
  324. data/share/sample/ruby-1.9.3-p0/adlint/ext-etc/adlint_pinit.h +24 -0
  325. data/share/sample/ruby-1.9.3-p0/adlint/ext-etc/adlint_traits.yml +241 -0
  326. data/share/sample/ruby-1.9.3-p0/adlint/ext-fcntl/GNUmakefile +131 -0
  327. data/share/sample/ruby-1.9.3-p0/adlint/ext-fcntl/adlint_cinit.h +228 -0
  328. data/share/sample/ruby-1.9.3-p0/adlint/ext-fcntl/adlint_pinit.h +24 -0
  329. data/share/sample/ruby-1.9.3-p0/adlint/ext-fcntl/adlint_traits.yml +241 -0
  330. data/share/sample/ruby-1.9.3-p0/adlint/ext-fiber/GNUmakefile +131 -0
  331. data/share/sample/ruby-1.9.3-p0/adlint/ext-fiber/adlint_cinit.h +228 -0
  332. data/share/sample/ruby-1.9.3-p0/adlint/ext-fiber/adlint_pinit.h +24 -0
  333. data/share/sample/ruby-1.9.3-p0/adlint/ext-fiber/adlint_traits.yml +241 -0
  334. data/share/sample/ruby-1.9.3-p0/adlint/ext-fiddle/GNUmakefile +134 -0
  335. data/share/sample/ruby-1.9.3-p0/adlint/ext-fiddle/adlint_cinit.h +228 -0
  336. data/share/sample/ruby-1.9.3-p0/adlint/ext-fiddle/adlint_pinit.h +24 -0
  337. data/share/sample/ruby-1.9.3-p0/adlint/ext-fiddle/adlint_traits.yml +242 -0
  338. data/share/sample/ruby-1.9.3-p0/adlint/ext-gdbm/GNUmakefile +131 -0
  339. data/share/sample/ruby-1.9.3-p0/adlint/ext-gdbm/adlint_cinit.h +228 -0
  340. data/share/sample/ruby-1.9.3-p0/adlint/ext-gdbm/adlint_pinit.h +24 -0
  341. data/share/sample/ruby-1.9.3-p0/adlint/ext-gdbm/adlint_traits.yml +241 -0
  342. data/share/sample/ruby-1.9.3-p0/adlint/ext-iconv/GNUmakefile +131 -0
  343. data/share/sample/ruby-1.9.3-p0/adlint/ext-iconv/adlint_cinit.h +228 -0
  344. data/share/sample/ruby-1.9.3-p0/adlint/ext-iconv/adlint_pinit.h +24 -0
  345. data/share/sample/ruby-1.9.3-p0/adlint/ext-iconv/adlint_traits.yml +241 -0
  346. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-console/GNUmakefile +131 -0
  347. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-console/adlint_cinit.h +228 -0
  348. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-console/adlint_pinit.h +24 -0
  349. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-console/adlint_traits.yml +241 -0
  350. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-nonblock/GNUmakefile +131 -0
  351. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-nonblock/adlint_cinit.h +228 -0
  352. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-nonblock/adlint_pinit.h +24 -0
  353. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-nonblock/adlint_traits.yml +241 -0
  354. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-wait/GNUmakefile +131 -0
  355. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-wait/adlint_cinit.h +228 -0
  356. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-wait/adlint_pinit.h +24 -0
  357. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-wait/adlint_traits.yml +241 -0
  358. data/share/sample/ruby-1.9.3-p0/adlint/ext-json-generator/GNUmakefile +131 -0
  359. data/share/sample/ruby-1.9.3-p0/adlint/ext-json-generator/adlint_cinit.h +228 -0
  360. data/share/sample/ruby-1.9.3-p0/adlint/ext-json-generator/adlint_pinit.h +24 -0
  361. data/share/sample/ruby-1.9.3-p0/adlint/ext-json-generator/adlint_traits.yml +241 -0
  362. data/share/sample/ruby-1.9.3-p0/adlint/ext-json-parser/GNUmakefile +131 -0
  363. data/share/sample/ruby-1.9.3-p0/adlint/ext-json-parser/adlint_cinit.h +228 -0
  364. data/share/sample/ruby-1.9.3-p0/adlint/ext-json-parser/adlint_pinit.h +24 -0
  365. data/share/sample/ruby-1.9.3-p0/adlint/ext-json-parser/adlint_traits.yml +241 -0
  366. data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-complex/GNUmakefile +131 -0
  367. data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-complex/adlint_cinit.h +228 -0
  368. data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-complex/adlint_pinit.h +24 -0
  369. data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-complex/adlint_traits.yml +241 -0
  370. data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-rational/GNUmakefile +131 -0
  371. data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-rational/adlint_cinit.h +228 -0
  372. data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-rational/adlint_pinit.h +24 -0
  373. data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-rational/adlint_traits.yml +241 -0
  374. data/share/sample/ruby-1.9.3-p0/adlint/ext-nkf/GNUmakefile +131 -0
  375. data/share/sample/ruby-1.9.3-p0/adlint/ext-nkf/adlint_cinit.h +228 -0
  376. data/share/sample/ruby-1.9.3-p0/adlint/ext-nkf/adlint_pinit.h +24 -0
  377. data/share/sample/ruby-1.9.3-p0/adlint/ext-nkf/adlint_traits.yml +241 -0
  378. data/share/sample/ruby-1.9.3-p0/adlint/ext-openssl/GNUmakefile +162 -0
  379. data/share/sample/ruby-1.9.3-p0/adlint/ext-openssl/adlint_cinit.h +228 -0
  380. data/share/sample/ruby-1.9.3-p0/adlint/ext-openssl/adlint_pinit.h +24 -0
  381. data/share/sample/ruby-1.9.3-p0/adlint/ext-openssl/adlint_traits.yml +241 -0
  382. data/share/sample/ruby-1.9.3-p0/adlint/ext-pathname/GNUmakefile +131 -0
  383. data/share/sample/ruby-1.9.3-p0/adlint/ext-pathname/adlint_cinit.h +228 -0
  384. data/share/sample/ruby-1.9.3-p0/adlint/ext-pathname/adlint_pinit.h +24 -0
  385. data/share/sample/ruby-1.9.3-p0/adlint/ext-pathname/adlint_traits.yml +241 -0
  386. data/share/sample/ruby-1.9.3-p0/adlint/ext-psych/GNUmakefile +135 -0
  387. data/share/sample/ruby-1.9.3-p0/adlint/ext-psych/adlint_cinit.h +228 -0
  388. data/share/sample/ruby-1.9.3-p0/adlint/ext-psych/adlint_pinit.h +24 -0
  389. data/share/sample/ruby-1.9.3-p0/adlint/ext-psych/adlint_traits.yml +241 -0
  390. data/share/sample/ruby-1.9.3-p0/adlint/ext-pty/GNUmakefile +131 -0
  391. data/share/sample/ruby-1.9.3-p0/adlint/ext-pty/adlint_cinit.h +228 -0
  392. data/share/sample/ruby-1.9.3-p0/adlint/ext-pty/adlint_pinit.h +24 -0
  393. data/share/sample/ruby-1.9.3-p0/adlint/ext-pty/adlint_traits.yml +241 -0
  394. data/share/sample/ruby-1.9.3-p0/adlint/ext-racc-cparse/GNUmakefile +131 -0
  395. data/share/sample/ruby-1.9.3-p0/adlint/ext-racc-cparse/adlint_cinit.h +228 -0
  396. data/share/sample/ruby-1.9.3-p0/adlint/ext-racc-cparse/adlint_pinit.h +24 -0
  397. data/share/sample/ruby-1.9.3-p0/adlint/ext-racc-cparse/adlint_traits.yml +241 -0
  398. data/share/sample/ruby-1.9.3-p0/adlint/ext-readline/GNUmakefile +131 -0
  399. data/share/sample/ruby-1.9.3-p0/adlint/ext-readline/adlint_cinit.h +228 -0
  400. data/share/sample/ruby-1.9.3-p0/adlint/ext-readline/adlint_pinit.h +24 -0
  401. data/share/sample/ruby-1.9.3-p0/adlint/ext-readline/adlint_traits.yml +241 -0
  402. data/share/sample/ruby-1.9.3-p0/adlint/ext-ripper/GNUmakefile +131 -0
  403. data/share/sample/ruby-1.9.3-p0/adlint/ext-ripper/adlint_cinit.h +228 -0
  404. data/share/sample/ruby-1.9.3-p0/adlint/ext-ripper/adlint_pinit.h +24 -0
  405. data/share/sample/ruby-1.9.3-p0/adlint/ext-ripper/adlint_traits.yml +241 -0
  406. data/share/sample/ruby-1.9.3-p0/adlint/ext-sdbm/GNUmakefile +132 -0
  407. data/share/sample/ruby-1.9.3-p0/adlint/ext-sdbm/adlint_cinit.h +228 -0
  408. data/share/sample/ruby-1.9.3-p0/adlint/ext-sdbm/adlint_pinit.h +24 -0
  409. data/share/sample/ruby-1.9.3-p0/adlint/ext-sdbm/adlint_traits.yml +241 -0
  410. data/share/sample/ruby-1.9.3-p0/adlint/ext-socket/GNUmakefile +144 -0
  411. data/share/sample/ruby-1.9.3-p0/adlint/ext-socket/adlint_cinit.h +228 -0
  412. data/share/sample/ruby-1.9.3-p0/adlint/ext-socket/adlint_pinit.h +24 -0
  413. data/share/sample/ruby-1.9.3-p0/adlint/ext-socket/adlint_traits.yml +241 -0
  414. data/share/sample/ruby-1.9.3-p0/adlint/ext-stringio/GNUmakefile +131 -0
  415. data/share/sample/ruby-1.9.3-p0/adlint/ext-stringio/adlint_cinit.h +228 -0
  416. data/share/sample/ruby-1.9.3-p0/adlint/ext-stringio/adlint_pinit.h +24 -0
  417. data/share/sample/ruby-1.9.3-p0/adlint/ext-stringio/adlint_traits.yml +241 -0
  418. data/share/sample/ruby-1.9.3-p0/adlint/ext-strscan/GNUmakefile +131 -0
  419. data/share/sample/ruby-1.9.3-p0/adlint/ext-strscan/adlint_cinit.h +228 -0
  420. data/share/sample/ruby-1.9.3-p0/adlint/ext-strscan/adlint_pinit.h +24 -0
  421. data/share/sample/ruby-1.9.3-p0/adlint/ext-strscan/adlint_traits.yml +241 -0
  422. data/share/sample/ruby-1.9.3-p0/adlint/ext-syck/GNUmakefile +140 -0
  423. data/share/sample/ruby-1.9.3-p0/adlint/ext-syck/adlint_cinit.h +228 -0
  424. data/share/sample/ruby-1.9.3-p0/adlint/ext-syck/adlint_pinit.h +24 -0
  425. data/share/sample/ruby-1.9.3-p0/adlint/ext-syck/adlint_traits.yml +241 -0
  426. data/share/sample/ruby-1.9.3-p0/adlint/ext-syslog/GNUmakefile +131 -0
  427. data/share/sample/ruby-1.9.3-p0/adlint/ext-syslog/adlint_cinit.h +228 -0
  428. data/share/sample/ruby-1.9.3-p0/adlint/ext-syslog/adlint_pinit.h +24 -0
  429. data/share/sample/ruby-1.9.3-p0/adlint/ext-syslog/adlint_traits.yml +241 -0
  430. data/share/sample/ruby-1.9.3-p0/adlint/ext-zlib/GNUmakefile +131 -0
  431. data/share/sample/ruby-1.9.3-p0/adlint/ext-zlib/adlint_cinit.h +228 -0
  432. data/share/sample/ruby-1.9.3-p0/adlint/ext-zlib/adlint_pinit.h +24 -0
  433. data/share/sample/ruby-1.9.3-p0/adlint/ext-zlib/adlint_traits.yml +241 -0
  434. data/share/sample/screen-4.0.3/adlint/GNUmakefile +162 -0
  435. data/share/sample/screen-4.0.3/adlint/adlint_cinit.h +228 -0
  436. data/share/sample/screen-4.0.3/adlint/adlint_pinit.h +21 -0
  437. data/share/sample/screen-4.0.3/adlint/adlint_traits.yml +238 -0
  438. data/share/sample/vim-7.3/adlint/vim/GNUmakefile +185 -0
  439. data/share/sample/vim-7.3/adlint/vim/adlint_cinit.h +228 -0
  440. data/share/sample/vim-7.3/adlint/vim/adlint_pinit.h +25 -0
  441. data/share/sample/vim-7.3/adlint/vim/adlint_traits.yml +250 -0
  442. data/share/sample/vim-7.3/adlint/xxd/GNUmakefile +131 -0
  443. data/share/sample/vim-7.3/adlint/xxd/adlint_cinit.h +228 -0
  444. data/share/sample/vim-7.3/adlint/xxd/adlint_pinit.h +24 -0
  445. data/share/sample/vim-7.3/adlint/xxd/adlint_traits.yml +237 -0
  446. data/share/sample/zsh-4.3.15/adlint/GNUmakefile +146 -0
  447. data/share/sample/zsh-4.3.15/adlint/adlint_traits.yml +225 -0
  448. data/share/sample/zsh-4.3.15/adlint/builtins/GNUmakefile +132 -0
  449. data/share/sample/zsh-4.3.15/adlint/builtins/adlint_cinit.h +228 -0
  450. data/share/sample/zsh-4.3.15/adlint/builtins/adlint_pinit.h +24 -0
  451. data/share/sample/zsh-4.3.15/adlint/builtins/adlint_traits.yml +240 -0
  452. data/share/sample/zsh-4.3.15/adlint/core/GNUmakefile +153 -0
  453. data/share/sample/zsh-4.3.15/adlint/core/adlint_cinit.h +228 -0
  454. data/share/sample/zsh-4.3.15/adlint/core/adlint_pinit.h +23 -0
  455. data/share/sample/zsh-4.3.15/adlint/core/adlint_traits.yml +239 -0
  456. data/share/sample/zsh-4.3.15/adlint/modules/GNUmakefile +147 -0
  457. data/share/sample/zsh-4.3.15/adlint/modules/adlint_cinit.h +228 -0
  458. data/share/sample/zsh-4.3.15/adlint/modules/adlint_pinit.h +24 -0
  459. data/share/sample/zsh-4.3.15/adlint/modules/adlint_traits.yml +240 -0
  460. data/share/sample/zsh-4.3.15/adlint/zle/GNUmakefile +144 -0
  461. data/share/sample/zsh-4.3.15/adlint/zle/adlint_cinit.h +228 -0
  462. data/share/sample/zsh-4.3.15/adlint/zle/adlint_pinit.h +24 -0
  463. data/share/sample/zsh-4.3.15/adlint/zle/adlint_traits.yml +239 -0
  464. data/spec/MUST_WRITE_SPECS_WITH_RSPEC +0 -0
  465. metadata +532 -0
@@ -0,0 +1,1018 @@
1
+ # C runtime object model.
2
+ #
3
+ # Author:: Yutaka Yanoh <mailto:yanoh@users.sourceforge.net>
4
+ # Copyright:: Copyright (C) 2010-2012, 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-2012, 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/util"
33
+ require "adlint/c/value"
34
+ require "adlint/c/scope"
35
+
36
+ module AdLint #:nodoc:
37
+ module C #:nodoc:
38
+
39
+ module Bindable
40
+ attr_accessor :binding
41
+
42
+ def bind_to(target)
43
+ case target
44
+ when Memory
45
+ Binding.bind(self, target)
46
+ when Object
47
+ Binding.bind(target, self)
48
+ end
49
+ end
50
+
51
+ def be_alias_to(memory)
52
+ case memory
53
+ when Memory
54
+ Binding.create_alias(self, memory)
55
+ else
56
+ raise TypeError, "an object cannot be an alias to other objects."
57
+ end
58
+ end
59
+ end
60
+
61
+ class Binding
62
+ def self.bind(object, memory)
63
+ binding = new(object, memory)
64
+ object.binding = binding
65
+ memory.binding = binding
66
+ binding
67
+ end
68
+
69
+ def self.create_alias(object, memory)
70
+ binding = new(object, memory)
71
+ object.binding = binding
72
+ binding
73
+ end
74
+
75
+ def initialize(object, memory)
76
+ @object = object
77
+ @memory = memory
78
+ end
79
+ private_class_method :new
80
+
81
+ attr_reader :object
82
+ attr_reader :memory
83
+ end
84
+
85
+ class Object
86
+ include Bindable
87
+
88
+ def initialize(declaration_or_definition = nil)
89
+ @declarations_and_definitions = [declaration_or_definition].compact
90
+ end
91
+
92
+ attr_reader :declarations_and_definitions
93
+
94
+ def designated_by_lvalue?
95
+ subclass_responsibility
96
+ end
97
+
98
+ def named?
99
+ subclass_responsibility
100
+ end
101
+
102
+ def temporary?
103
+ subclass_responsibility
104
+ end
105
+
106
+ def function?
107
+ subclass_responsibility
108
+ end
109
+
110
+ def variable?
111
+ subclass_responsibility
112
+ end
113
+ end
114
+
115
+ class TypedObject < Object
116
+ def initialize(type, declaration_or_definition = nil)
117
+ super(declaration_or_definition)
118
+ @type = type
119
+ end
120
+
121
+ attr_reader :type
122
+ end
123
+
124
+ # == DESCRIPTION
125
+ # === Variable class hierarchy
126
+ # Variable
127
+ # <--- ScopedVariable
128
+ # <--- OuterVariable
129
+ # <--- NamedVariable --------- Nameable <<module>>
130
+ # <--- AliasVariable |
131
+ # <--- TemporaryVariable |
132
+ # <--- InnerVariable -------------+
133
+ # <--- ArrayElementVariable
134
+ # <--- CompositeMemberVariable
135
+ class Variable < TypedObject
136
+ def initialize(memory, declaration_or_definition, type)
137
+ super(type, declaration_or_definition)
138
+
139
+ relate_to_memory(memory)
140
+ end
141
+
142
+ def function?
143
+ false
144
+ end
145
+
146
+ def variable?
147
+ true
148
+ end
149
+
150
+ def name
151
+ subclass_responsibility
152
+ end
153
+
154
+ def named?
155
+ false
156
+ end
157
+
158
+ def value
159
+ binding.memory.read
160
+ end
161
+
162
+ def assign!(value)
163
+ # NOTE: Length of the incomplete array type should be deducted while
164
+ # initializer evaluation. So, adjustment of the assigning value
165
+ # can be done at this point by Value#coerce_to(type).
166
+ # NOTE: Domain of the assigning value must be narrowed before writing to
167
+ # the memory by Value#coerce_to(type).
168
+ binding.memory.write(value.coerce_to(type))
169
+ end
170
+
171
+ def uninitialize!
172
+ assign!(self.type.undefined_value)
173
+ end
174
+
175
+ def narrow_value_domain!(operator_symbol, value)
176
+ unless self_value = modifiable_value
177
+ assign!(type.arbitrary_value)
178
+ self_value = modifiable_value
179
+ end
180
+
181
+ self_value.narrow_domain!(operator_symbol, value.coerce_to(type))
182
+ self_value.exist?
183
+ end
184
+
185
+ def widen_value_domain!(operator_symbol, value)
186
+ unless self_value = modifiable_value
187
+ assign!(type.nil_value)
188
+ self_value = modifiable_value
189
+ end
190
+
191
+ self_value.widen_domain!(operator_symbol, value.coerce_to(type))
192
+ self_value.exist?
193
+ end
194
+
195
+ private
196
+ def relate_to_memory(memory)
197
+ bind_to(memory)
198
+ end
199
+
200
+ def modifiable_value
201
+ binding.memory.read_modifiable
202
+ end
203
+ end
204
+
205
+ class ScopedVariable < Variable
206
+ def initialize(memory, declaration_or_definition, type, scope)
207
+ super(memory, declaration_or_definition, type)
208
+ @scope = scope
209
+ end
210
+
211
+ attr_accessor :scope
212
+ end
213
+
214
+ class OuterVariable < ScopedVariable
215
+ def initialize(memory, declaration_or_definition, type, scope)
216
+ super(memory, declaration_or_definition, type, scope)
217
+
218
+ # TODO: If too slow, make an index of inner variables.
219
+ @inner_variables = create_inner_variables(type, scope)
220
+ end
221
+
222
+ def inner_variable_at(index)
223
+ if @type.array?
224
+ # TODO: If linear serching is too slow, use an index of inner
225
+ # variables.
226
+ target_name = ArrayElementVariable.component_name_of(index)
227
+ @inner_variables.find { |iv| iv.component_name == target_name }
228
+ else
229
+ nil
230
+ end
231
+ end
232
+
233
+ def inner_variable_named(name)
234
+ if @type.composite?
235
+ # TODO: If linear serching is too slow, use an index of inner
236
+ # variables.
237
+ target_name = CompositeMemberVariable.component_name_of(name)
238
+ @inner_variables.find { |iv| iv.component_name == target_name }
239
+ else
240
+ nil
241
+ end
242
+ end
243
+
244
+ private
245
+ def create_inner_variables(type, scope)
246
+ case
247
+ when type.array?
248
+ create_array_elements(type, scope, binding.memory)
249
+ when type.composite?
250
+ create_composite_members(type, scope, binding.memory)
251
+ else
252
+ nil
253
+ end
254
+ end
255
+
256
+ def create_array_elements(type, scope, memory)
257
+ offset = 0
258
+ type.impl_length.times.map do |index|
259
+ window = memory.create_window(offset, type.base_type.aligned_byte_size)
260
+ offset += window.byte_size
261
+ ArrayElementVariable.new(window, self, type.base_type, index)
262
+ end
263
+ end
264
+
265
+ def create_composite_members(type, scope, memory)
266
+ offset = 0
267
+ type.members.map do |member|
268
+ window = memory.create_window(offset, member.type.aligned_byte_size)
269
+ offset += window.byte_size
270
+ CompositeMemberVariable.new(window, self, member.type, member.name)
271
+ end
272
+ end
273
+ end
274
+
275
+ module Nameable
276
+ attr_reader :name
277
+
278
+ def named?
279
+ true
280
+ end
281
+
282
+ private
283
+ def name=(name)
284
+ # NOTE: Private attr_writer to suppress `private attribute?' warning.
285
+ @name = name
286
+ end
287
+ end
288
+
289
+ class NamedVariable < OuterVariable
290
+ include Nameable
291
+
292
+ def initialize(memory, declaration_or_definition, scope)
293
+ self.name = declaration_or_definition.identifier.value
294
+
295
+ super(memory, declaration_or_definition, declaration_or_definition.type,
296
+ scope)
297
+ end
298
+
299
+ def temporary?
300
+ false
301
+ end
302
+
303
+ def designated_by_lvalue?
304
+ true
305
+ end
306
+
307
+ # NOTE: This method should be overridden by PhantomVariable.
308
+ def to_named_variable
309
+ self
310
+ end
311
+
312
+ def pretty_print(pp)
313
+ Summary.new(object_id, name, type, binding.memory).pretty_print(pp)
314
+ end
315
+
316
+ Summary = Struct.new(:object_id, :name, :type, :memory)
317
+ end
318
+
319
+ class TemporaryVariable < OuterVariable
320
+ def initialize(memory, type, scope)
321
+ super(memory, nil, type, scope)
322
+ end
323
+
324
+ def temporary?
325
+ true
326
+ end
327
+
328
+ def designated_by_lvalue?
329
+ false
330
+ end
331
+
332
+ def named?
333
+ false
334
+ end
335
+
336
+ def pretty_print(pp)
337
+ Summary.new(object_id, type, binding.memory).pretty_print(pp)
338
+ end
339
+
340
+ Summary = Struct.new(:object_id, :type, :memory)
341
+ end
342
+
343
+ class InnerVariable < OuterVariable
344
+ include Nameable
345
+
346
+ def initialize(memory, outer_variable, type, component_name)
347
+ self.name = create_qualified_name(outer_variable, component_name)
348
+
349
+ super(memory, nil, type, outer_variable.scope)
350
+
351
+ @owner = outer_variable
352
+ @component_name = component_name
353
+ end
354
+
355
+ attr_reader :owner
356
+ attr_reader :component_name
357
+
358
+ def temporary?
359
+ @owner.temporary?
360
+ end
361
+
362
+ def designated_by_lvalue?
363
+ true
364
+ end
365
+
366
+ def to_named_variable
367
+ self
368
+ end
369
+
370
+ private
371
+ def create_qualified_name(outer_variable, component_name)
372
+ if outer_variable.named?
373
+ "#{outer_variable.name}#{component_name}"
374
+ else
375
+ "__adlint__tempvar#{component_name}"
376
+ end
377
+ end
378
+ end
379
+
380
+ class ArrayElementVariable < InnerVariable
381
+ def self.component_name_of(index)
382
+ "[#{index}]"
383
+ end
384
+
385
+ def initialize(memory, outer_variable, type, index)
386
+ super(memory, outer_variable, type, self.class.component_name_of(index))
387
+ end
388
+ end
389
+
390
+ class CompositeMemberVariable < InnerVariable
391
+ def self.component_name_of(name)
392
+ ".#{name}"
393
+ end
394
+
395
+ def initialize(memory, outer_variable, type, name)
396
+ super(memory, outer_variable, type, self.class.component_name_of(name))
397
+ end
398
+ end
399
+
400
+ class AliasVariable < NamedVariable
401
+ def initialize(variable)
402
+ super(variable.binding.memory,
403
+ variable.declarations_and_definitions.first,
404
+ variable.scope)
405
+ end
406
+
407
+ private
408
+ def relate_to_memory(memory)
409
+ be_alias_to(memory)
410
+ end
411
+ end
412
+
413
+ class VariableTable
414
+ def initialize(memory_pool)
415
+ @memory_pool = memory_pool
416
+ @named_variables = [{}]
417
+ @temporary_variables = [[]]
418
+ @scope_stack = [GlobalScope.new]
419
+ end
420
+
421
+ def all_named_variables
422
+ @named_variables.map { |hash| hash.values }.flatten
423
+ end
424
+
425
+ def enter_scope
426
+ @named_variables.push({})
427
+ @temporary_variables.push([])
428
+ @scope_stack.push(Scope.new(@scope_stack.size))
429
+ end
430
+
431
+ def leave_scope
432
+ @named_variables.pop.each_value do |variable|
433
+ @memory_pool.free(variable.binding.memory)
434
+ end
435
+ @temporary_variables.pop.each do |variable|
436
+ @memory_pool.free(variable.binding.memory)
437
+ end
438
+ @scope_stack.pop
439
+ rollback_all_variables! if current_scope.global?
440
+ end
441
+
442
+ def declare(declaration)
443
+ if variable = lookup(declaration.identifier.value)
444
+ variable.declarations_and_definitions.push(declaration)
445
+ return variable
446
+ end
447
+
448
+ # NOTE: External variable may have undefined values.
449
+ define_variable(declaration, declaration.type,
450
+ allocate_memory(declaration),
451
+ declaration.type.undefined_value)
452
+ end
453
+
454
+ def define(definition, init_value = nil)
455
+ init_value ||= default_value_of(definition)
456
+
457
+ if variable = lookup(definition.identifier.value)
458
+ if variable.scope == current_scope
459
+ variable.declarations_and_definitions.push(definition)
460
+ variable.assign!(init_value)
461
+ return variable
462
+ end
463
+ end
464
+
465
+ # NOTE: Domain of the init-value will be restricted by type's min-max in
466
+ # define_variable.
467
+ define_variable(definition, definition.type, allocate_memory(definition),
468
+ init_value)
469
+ end
470
+
471
+ def define_temporary(type, init_value)
472
+ memory = @memory_pool.allocate_dynamic(type.aligned_byte_size)
473
+
474
+ # NOTE: Domain of the init-value will be restricted by type's min-max in
475
+ # define_variable.
476
+ define_variable(nil, type, memory, init_value)
477
+ end
478
+
479
+ def lookup(name_str)
480
+ @named_variables.reverse_each do |hash|
481
+ if variable = hash[name_str]
482
+ return variable
483
+ end
484
+ end
485
+ nil
486
+ end
487
+
488
+ def begin_versioning_group
489
+ @named_variables.each do |hash|
490
+ hash.each_value { |variable| variable.value.begin_versioning_group }
491
+ end
492
+ end
493
+
494
+ def end_versioning_group(raise_complement_values)
495
+ @named_variables.each do |hash|
496
+ hash.each_value do |variable|
497
+ variable.value.end_versioning_group(raise_complement_values)
498
+ end
499
+ end
500
+ end
501
+
502
+ def begin_versioning
503
+ @named_variables.each do |hash|
504
+ hash.each_value { |variable| variable.value.begin_versioning }
505
+ end
506
+ end
507
+
508
+ def end_versioning
509
+ @named_variables.each do |hash|
510
+ hash.each_value { |variable| variable.value.end_versioning }
511
+ end
512
+ end
513
+
514
+ def rollback_latest_version
515
+ @named_variables.each do |hash|
516
+ hash.each_value { |variable| variable.value.rollback! }
517
+ end
518
+ end
519
+
520
+ private
521
+ def define_variable(declaration_or_definition, type, memory, init_value)
522
+ variable = create_variable(declaration_or_definition, type, memory)
523
+ variable.assign!(init_value)
524
+
525
+ if variable.named?
526
+ @named_variables.last[variable.name] = variable
527
+ else
528
+ @temporary_variables.last.push(variable)
529
+ end
530
+
531
+ variable
532
+ end
533
+
534
+ def allocate_memory(declaration_or_definition)
535
+ byte_size = declaration_or_definition.type.aligned_byte_size
536
+ if storage_class_of(declaration_or_definition) == :static
537
+ @memory_pool.allocate_static(byte_size)
538
+ else
539
+ @memory_pool.allocate_dynamic(byte_size)
540
+ end
541
+ end
542
+
543
+ def default_value_of(definition)
544
+ if storage_class_of(definition) == :static
545
+ definition.type.zero_value
546
+ else
547
+ definition.type.undefined_value
548
+ end
549
+ end
550
+
551
+ def storage_class_of(declaration_or_definition)
552
+ storage_class_specifier =
553
+ declaration_or_definition.storage_class_specifier
554
+ if storage_class_specifier &&
555
+ (storage_class_specifier.type == :EXTERN ||
556
+ storage_class_specifier.type == :STATIC)
557
+ :static
558
+ else
559
+ current_scope.global? ? :static : :dynamic
560
+ end
561
+ end
562
+
563
+ def create_variable(declaration_or_definition, type, memory)
564
+ if declaration_or_definition
565
+ NamedVariable.new(memory, declaration_or_definition, current_scope)
566
+ else
567
+ TemporaryVariable.new(memory, type, current_scope)
568
+ end
569
+ end
570
+
571
+ def current_scope
572
+ @scope_stack.last
573
+ end
574
+
575
+ def rollback_all_variables!
576
+ @named_variables.first.each_value do |variable|
577
+ variable.value.rollback_to_original!
578
+ end
579
+ end
580
+ end
581
+
582
+ # == DESCRIPTION
583
+ # === Function class hierarchy
584
+ # Function
585
+ # <--- NamedFunction --- Nameable <<module>>
586
+ # <--- ExplicitFunction
587
+ # <--- ImplicitFunction
588
+ # <--- BuiltinFunction
589
+ # <--- AnonymousFunction
590
+ class Function < TypedObject
591
+ def initialize(declaration_or_definition, type)
592
+ super(type, declaration_or_definition)
593
+ end
594
+
595
+ def name
596
+ subclass_responsibility
597
+ end
598
+
599
+ def named?
600
+ false
601
+ end
602
+
603
+ def temporary?
604
+ false
605
+ end
606
+
607
+ def variable?
608
+ false
609
+ end
610
+
611
+ def function?
612
+ true
613
+ end
614
+
615
+ def explicit?
616
+ subclass_responsibility
617
+ end
618
+
619
+ def implicit?
620
+ !explicit?
621
+ end
622
+
623
+ def builtin?
624
+ subclass_responsibility
625
+ end
626
+
627
+ def call(interpreter, args)
628
+ assign_arguments_to_parameters(interpreter, args)
629
+ return_values_via_pointer_arguments(interpreter, args)
630
+
631
+ if type.return_type.function?
632
+ interpreter.temporary_variable
633
+ else
634
+ interpreter.temporary_variable(type.return_type,
635
+ type.return_type.return_value)
636
+ end
637
+ end
638
+
639
+ def signature
640
+ subclass_responsibility
641
+ end
642
+
643
+ private
644
+ def assign_arguments_to_parameters(interpreter, args)
645
+ args.zip(type.parameter_types).each do |(arg, expr), param_type|
646
+ next if param_type && param_type.void?
647
+
648
+ if param_type
649
+ case
650
+ when arg.type.array? && param_type.pointer?
651
+ arg_value = interpreter.pointer_value_of(arg)
652
+ converted = interpreter.temporary_variable(param_type, arg_value)
653
+ when arg.type.pointer? && param_type.array?
654
+ converted = interpreter.pointee_of(arg)
655
+ when arg.type.function? && param_type.pointer?
656
+ arg_value = interpreter.pointer_value_of(arg)
657
+ converted = interpreter.temporary_variable(param_type, arg_value)
658
+ when arg.variable? && !param_type.same_as?(arg.type)
659
+ converted =
660
+ interpreter.do_conversion(arg, param_type) ||
661
+ interpreter.temporary_variable(param_type)
662
+ else
663
+ next
664
+ end
665
+ else
666
+ converted = interpreter.do_default_argument_promotion(arg)
667
+ next if arg.type.same_as?(converted.type)
668
+ end
669
+
670
+ if converted
671
+ interpreter.notify_implicit_conv_performed(expr, arg, converted)
672
+ end
673
+ end
674
+ end
675
+
676
+ def return_values_via_pointer_arguments(interpreter, args)
677
+ args.zip(type.parameter_types).each do |(arg, expr), param_type|
678
+ next if param_type && param_type.void?
679
+ next unless arg.variable? && arg.value.scalar?
680
+
681
+ param_type = param_type.unqualify if param_type
682
+
683
+ if param_type && param_type.pointer? && !param_type.base_type.const? or
684
+ param_type.nil? && arg.type.pointer?
685
+ if pointee = interpreter.pointee_of(arg) and
686
+ pointee.designated_by_lvalue? && pointee.variable?
687
+ pointee.assign!(pointee.type.return_value)
688
+ interpreter.notify_variable_value_updated(expr, pointee)
689
+ end
690
+ end
691
+ end
692
+ end
693
+ end
694
+
695
+ class NamedFunction < Function
696
+ include Nameable
697
+
698
+ def initialize(declaration_or_definition, type, name)
699
+ super(declaration_or_definition, type)
700
+
701
+ self.name = name
702
+ end
703
+
704
+ def designated_by_lvalue?
705
+ true
706
+ end
707
+
708
+ def call(interpreter, args)
709
+ case name
710
+ when "exit", "_exit", "abort"
711
+ BreakEvent.of_return.throw
712
+ when "longjmp", "siglongjmp"
713
+ BreakEvent.of_return.throw
714
+ else
715
+ super
716
+ end
717
+ end
718
+
719
+ def signature
720
+ "#{type.return_type.brief_image} #{name}(" +
721
+ type.parameter_types.map { |ptype| ptype.brief_image }.join(",") +
722
+ (type.have_va_list? ? ",...)" : ")")
723
+ end
724
+ end
725
+
726
+ class ExplicitFunction < NamedFunction
727
+ def initialize(declaration_or_definition)
728
+ super(declaration_or_definition, declaration_or_definition.type,
729
+ declaration_or_definition.identifier.value)
730
+ end
731
+
732
+ def explicit?
733
+ true
734
+ end
735
+
736
+ def builtin?
737
+ false
738
+ end
739
+ end
740
+
741
+ class ImplicitFunction < NamedFunction
742
+ def initialize(type, name)
743
+ super(nil, type, name)
744
+ end
745
+
746
+ def explicit?
747
+ false
748
+ end
749
+
750
+ def builtin?
751
+ false
752
+ end
753
+ end
754
+
755
+ class AnonymousFunction < Function
756
+ def initialize(type)
757
+ super(nil, type)
758
+ end
759
+
760
+ def designated_by_lvalue?
761
+ false
762
+ end
763
+
764
+ def explicit?
765
+ false
766
+ end
767
+
768
+ def builtin?
769
+ false
770
+ end
771
+
772
+ def signature
773
+ "#{type.return_type.brief_image} __adlint__anonymous_func(" +
774
+ type.parameter_types.map { |ptype| ptype.brief_image }.join(",") +
775
+ (type.have_va_list? ? ",...)" : ")")
776
+ end
777
+ end
778
+
779
+ class FunctionTable
780
+ def initialize(memory_pool)
781
+ @memory_pool = memory_pool
782
+ @functions = [{}]
783
+ @scope_stack = [GlobalScope.new]
784
+ end
785
+
786
+ def enter_scope
787
+ @functions.push({})
788
+ @scope_stack.push(Scope.new(@scope_stack.size))
789
+ end
790
+
791
+ def leave_scope
792
+ @functions.pop.each_value do |function|
793
+ @memory_pool.free(function.binding.memory)
794
+ end
795
+ @scope_stack.pop
796
+ end
797
+
798
+ def define(function)
799
+ # NOTE: A function has a starting address in the TEXT segment.
800
+ # This is ad-hoc implementation, but it's enough for analysis.
801
+ function.bind_to(@memory_pool.allocate_static(0))
802
+
803
+ @functions.last[function.name] = function if function.named?
804
+ function
805
+ end
806
+
807
+ def lookup(name_str)
808
+ @functions.reverse_each do |hash|
809
+ if function = hash[name_str]
810
+ return function
811
+ end
812
+ end
813
+ nil
814
+ end
815
+ end
816
+
817
+ class Memory
818
+ include Bindable
819
+
820
+ def initialize(address, byte_size)
821
+ @address = address
822
+ @byte_size = byte_size
823
+ @value = nil
824
+ end
825
+
826
+ attr_reader :address
827
+ attr_reader :byte_size
828
+
829
+ def static?
830
+ subclass_responsibility
831
+ end
832
+
833
+ def dynamic?
834
+ subclass_responsibility
835
+ end
836
+
837
+ def read
838
+ @value ? @frozen_value ||= FrozenValue.new(@value) : nil
839
+ end
840
+
841
+ def read_modifiable
842
+ @value
843
+ end
844
+
845
+ def write(value)
846
+ if @value
847
+ @value.overwrite!(value)
848
+ else
849
+ @value = VersionedValue.new(value)
850
+ end
851
+ end
852
+ end
853
+
854
+ class MemoryBlock < Memory
855
+ def initialize(address, byte_size)
856
+ super
857
+
858
+ @windows = []
859
+ end
860
+
861
+ attr_reader :windows
862
+
863
+ def create_window(offset, byte_size)
864
+ window = MemoryWindow.new(self, @address + offset, byte_size)
865
+ window.on_written += method(:handle_written_through_window)
866
+ @windows.push(window)
867
+ window
868
+ end
869
+
870
+ def write(value)
871
+ super
872
+ if !@windows.empty? &&
873
+ (@value.array? && value.array?) ||
874
+ (@value.composite? && value.composite?)
875
+ single_value = value.to_single_value
876
+ @windows.zip(single_value.values).each do |window, inner_value|
877
+ window.write(inner_value, false)
878
+ end
879
+ end
880
+ end
881
+
882
+ protected
883
+ def create_value_from_windows
884
+ case
885
+ when @value.scalar?
886
+ @value
887
+ when @value.array?
888
+ ArrayValue.new(@windows.map { |w| w.create_value_from_windows })
889
+ when @value.composite?
890
+ CompositeValue.new(@windows.map { |w| w.create_value_from_windows })
891
+ end
892
+ end
893
+
894
+ private
895
+ def handle_written_through_window(window)
896
+ value = create_value_from_windows
897
+
898
+ if @value
899
+ @value.overwrite!(value)
900
+ else
901
+ @value = VersionedValue.new(value)
902
+ end
903
+ end
904
+ end
905
+
906
+ class MemoryWindow < MemoryBlock
907
+ def initialize(owner, address, byte_size)
908
+ super(address, byte_size)
909
+ @owner = owner
910
+ end
911
+
912
+ extend Pluggable
913
+
914
+ def_plugin :on_written
915
+
916
+ def static?
917
+ @owner.static?
918
+ end
919
+
920
+ def dynamic?
921
+ @owner.dynamic?
922
+ end
923
+
924
+ def write(value, cascade = true)
925
+ super(value)
926
+ on_written.invoke(self) if cascade
927
+ end
928
+
929
+ private
930
+ def handle_written_through_window(window)
931
+ super
932
+ on_written.invoke(self)
933
+ end
934
+ end
935
+
936
+ class StaticMemoryBlock < MemoryBlock
937
+ def static?
938
+ true
939
+ end
940
+
941
+ def dynamic?
942
+ false
943
+ end
944
+ end
945
+
946
+ class DynamicMemoryBlock < MemoryBlock
947
+ def static?
948
+ false
949
+ end
950
+
951
+ def dynamic?
952
+ true
953
+ end
954
+ end
955
+
956
+ class MemoryPool
957
+ def initialize
958
+ @memory_blocks = {}
959
+ @address_ranges = []
960
+ # NOTE: To make room for NULL and controlling expressions.
961
+ @free_address = 10
962
+ end
963
+
964
+ def allocate_static(byte_size)
965
+ memory_block = StaticMemoryBlock.new(@free_address, byte_size)
966
+ @free_address += allocating_byte_size(byte_size)
967
+ @memory_blocks[memory_block.address] = memory_block
968
+ @address_ranges.push(memory_block.address...@free_address)
969
+ memory_block
970
+ end
971
+
972
+ def allocate_dynamic(byte_size)
973
+ memory_block = DynamicMemoryBlock.new(@free_address, byte_size)
974
+ @free_address += allocating_byte_size(byte_size)
975
+ @memory_blocks[memory_block.address] = memory_block
976
+ @address_ranges.push(memory_block.address...@free_address)
977
+ memory_block
978
+ end
979
+
980
+ def free(memory_block)
981
+ @memory_blocks.delete(memory_block.address)
982
+ @address_ranges.reject! { |range| range.include?(memory_block.address) }
983
+ end
984
+
985
+ def lookup(address)
986
+ if memory_block = @memory_blocks[address]
987
+ return memory_block
988
+ else
989
+ if addr_range = @address_ranges.find { |r| r.include?(address) }
990
+ memory_block = @memory_blocks[addr_range.first]
991
+ return memory_block.windows.find { |w| w.address == address }
992
+ end
993
+ end
994
+ nil
995
+ end
996
+
997
+ private
998
+ def allocating_byte_size(byte_size)
999
+ byte_size == 0 ? 1 : byte_size
1000
+ end
1001
+ end
1002
+
1003
+ class EnumeratorTable
1004
+ def initialize
1005
+ @enumerators = {}
1006
+ end
1007
+
1008
+ def define(enumerator)
1009
+ @enumerators[enumerator.identifier.value] = enumerator
1010
+ end
1011
+
1012
+ def lookup(name_str)
1013
+ @enumerators[name_str]
1014
+ end
1015
+ end
1016
+
1017
+ end
1018
+ end