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,1012 @@
1
+ # C preprocessor.
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/error"
33
+ require "adlint/source"
34
+ require "adlint/report"
35
+ require "adlint/cpp/syntax"
36
+ require "adlint/cpp/source"
37
+ require "adlint/cpp/macro"
38
+ require "adlint/cpp/lexer"
39
+ require "adlint/cpp/constexpr"
40
+
41
+ module AdLint #:nodoc:
42
+ module Cpp #:nodoc:
43
+
44
+ # == DESCRIPTION
45
+ # C preprocessor language evaluator.
46
+ #
47
+ # Preprocessor executes recursive descent parsing and evaluation at a time.
48
+ class Preprocessor
49
+ include ReportUtil
50
+
51
+ def execute(context, source)
52
+ @context = context
53
+ context.push_lexer(create_lexer(context, source))
54
+ preprocessing_file(context)
55
+ end
56
+
57
+ extend Pluggable
58
+
59
+ def_plugin :on_user_header_included
60
+ def_plugin :on_system_header_included
61
+ def_plugin :on_object_like_macro_defined
62
+ def_plugin :on_function_like_macro_defined
63
+ def_plugin :on_va_function_like_macro_defined
64
+ def_plugin :on_asm_section_evaled
65
+ def_plugin :on_unknown_pragma_evaled
66
+ def_plugin :on_pp_token_extracted
67
+ def_plugin :on_block_comment_found
68
+ def_plugin :on_line_comment_found
69
+ def_plugin :on_nested_block_comment_found
70
+ def_plugin :on_eof_newline_not_found
71
+ def_plugin :on_unlexable_char_found
72
+ def_plugin :on_cr_at_eol_found
73
+ def_plugin :on_eof_mark_at_eof_found
74
+ def_plugin :on_illformed_defined_op_found
75
+ def_plugin :on_undefined_macro_referred
76
+
77
+ private
78
+ def preprocessing_file(context)
79
+ PreprocessingFile.new(context.translation_unit_fpath, group(context))
80
+ end
81
+
82
+ def group(context)
83
+ if group_part = group_part(context)
84
+ group = Group.new.push(group_part)
85
+ while group_part = group_part(context)
86
+ group.push(group_part)
87
+ end
88
+ return group
89
+ end
90
+ nil
91
+ end
92
+
93
+ def group_part(context)
94
+ if top_token = context.top_token
95
+ case top_token.type
96
+ when :IF, :IFDEF, :IFNDEF
97
+ return if_section(context)
98
+ when :INCLUDE, :INCLUDE_NEXT, :DEFINE, :UNDEF, :LINE, :ERROR, :PRAGMA
99
+ return control_line(context)
100
+ when :ASM
101
+ return asm_section(context)
102
+ when :NULL_DIRECTIVE
103
+ return NullDirective.new(context.next_token)
104
+ when :TEXT_LINE
105
+ text_line = TextLine.new(context.next_token)
106
+ tokens = TextLineNormalizer.normalize(text_line, context)
107
+ if tokens
108
+ context.deferred_text_lines.clear
109
+ tokens.each do |token|
110
+ context.source.add_token(token)
111
+ notify_pp_token_extracted(token)
112
+ end
113
+ else
114
+ context.deferred_text_lines.push(text_line)
115
+ end
116
+ return text_line
117
+ end
118
+ end
119
+ nil
120
+ end
121
+
122
+ def if_section(context)
123
+ context.push_branch
124
+ if_group = if_group(context)
125
+
126
+ while top_token = context.top_token
127
+ case top_token.type
128
+ when :ELIF
129
+ elif_groups = elif_groups(context)
130
+ when :ELSE
131
+ else_group = else_group(context)
132
+ when :ENDIF
133
+ endif_line = endif_line(context)
134
+ break
135
+ end
136
+ end
137
+
138
+ E(:E0004, if_group.location) unless endif_line
139
+
140
+ context.pop_branch
141
+ IfSection.new(if_group, elif_groups, else_group, endif_line)
142
+ end
143
+
144
+ def if_group(context)
145
+ if keyword = context.top_token
146
+ case keyword.type
147
+ when :IF
148
+ return if_statement(context)
149
+ when :IFDEF
150
+ return ifdef_statement(context)
151
+ when :IFNDEF
152
+ return ifndef_statement(context)
153
+ end
154
+ end
155
+ nil
156
+ end
157
+
158
+ def if_statement(context)
159
+ keyword = context.next_token
160
+ unless pp_tokens = pp_tokens(context)
161
+ return nil
162
+ end
163
+ unless new_line = context.next_token and new_line.type == :NEW_LINE
164
+ return nil
165
+ end
166
+ expression = ExpressionNormalizer.normalize(pp_tokens, context, self)
167
+ if expression.value == 0
168
+ context.skip_group
169
+ else
170
+ group = group(context)
171
+ context.branch_evaluated = true
172
+ end
173
+ IfStatement.new(keyword, expression, group)
174
+ end
175
+
176
+ def ifdef_statement(context)
177
+ keyword = context.next_token
178
+ unless identifier = context.next_token and identifier.type == :IDENTIFIER
179
+ return nil
180
+ end
181
+ unless new_line = context.next_token and new_line.type == :NEW_LINE
182
+ return nil
183
+ end
184
+ if macro_defined?(context, identifier)
185
+ group = group(context)
186
+ context.branch_evaluated = true
187
+ else
188
+ context.skip_group
189
+ end
190
+ IfdefStatement.new(keyword, identifier, group)
191
+ end
192
+
193
+ def ifndef_statement(context)
194
+ keyword = context.next_token
195
+ unless identifier = context.next_token and identifier.type == :IDENTIFIER
196
+ return nil
197
+ end
198
+ unless new_line = context.next_token and new_line.type == :NEW_LINE
199
+ return nil
200
+ end
201
+ if macro_defined?(context, identifier)
202
+ context.skip_group
203
+ else
204
+ group = group(context)
205
+ context.branch_evaluated = true
206
+ end
207
+ IfndefStatement.new(keyword, identifier, group)
208
+ end
209
+
210
+ def elif_groups(context)
211
+ if elif_group = elif_group(context)
212
+ elif_groups = ElifGroups.new.push(elif_group)
213
+ while elif_group = elif_group(context)
214
+ elif_groups.push(elif_group)
215
+ end
216
+ return elif_groups
217
+ end
218
+ nil
219
+ end
220
+
221
+ def elif_group(context)
222
+ unless top_token = context.top_token and top_token.type == :ELIF
223
+ return nil
224
+ end
225
+
226
+ if keyword = context.next_token
227
+ if keyword.type == :ELIF
228
+ unless pp_tokens = pp_tokens(context)
229
+ return nil
230
+ end
231
+ unless new_line = context.next_token and new_line.type == :NEW_LINE
232
+ return nil
233
+ end
234
+ expression = ExpressionNormalizer.normalize(pp_tokens, context, self)
235
+ if context.branch_evaluated? || expression.value == 0
236
+ context.skip_group
237
+ else
238
+ group = group(context)
239
+ context.branch_evaluated = true
240
+ end
241
+ return ElifStatement.new(keyword, expression, group)
242
+ end
243
+ end
244
+ nil
245
+ end
246
+
247
+ def else_group(context)
248
+ if keyword = context.next_token
249
+ if keyword.type == :ELSE
250
+ unless new_line = context.next_token and new_line.type == :NEW_LINE
251
+ return nil
252
+ end
253
+ if context.branch_evaluated?
254
+ context.skip_group
255
+ else
256
+ group = group(context)
257
+ context.branch_evaluated = true
258
+ end
259
+ return ElseStatement.new(keyword, group)
260
+ end
261
+ end
262
+ nil
263
+ end
264
+
265
+ def endif_line(context)
266
+ if keyword = context.next_token
267
+ if keyword.type == :ENDIF
268
+ unless new_line = context.next_token and new_line.type == :NEW_LINE
269
+ return nil
270
+ end
271
+ return EndifLine.new(keyword)
272
+ end
273
+ end
274
+ nil
275
+ end
276
+
277
+ def control_line(context)
278
+ if keyword = context.top_token
279
+ case keyword.type
280
+ when :INCLUDE
281
+ return include_line(context)
282
+ when :INCLUDE_NEXT
283
+ return include_next_line(context)
284
+ when :DEFINE
285
+ return define_line(context)
286
+ when :UNDEF
287
+ return undef_line(context)
288
+ when :LINE
289
+ return line_line(context)
290
+ when :ERROR
291
+ return error_line(context)
292
+ when :PRAGMA
293
+ return pragma_line(context)
294
+ end
295
+ end
296
+ nil
297
+ end
298
+
299
+ def include_line(context)
300
+ keyword = context.next_token
301
+ if header_name = context.top_token
302
+ case header_name.type
303
+ when :USR_HEADER_NAME
304
+ return user_include_line(context, keyword)
305
+ when :SYS_HEADER_NAME
306
+ return system_include_line(context, keyword)
307
+ else
308
+ return macro_include_line(context, keyword)
309
+ end
310
+ end
311
+ nil
312
+ end
313
+
314
+ def include_next_line(context)
315
+ keyword = context.next_token
316
+ if header_name = context.top_token
317
+ case header_name.type
318
+ when :USR_HEADER_NAME
319
+ return user_include_next_line(context, keyword)
320
+ when :SYS_HEADER_NAME
321
+ return system_include_next_line(context, keyword)
322
+ else
323
+ return macro_include_next_line(context, keyword)
324
+ end
325
+ end
326
+ nil
327
+ end
328
+
329
+ def user_include_line(context, keyword)
330
+ header_name = context.next_token
331
+ unless new_line = context.next_token and new_line.type == :NEW_LINE
332
+ return nil
333
+ end
334
+ user_include_line =
335
+ UserIncludeLine.new(keyword, header_name, context.include_depth)
336
+ include_first_user_header(user_include_line, context)
337
+ user_include_line
338
+ end
339
+
340
+ def user_include_next_line(context, keyword)
341
+ header_name = context.next_token
342
+ unless new_line = context.next_token and new_line.type == :NEW_LINE
343
+ return nil
344
+ end
345
+ user_include_next_line =
346
+ UserIncludeNextLine.new(keyword, header_name, context.include_depth)
347
+ include_next_user_header(user_include_next_line, context)
348
+ user_include_next_line
349
+ end
350
+
351
+ def system_include_line(context, keyword)
352
+ header_name = context.next_token
353
+ unless new_line = context.next_token and new_line.type == :NEW_LINE
354
+ return nil
355
+ end
356
+ system_include_line =
357
+ SystemIncludeLine.new(keyword, header_name, context.include_depth)
358
+ include_first_system_header(system_include_line, context)
359
+ system_include_line
360
+ end
361
+
362
+ def system_include_next_line(context, keyword)
363
+ header_name = context.next_token
364
+ unless new_line = context.next_token and new_line.type == :NEW_LINE
365
+ return nil
366
+ end
367
+ system_include_next_line =
368
+ SystemIncludeNextLine.new(keyword, header_name, context.include_depth)
369
+ include_next_system_header(system_include_next_line, context)
370
+ system_include_next_line
371
+ end
372
+
373
+ def macro_include_line(context, keyword)
374
+ unless pp_tokens = pp_tokens(context)
375
+ return nil
376
+ end
377
+ unless new_line = context.next_token and new_line.type == :NEW_LINE
378
+ return nil
379
+ end
380
+ tokens = PPTokensNormalizer.normalize(pp_tokens, context)
381
+ return nil if tokens.empty?
382
+ case parameter = tokens.map { |t| t.value }.join
383
+ when /\A".*"\z/
384
+ user_include_line = UserIncludeLine.new(
385
+ keyword, Token.new(:USR_HEADER_NAME, parameter,
386
+ pp_tokens.tokens.first.location),
387
+ context.include_depth)
388
+ include_first_user_header(user_include_line, context)
389
+ return user_include_line
390
+ when /\A<.*>\z/
391
+ system_include_line = SystemIncludeLine.new(
392
+ keyword, Token.new(:SYS_HEADER_NAME, parameter,
393
+ pp_tokens.tokens.first.location),
394
+ context.include_depth)
395
+ include_first_system_header(system_include_line, context)
396
+ return system_include_line
397
+ end
398
+ nil
399
+ end
400
+
401
+ def macro_include_next_line(context, keyword)
402
+ unless pp_tokens = pp_tokens(context)
403
+ return nil
404
+ end
405
+ unless new_line = context.next_token and new_line.type == :NEW_LINE
406
+ return nil
407
+ end
408
+ tokens = PPTokensNormalizer.normalize(pp_tokens, context)
409
+ return nil if tokens.empty?
410
+ case parameter = tokens.map { |t| t.value }.join
411
+ when /\A".*"\z/
412
+ user_include_next_line = UserIncludeNextLine.new(
413
+ keyword, Token.new(:USR_HEADER_NAME, parameter,
414
+ pp_tokens.tokens.first.location),
415
+ context.include_depth)
416
+ include_next_user_header(user_include_next_line, context)
417
+ return user_include_next_line
418
+ when /\A<.*>\z/
419
+ system_include_next_line = SystemIncludeNextLine.new(
420
+ keyword, Token.new(:SYS_HEADER_NAME, parameter,
421
+ pp_tokens.tokens.first.location),
422
+ context.include_depth)
423
+ include_next_system_header(system_include_next_line, context)
424
+ return system_include_next_line
425
+ end
426
+ nil
427
+ end
428
+
429
+ def define_line(context)
430
+ keyword = context.next_token
431
+ unless identifier = context.next_token and identifier.type == :IDENTIFIER
432
+ return nil
433
+ end
434
+ symbol = context.symbol_table.create_new_symbol(MacroName, identifier)
435
+
436
+ if paren = context.top_token and paren.type == "("
437
+ context.next_token
438
+ identifier_list = identifier_list(context)
439
+ unless paren_or_ellipsis = context.next_token
440
+ return nil
441
+ end
442
+ case paren_or_ellipsis.type
443
+ when "..."
444
+ ellipsis = paren_or_ellipsis
445
+ if paren = context.top_token and paren.type == ")"
446
+ context.next_token
447
+ else
448
+ return nil
449
+ end
450
+ when ")"
451
+ ellipsis = nil
452
+ else
453
+ return nil
454
+ end
455
+ replacement_list = replacement_list(context)
456
+ unless new_line = context.next_token and new_line.type == :NEW_LINE
457
+ return nil
458
+ end
459
+ if ellipsis
460
+ define_line = VaFunctionLikeDefineLine.new(keyword, identifier,
461
+ identifier_list,
462
+ replacement_list, symbol)
463
+ macro = FunctionLikeMacro.new(define_line)
464
+ notify_va_function_like_macro_defined(define_line, macro)
465
+ else
466
+ define_line = FunctionLikeDefineLine.new(keyword, identifier,
467
+ identifier_list,
468
+ replacement_list, symbol)
469
+ macro = FunctionLikeMacro.new(define_line)
470
+ notify_function_like_macro_defined(define_line, macro)
471
+ end
472
+ else
473
+ replacement_list = replacement_list(context)
474
+ unless new_line = context.next_token and new_line.type == :NEW_LINE
475
+ return nil
476
+ end
477
+ define_line = ObjectLikeDefineLine.new(keyword, identifier,
478
+ replacement_list, symbol)
479
+ macro = ObjectLikeMacro.new(define_line)
480
+ notify_object_like_macro_defined(define_line, macro)
481
+ end
482
+
483
+ context.macro_table.define(macro)
484
+ define_line
485
+ end
486
+
487
+ def undef_line(context)
488
+ keyword = context.next_token
489
+ unless identifier = context.next_token and identifier.type == :IDENTIFIER
490
+ return nil
491
+ end
492
+ unless new_line = context.next_token and new_line.type == :NEW_LINE
493
+ return nil
494
+ end
495
+ context.macro_table.undef(identifier.value)
496
+ UndefLine.new(keyword, identifier)
497
+ end
498
+
499
+ def line_line(context)
500
+ keyword = context.next_token
501
+ unless pp_tokens = pp_tokens(context)
502
+ return nil
503
+ end
504
+ unless new_line = context.next_token and new_line.type == :NEW_LINE
505
+ return nil
506
+ end
507
+ LineLine.new(keyword, pp_tokens)
508
+ end
509
+
510
+ def error_line(context)
511
+ keyword = context.next_token
512
+ pp_tokens = pp_tokens(context)
513
+ unless new_line = context.next_token and new_line.type == :NEW_LINE
514
+ return nil
515
+ end
516
+ ErrorLine.new(keyword, pp_tokens)
517
+ end
518
+
519
+ def pragma_line(context)
520
+ keyword = context.next_token
521
+ pp_tokens = pp_tokens(context)
522
+ unless new_line = context.next_token and new_line.type == :NEW_LINE
523
+ return nil
524
+ end
525
+ pragma_line = PragmaLine.new(keyword, pp_tokens)
526
+ if pp_tokens.tokens.size == 1 && pp_tokens.tokens.first.value == "once"
527
+ context.once_set.add(keyword.location.fpath)
528
+ else
529
+ notify_unknown_pragma_evaled(pragma_line)
530
+ end
531
+ pragma_line
532
+ end
533
+
534
+ def identifier_list(context)
535
+ unless identifier = context.top_token and identifier.type == :IDENTIFIER
536
+ return nil
537
+ end
538
+ identifier_list = IdentifierList.new
539
+ while token = context.next_token
540
+ if token.type == :IDENTIFIER
541
+ identifier_list.push(token)
542
+ end
543
+ if comma = context.top_token and comma.type == ","
544
+ context.next_token
545
+ else
546
+ break
547
+ end
548
+ unless identifier = context.top_token and
549
+ identifier.type == :IDENTIFIER
550
+ break
551
+ end
552
+ end
553
+ identifier_list
554
+ end
555
+
556
+ def replacement_list(context)
557
+ pp_tokens(context)
558
+ end
559
+
560
+ def pp_tokens(context)
561
+ unless pp_token = context.top_token and pp_token.type == :PP_TOKEN
562
+ return nil
563
+ end
564
+ pp_tokens = PPTokens.new
565
+ while token = context.top_token
566
+ if token.type == :PP_TOKEN
567
+ pp_tokens.push(context.next_token)
568
+ else
569
+ break
570
+ end
571
+ end
572
+ pp_tokens
573
+ end
574
+
575
+ def asm_section(context)
576
+ asm_line = asm_line(context)
577
+ context.skip_group
578
+ endasm_line = endasm_line(context)
579
+ asm_section = AsmSection.new(asm_line, endasm_line)
580
+ notify_asm_section_evaled(asm_section)
581
+ asm_section
582
+ end
583
+
584
+ def asm_line(context)
585
+ if keyword = context.next_token
586
+ if keyword.type == :ASM
587
+ unless new_line = context.next_token and new_line.type == :NEW_LINE
588
+ return nil
589
+ end
590
+ return AsmLine.new(keyword)
591
+ end
592
+ end
593
+ nil
594
+ end
595
+
596
+ def endasm_line(context)
597
+ if keyword = context.next_token
598
+ if keyword.type == :ENDASM
599
+ unless new_line = context.next_token and new_line.type == :NEW_LINE
600
+ return nil
601
+ end
602
+ return EndasmLine.new(keyword)
603
+ end
604
+ end
605
+ nil
606
+ end
607
+
608
+ def include_first_user_header(user_include_line, context)
609
+ basename =
610
+ user_include_line.header_name.value.sub(/\A"(.*)"\z/, "\\1")
611
+ current_dpath = user_include_line.location.fpath.dirname
612
+ if fpath = resolve_first_user_header(basename, current_dpath)
613
+ include_user_header(fpath, user_include_line, context)
614
+ else
615
+ E(:E0010, user_include_line.location, basename)
616
+ raise MissingUserHeaderError.new(user_include_line.location, basename,
617
+ context.msg_fpath, context.log_fpath)
618
+ end
619
+ end
620
+
621
+ def include_next_user_header(user_include_next_line, context)
622
+ basename =
623
+ user_include_next_line.header_name.value.sub(/\A"(.*)"\z/, "\\1")
624
+ current_dpath = user_include_next_line.location.fpath.dirname
625
+ if fpath = resolve_next_user_header(basename, current_dpath)
626
+ include_user_header(fpath, user_include_next_line, context)
627
+ else
628
+ E(:E0010, user_include_line.location, basename)
629
+ raise MissingUserHeaderError.new(user_include_next_line.location,
630
+ basename,
631
+ context.msg_fpath, context.log_fpath)
632
+ end
633
+ end
634
+
635
+ def include_user_header(fpath, user_include_line, context)
636
+ unless context.once_set.include?(fpath)
637
+ Analyzer.current.info("including \"#{fpath}\" at " +
638
+ "#{user_include_line.location.to_s}")
639
+ user_include_line.fpath = fpath
640
+ user_header = UserHeader.new(fpath, user_include_line.location)
641
+ context.push_lexer(create_lexer(context, user_header))
642
+ context.sources.push(user_header)
643
+ notify_user_header_included(user_include_line, user_header)
644
+ end
645
+ end
646
+
647
+ def include_first_system_header(system_include_line, context)
648
+ basename =
649
+ system_include_line.header_name.value.sub(/\A<(.*)>\z/, "\\1")
650
+ if fpath = resolve_first_system_header(basename)
651
+ include_system_header(fpath, system_include_line, context)
652
+ else
653
+ E(:E0009, system_include_line.location, basename)
654
+ raise MissingSystemHeaderError.new(system_include_line.location,
655
+ basename,
656
+ context.msg_fpath,
657
+ context.log_fpath)
658
+ end
659
+ end
660
+
661
+ def include_next_system_header(system_include_next_line, context)
662
+ basename =
663
+ system_include_next_line.header_name.value.sub(/\A<(.*)>\z/, "\\1")
664
+ if fpath = resolve_next_system_header(basename)
665
+ include_system_header(fpath, system_include_next_line, context)
666
+ else
667
+ E(:E0009, system_include_line.location, basename)
668
+ raise MissingSystemHeaderError.new(system_include_line.location,
669
+ basename,
670
+ context.msg_fpath,
671
+ context.log_fpath)
672
+ end
673
+ end
674
+
675
+ def include_system_header(fpath, system_include_line, context)
676
+ unless context.once_set.include?(fpath)
677
+ Analyzer.current.info("including <#{fpath}> at " +
678
+ "#{system_include_line.location.to_s}")
679
+ system_include_line.fpath = fpath
680
+ system_header = SystemHeader.new(fpath, system_include_line.location)
681
+ context.push_lexer(create_lexer(context, system_header))
682
+ context.sources.push(system_header)
683
+ notify_system_header_included(system_include_line, system_header)
684
+ end
685
+ end
686
+
687
+ def resolve_first_user_header(basename, current_dpath)
688
+ resolve_user_headers(basename, current_dpath, 1).first
689
+ end
690
+
691
+ def resolve_next_user_header(basename, current_dpath)
692
+ resolve_user_headers(basename, current_dpath, 2).last
693
+ end
694
+
695
+ def resolve_user_headers(basename, current_dpath, max_num)
696
+ include_paths = [current_dpath]
697
+ include_paths += Traits.instance.of_project.include_path
698
+ include_paths += Traits.instance.of_compiler.include_path
699
+
700
+ result = []
701
+ include_paths.each do |dpath|
702
+ fpath = dpath.join(Pathname.new(basename))
703
+ result.push(fpath) if File.readable?(fpath)
704
+ break if result.size == max_num
705
+ end
706
+ result
707
+ end
708
+
709
+ def resolve_first_system_header(basename)
710
+ resolve_system_headers(basename, 1).first
711
+ end
712
+
713
+ def resolve_next_system_header(basename)
714
+ resolve_system_headers(basename, 2).last
715
+ end
716
+
717
+ def resolve_system_headers(basename, max_num)
718
+ include_paths = Traits.instance.of_project.include_path
719
+ include_paths += Traits.instance.of_compiler.include_path
720
+
721
+ result = []
722
+ include_paths.each do |dpath|
723
+ fpath = dpath.join(Pathname.new(basename))
724
+ result.push(fpath) if File.readable?(fpath)
725
+ break if result.size == max_num
726
+ end
727
+ result
728
+ end
729
+
730
+ def macro_defined?(context, identifier)
731
+ if macro = context.macro_table.lookup(identifier.value)
732
+ macro.define_line.mark_as_referred_by(identifier)
733
+ true
734
+ else
735
+ false
736
+ end
737
+ end
738
+
739
+ def create_lexer(context, source)
740
+ Lexer.new(source).tap { |lexer| attach_lexer_plugin(lexer, context) }
741
+ end
742
+
743
+ def attach_lexer_plugin(lexer, context)
744
+ lexer.on_block_comment_found += lambda { |comment, location|
745
+ on_block_comment_found.invoke(comment, location)
746
+ }
747
+ lexer.on_line_comment_found += lambda { |comment, location|
748
+ on_line_comment_found.invoke(comment, location)
749
+ }
750
+ lexer.on_nested_block_comment_found += lambda { |location|
751
+ on_nested_block_comment_found.invoke(location)
752
+ }
753
+ lexer.on_unterminated_block_comment += lambda { |location|
754
+ handle_unterminated_block_comment(context, location)
755
+ }
756
+ lexer.on_eof_newline_not_found += lambda { |location|
757
+ on_eof_newline_not_found.invoke(location)
758
+ }
759
+ lexer.on_unlexable_char_found += lambda { |char, location|
760
+ on_unlexable_char_found.invoke(char, location)
761
+ }
762
+ lexer.on_cr_at_eol_found += lambda { |location|
763
+ on_cr_at_eol_found.invoke(location)
764
+ }
765
+ lexer.on_eof_mark_at_eof_found += lambda { |location|
766
+ on_eof_mark_at_eof_found.invoke(location)
767
+ }
768
+ end
769
+
770
+ def notify_user_header_included(user_include_line, user_header)
771
+ on_user_header_included.invoke(user_include_line, user_header)
772
+ end
773
+
774
+ def notify_system_header_included(system_include_line, system_header)
775
+ on_system_header_included.invoke(system_include_line, system_header)
776
+ end
777
+
778
+ def notify_object_like_macro_defined(define_line, macro)
779
+ on_object_like_macro_defined.invoke(define_line, macro)
780
+ end
781
+
782
+ def notify_function_like_macro_defined(define_line, macro)
783
+ on_function_like_macro_defined.invoke(define_line, macro)
784
+ end
785
+
786
+ def notify_va_function_like_macro_defined(define_line, macro)
787
+ on_va_function_like_macro_defined.invoke(define_line, macro)
788
+ end
789
+
790
+ def notify_asm_section_evaled(asm_section)
791
+ on_asm_section_evaled.invoke(asm_section)
792
+ end
793
+
794
+ def notify_unknown_pragma_evaled(pragma_line)
795
+ on_unknown_pragma_evaled.invoke(pragma_line)
796
+ end
797
+
798
+ def notify_pp_token_extracted(pp_token)
799
+ on_pp_token_extracted.invoke(pp_token)
800
+ end
801
+
802
+ def notify_illformed_defined_op_found(location)
803
+ on_illformed_defined_op_found.invoke(location)
804
+ end
805
+
806
+ def notify_undefined_macro_referred(identifier)
807
+ on_undefined_macro_referred.invoke(identifier)
808
+ end
809
+
810
+ def handle_unterminated_block_comment(context, location)
811
+ E(:E0016, location)
812
+ raise UnterminatedCommentError.new(location,
813
+ context.msg_fpath, context.log_fpath)
814
+ end
815
+
816
+ def report
817
+ @context.report
818
+ end
819
+ end
820
+
821
+ class PreprocessContext
822
+ def initialize(phase_context)
823
+ @phase_context = phase_context
824
+ @deferred_text_lines = []
825
+ @lexer_stack = []
826
+ @branch_stack = []
827
+ @once_set = Set.new
828
+ end
829
+
830
+ attr_reader :deferred_text_lines
831
+ attr_reader :once_set
832
+
833
+ def translation_unit_fpath
834
+ @phase_context[:sources].first.fpath
835
+ end
836
+
837
+ def source
838
+ @phase_context[:c_source]
839
+ end
840
+
841
+ def sources
842
+ @phase_context[:sources]
843
+ end
844
+
845
+ def symbol_table
846
+ @phase_context[:symbol_table]
847
+ end
848
+
849
+ def macro_table
850
+ @phase_context[:cpp_macro_table]
851
+ end
852
+
853
+ def report
854
+ @phase_context.report
855
+ end
856
+
857
+ def msg_fpath
858
+ @phase_context.msg_fpath
859
+ end
860
+
861
+ def log_fpath
862
+ @phase_context.log_fpath
863
+ end
864
+
865
+ def push_lexer(lexer)
866
+ @lexer_stack.push(lexer)
867
+ end
868
+
869
+ def top_token
870
+ return nil if @lexer_stack.empty?
871
+ unless token = @lexer_stack.last.top_token
872
+ @lexer_stack.pop
873
+ top_token
874
+ else
875
+ token
876
+ end
877
+ end
878
+
879
+ def next_token
880
+ return nil unless top_token
881
+ @last_token = @lexer_stack.last.next_token
882
+ end
883
+
884
+ def skip_group
885
+ until @lexer_stack.last.skip_group
886
+ @lexer_stack.pop
887
+ break if @lexer_stack.empty?
888
+ end
889
+ end
890
+
891
+ def push_branch
892
+ @branch_stack.push(false)
893
+ end
894
+
895
+ def pop_branch
896
+ @branch_stack.pop
897
+ end
898
+
899
+ def branch_evaluated=(evaluated)
900
+ @branch_stack[-1] = evaluated
901
+ end
902
+
903
+ def branch_evaluated?
904
+ @branch_stack.last
905
+ end
906
+
907
+ def include_depth
908
+ @lexer_stack.size
909
+ end
910
+ end
911
+
912
+ module PPTokensNormalizer
913
+ def normalize(pp_tokens, context)
914
+ context.macro_table.replace(pp_tokens.tokens)
915
+ pp_tokens.tokens
916
+ end
917
+ module_function :normalize
918
+ end
919
+
920
+ module ExpressionNormalizer
921
+ def normalize(pp_tokens, context, preprocessor = nil)
922
+ tokens = PPTokensNormalizer.normalize(pp_tokens, context)
923
+ const_expr = ConstantExpression.new(context, tokens)
924
+ if preprocessor
925
+ const_expr.on_illformed_defined_op_found +=
926
+ preprocessor.method(:notify_illformed_defined_op_found)
927
+ const_expr.on_undefined_macro_referred +=
928
+ preprocessor.method(:notify_undefined_macro_referred)
929
+ end
930
+ const_expr.evaluate
931
+ end
932
+ module_function :normalize
933
+ end
934
+
935
+ module TextLineNormalizer
936
+ def normalize(text_line, context)
937
+ pp_tokens = []
938
+ unless context.deferred_text_lines.empty?
939
+ context.deferred_text_lines.each do |deferred_line|
940
+ lexer = TextLineToPPTokensLexer.new(deferred_line)
941
+ pp_tokens += lexer.execute.to_a
942
+ end
943
+ end
944
+
945
+ lexer = TextLineToPPTokensLexer.new(text_line)
946
+ pp_tokens += lexer.execute.to_a
947
+
948
+ function_like_macro_referred = pp_tokens.any? { |t|
949
+ (macro = context.macro_table.lookup(t.value)) ?
950
+ macro.function_like? : false
951
+ }
952
+
953
+ if function_like_macro_referred
954
+ return nil unless complete_macro_reference?(pp_tokens, context)
955
+ end
956
+
957
+ context.macro_table.replace(pp_tokens)
958
+ pp_tokens
959
+ end
960
+ module_function :normalize
961
+
962
+ def complete_macro_reference?(pp_tokens, context)
963
+ index = 0
964
+ while token = pp_tokens[index]
965
+ index += 1
966
+ macro = context.macro_table.lookup(token.value)
967
+ if macro && macro.function_like?
968
+ next if not_calling_function_like_macro?(pp_tokens, index)
969
+ else
970
+ next
971
+ end
972
+
973
+ # NOTE: It's not completed when a new-line appears after the macro
974
+ # name.
975
+ return false unless pp_tokens[index..-1].any? { |t| t.value == "(" }
976
+
977
+ paren_count = 0
978
+ while token = pp_tokens[index]
979
+ case token.value
980
+ when "("
981
+ paren_count += 1
982
+ when ")"
983
+ paren_count -= 1
984
+ break if paren_count == 0
985
+ end
986
+ index += 1
987
+ end
988
+
989
+ return false if paren_count > 0
990
+ end
991
+ true
992
+ end
993
+ module_function :complete_macro_reference?
994
+
995
+ def not_calling_function_like_macro?(pp_tokens, index)
996
+ while pp_token = pp_tokens[index]
997
+ case
998
+ when pp_token.value == "("
999
+ return false
1000
+ when pp_token.type == :NEW_LINE
1001
+ index += 1
1002
+ else
1003
+ return true
1004
+ end
1005
+ end
1006
+ false
1007
+ end
1008
+ module_function :not_calling_function_like_macro?
1009
+ end
1010
+
1011
+ end
1012
+ end