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,860 @@
1
+ # Lexical analyzer which tokenizes C language source into pp-tokens.
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/lexer"
33
+ require "adlint/report"
34
+ require "adlint/util"
35
+
36
+ module AdLint #:nodoc:
37
+ module Cpp #:nodoc:
38
+
39
+ class Lexer
40
+ def initialize(source)
41
+ source.on_cr_at_eol_found += lambda { |location|
42
+ on_cr_at_eol_found.invoke(location)
43
+ }
44
+ source.on_eof_mark_at_eof_found += lambda { |location|
45
+ on_eof_mark_at_eof_found.invoke(location)
46
+ }
47
+ source.on_eof_newline_not_found += method(:notify_eof_newline_not_found)
48
+
49
+ @content = SourceContent.lazy_new(source)
50
+ @state = Initial.new(self)
51
+ @top_token = nil
52
+ end
53
+
54
+ attr_reader :content
55
+
56
+ extend Pluggable
57
+
58
+ def_plugin :on_block_comment_found
59
+ def_plugin :on_line_comment_found
60
+ def_plugin :on_nested_block_comment_found
61
+ def_plugin :on_unterminated_block_comment
62
+ def_plugin :on_eof_newline_not_found
63
+ def_plugin :on_unlexable_char_found
64
+ def_plugin :on_cr_at_eol_found
65
+ def_plugin :on_eof_mark_at_eof_found
66
+
67
+ def next_token
68
+ if @top_token
69
+ token = @top_token
70
+ @top_token = nil
71
+ return token
72
+ end
73
+ @state.next_token
74
+ end
75
+
76
+ def top_token
77
+ @top_token ? @top_token : (@top_token = self.next_token)
78
+ end
79
+
80
+ def skip_group
81
+ group_depth = 1
82
+ until @content.empty?
83
+ case
84
+ when @content.check(/[ \t]*#[ \t]*(?:if|ifdef|ifndef|asm)\b/)
85
+ group_depth += 1
86
+ @content.scan(/.*\n/)
87
+ when @content.check(/[ \t]*#[ \t]*(?:else|elif)\b/)
88
+ return true if group_depth == 1
89
+ @content.scan(/.*\n/)
90
+ when @content.check(/[ \t]*#[ \t]*(?:endif|endasm)\b/)
91
+ group_depth -= 1
92
+ return true if group_depth == 0
93
+ @content.scan(/.*\n/)
94
+ end
95
+ break unless scan_until_next_directive(@content)
96
+ end
97
+ false
98
+ end
99
+
100
+ def transit(next_state)
101
+ @state = next_state
102
+ end
103
+
104
+ def notify_block_comment_found(comment, location)
105
+ on_block_comment_found.invoke(comment, location)
106
+ end
107
+
108
+ def notify_line_comment_found(comment, location)
109
+ on_line_comment_found.invoke(comment, location)
110
+ end
111
+
112
+ def notify_nested_block_comment_found(location)
113
+ on_nested_block_comment_found.invoke(location)
114
+ end
115
+
116
+ def notify_unterminated_block_comment(location)
117
+ on_unterminated_block_comment.invoke(location)
118
+ end
119
+
120
+ def notify_eof_newline_not_found(location)
121
+ on_eof_newline_not_found.invoke(location)
122
+ end
123
+
124
+ def notify_unlexable_char_found(char, location)
125
+ on_unlexable_char_found.invoke(char, location)
126
+ end
127
+
128
+ GROUP_DIRECTIVE_RE =
129
+ /.*?(?=^[ \t]*#[ \t]*(?:if|ifdef|ifndef|asm|else|elif|endif|endasm)\b)/m
130
+ private_constant :GROUP_DIRECTIVE_RE
131
+
132
+ private
133
+ def scan_until_next_directive(content)
134
+ content.scan(GROUP_DIRECTIVE_RE)
135
+ end
136
+ end
137
+
138
+ class LexerState
139
+ def initialize(lexer)
140
+ @lexer = lexer
141
+ end
142
+
143
+ def next_token
144
+ subclass_responsibility
145
+ end
146
+
147
+ private
148
+ def discard_heading_comments
149
+ discarded = false
150
+ until @lexer.content.empty?
151
+ case
152
+ when @lexer.content.check(/\/\*/)
153
+ location = @lexer.content.location
154
+ comment = scan_block_comment(@lexer.content)
155
+ unless comment.empty?
156
+ @lexer.notify_block_comment_found(comment, location)
157
+ discarded = true
158
+ end
159
+ when @lexer.content.check(/\/\//)
160
+ location = @lexer.content.location
161
+ comment = scan_line_comment(@lexer.content)
162
+ unless comment.empty?
163
+ @lexer.notify_line_comment_found(comment, location)
164
+ discarded = true
165
+ end
166
+ else
167
+ break
168
+ end
169
+ end
170
+ discarded
171
+ end
172
+
173
+ def scan_block_comment(content)
174
+ result = ""
175
+ block_depth = 0
176
+ until content.empty?
177
+ location = content.location
178
+ case
179
+ when content.scan(/\/\*/)
180
+ block_depth += 1
181
+ result += "/*"
182
+ @lexer.notify_nested_block_comment_found(location) if block_depth > 1
183
+ when content.scan(/\*\//)
184
+ result += "*/"
185
+ break
186
+ else
187
+ return nil if block_depth == 0
188
+ if comment = content.scan(/.*?(?=\/\*|\*\/)/m)
189
+ result += comment
190
+ else
191
+ @lexer.notify_unterminated_block_comment(location)
192
+ end
193
+ end
194
+ end
195
+ result
196
+ end
197
+
198
+ def scan_line_comment(content)
199
+ content.scan(/\/\/.*?(?=\n)/)
200
+ end
201
+
202
+ def scan_escaped_newline(content)
203
+ content.scan(/\\[ \t]*\n/)
204
+ end
205
+
206
+ def tokenize_pp_token(content)
207
+ location = content.location
208
+ case
209
+ when value = Language::C.scan_keyword(content),
210
+ value = Language::Cpp.scan_keyword(content)
211
+ Token.new(:PP_TOKEN, value, location, Language::C::KEYWORDS[value])
212
+ when value = Language::C.scan_char_constant(content),
213
+ value = Language::C.scan_floating_constant(content),
214
+ value = Language::C.scan_integer_constant(content)
215
+ Token.new(:PP_TOKEN, value, location, :CONSTANT)
216
+ when value = Language::C.scan_string_literal(content)
217
+ Token.new(:PP_TOKEN, value, location, :STRING_LITERAL)
218
+ when value = Language::C.scan_null_constant(content)
219
+ Token.new(:PP_TOKEN, value, location, :NULL)
220
+ when value = Language::C.scan_identifier(content)
221
+ Token.new(:PP_TOKEN, value, location, :IDENTIFIER)
222
+ when value = Language::Cpp.scan_punctuator(content)
223
+ Token.new(:PP_TOKEN, value, location, value)
224
+ else
225
+ nil
226
+ end
227
+ end
228
+
229
+ def tokenize_new_line(content)
230
+ location = content.location
231
+ if value = content.scan(/\n/)
232
+ return Token.new(:NEW_LINE, value, location)
233
+ end
234
+ nil
235
+ end
236
+
237
+ def tokenize_header_name(content)
238
+ location = content.location
239
+ if value = Language::Cpp.scan_system_header_name(content)
240
+ return Token.new(:SYS_HEADER_NAME, value, location)
241
+ elsif value = Language::Cpp.scan_user_header_name(content)
242
+ return Token.new(:USR_HEADER_NAME, value, location)
243
+ end
244
+ nil
245
+ end
246
+
247
+ def tokenize_identifier(content)
248
+ location = content.location
249
+ if value = Language::C.scan_identifier(content)
250
+ return Token.new(:IDENTIFIER, value, location)
251
+ end
252
+ nil
253
+ end
254
+
255
+ def tokenize_punctuator(content)
256
+ location = content.location
257
+ if punctuator = Language::Cpp.scan_punctuator(content)
258
+ return Token.new(punctuator, punctuator, location)
259
+ end
260
+ nil
261
+ end
262
+ end
263
+
264
+ class Initial < LexerState
265
+ def next_token
266
+ # NOTE: An escaped newline may appear at the line above a preprocessing
267
+ # directive line.
268
+ while scan_escaped_newline(@lexer.content); end
269
+
270
+ case
271
+ when @lexer.content.check(/[ \t]*#/)
272
+ case
273
+ when token = tokenize_if_directive(@lexer.content)
274
+ @lexer.transit(InIfDirective.new(@lexer))
275
+ when token = tokenize_ifdef_directive(@lexer.content)
276
+ @lexer.transit(InIfdefDirective.new(@lexer))
277
+ when token = tokenize_ifndef_directive(@lexer.content)
278
+ @lexer.transit(InIfndefDirective.new(@lexer))
279
+ when token = tokenize_elif_directive(@lexer.content)
280
+ @lexer.transit(InElifDirective.new(@lexer))
281
+ when token = tokenize_else_directive(@lexer.content)
282
+ @lexer.transit(InElseDirective.new(@lexer))
283
+ when token = tokenize_endif_directive(@lexer.content)
284
+ @lexer.transit(InEndifDirective.new(@lexer))
285
+ when token = tokenize_include_directive(@lexer.content)
286
+ @lexer.transit(InIncludeDirective.new(@lexer))
287
+ when token = tokenize_include_next_directive(@lexer.content)
288
+ @lexer.transit(InIncludeNextDirective.new(@lexer))
289
+ when token = tokenize_define_directive(@lexer.content)
290
+ @lexer.transit(InDefineDirective.new(@lexer))
291
+ when token = tokenize_undef_directive(@lexer.content)
292
+ @lexer.transit(InUndefDirective.new(@lexer))
293
+ when token = tokenize_line_directive(@lexer.content)
294
+ @lexer.transit(InLineDirective.new(@lexer))
295
+ when token = tokenize_error_directive(@lexer.content)
296
+ @lexer.transit(InErrorDirective.new(@lexer))
297
+ when token = tokenize_pragma_directive(@lexer.content)
298
+ @lexer.transit(InPragmaDirective.new(@lexer))
299
+ when token = tokenize_asm_directive(@lexer.content)
300
+ @lexer.transit(InAsmDirective.new(@lexer))
301
+ when token = tokenize_endasm_directive(@lexer.content)
302
+ @lexer.transit(InEndasmDirective.new(@lexer))
303
+ else
304
+ token = tokenize_null_directive(@lexer.content)
305
+ end
306
+ else
307
+ token = tokenize_text_line(@lexer.content)
308
+ end
309
+
310
+ token
311
+ end
312
+
313
+ private
314
+ def tokenize_if_directive(content)
315
+ location = content.location
316
+ if value = content.scan(/[ \t]*#[ \t]*if\b/)
317
+ return Token.new(:IF, value, location)
318
+ end
319
+ nil
320
+ end
321
+
322
+ def tokenize_ifdef_directive(content)
323
+ location = content.location
324
+ if value = content.scan(/[ \t]*#[ \t]*ifdef\b/)
325
+ return Token.new(:IFDEF, value, location)
326
+ end
327
+ nil
328
+ end
329
+
330
+ def tokenize_ifndef_directive(content)
331
+ location = content.location
332
+ if value = content.scan(/[ \t]*#[ \t]*ifndef\b/)
333
+ return Token.new(:IFNDEF, value, location)
334
+ end
335
+ nil
336
+ end
337
+
338
+ def tokenize_elif_directive(content)
339
+ location = content.location
340
+ if value = content.scan(/[ \t]*#[ \t]*elif\b/)
341
+ return Token.new(:ELIF, value, location)
342
+ end
343
+ nil
344
+ end
345
+
346
+ def tokenize_else_directive(content)
347
+ location = content.location
348
+ if value = content.scan(/[ \t]*#[ \t]*else\b/)
349
+ return Token.new(:ELSE, value, location)
350
+ end
351
+ nil
352
+ end
353
+
354
+ def tokenize_endif_directive(content)
355
+ location = content.location
356
+ if value = content.scan(/[ \t]*#[ \t]*endif\b/)
357
+ return Token.new(:ENDIF, value, location)
358
+ end
359
+ nil
360
+ end
361
+
362
+ def tokenize_include_directive(content)
363
+ location = content.location
364
+ if value = content.scan(/[ \t]*#[ \t]*include\b/)
365
+ return Token.new(:INCLUDE, value, location)
366
+ end
367
+ nil
368
+ end
369
+
370
+ def tokenize_include_next_directive(content)
371
+ # NOTE: #include_next directive is a GCC extension.
372
+ location = content.location
373
+ if value = content.scan(/[ \t]*#[ \t]*include_next\b/)
374
+ return Token.new(:INCLUDE_NEXT, value, location)
375
+ end
376
+ nil
377
+ end
378
+
379
+ def tokenize_define_directive(content)
380
+ location = content.location
381
+ if value = content.scan(/[ \t]*#[ \t]*define\b/)
382
+ return Token.new(:DEFINE, value, location)
383
+ end
384
+ nil
385
+ end
386
+
387
+ def tokenize_undef_directive(content)
388
+ location = content.location
389
+ if value = content.scan(/[ \t]*#[ \t]*undef\b/)
390
+ return Token.new(:UNDEF, value, location)
391
+ end
392
+ nil
393
+ end
394
+
395
+ def tokenize_line_directive(content)
396
+ location = content.location
397
+ if value = content.scan(/[ \t]*#[ \t]*line\b/)
398
+ return Token.new(:LINE, value, location)
399
+ end
400
+ nil
401
+ end
402
+
403
+ def tokenize_error_directive(content)
404
+ location = content.location
405
+ if value = content.scan(/[ \t]*#[ \t]*error\b/)
406
+ return Token.new(:ERROR, value, location)
407
+ end
408
+ nil
409
+ end
410
+
411
+ def tokenize_pragma_directive(content)
412
+ location = content.location
413
+ if value = content.scan(/[ \t]*#[ \t]*pragma\b/)
414
+ return Token.new(:PRAGMA, value, location)
415
+ end
416
+ nil
417
+ end
418
+
419
+ def tokenize_asm_directive(content)
420
+ location = content.location
421
+ if value = content.scan(/[ \t]*#[ \t]*asm\b/)
422
+ return Token.new(:ASM, value, location)
423
+ end
424
+ nil
425
+ end
426
+
427
+ def tokenize_endasm_directive(content)
428
+ location = content.location
429
+ if value = content.scan(/[ \t]*#[ \t]*endasm\b/)
430
+ return Token.new(:ENDASM, value, location)
431
+ end
432
+ nil
433
+ end
434
+
435
+ def tokenize_null_directive(content)
436
+ location = content.location
437
+ value = content.scan(/[ \t]*#/)
438
+ until content.empty?
439
+ if token = content.scan(/.*?(?=\\[ \t]*\n|\n)/)
440
+ value += token
441
+ end
442
+
443
+ next if scan_escaped_newline(content)
444
+
445
+ if new_line = content.scan(/\n/)
446
+ value += new_line
447
+ break
448
+ end
449
+ end
450
+ Token.new(:NULL_DIRECTIVE, value, location)
451
+ end
452
+
453
+ def tokenize_text_line(content)
454
+ location = content.location
455
+ value = ""
456
+
457
+ until content.empty?
458
+ if token = content.scan(/.*?(?=\/\*|\/\/|\\[ \t]*\n|L?"|L?'|\n)/i)
459
+ value += token
460
+ end
461
+
462
+ if token = content.scan(/\n/)
463
+ value += token
464
+ break
465
+ end
466
+
467
+ next if scan_escaped_newline(content)
468
+
469
+ case
470
+ when content.check(/\/\*/)
471
+ discard_heading_comments
472
+ when content.check(/\/\//)
473
+ discard_heading_comments
474
+ when content.check(/L?"/i)
475
+ string_literal = Language::C.scan_string_literal(content)
476
+ value += string_literal
477
+ when content.check(/L?'/i)
478
+ char_constant = Language::C.scan_char_constant(content)
479
+ value += char_constant
480
+ end
481
+ end
482
+
483
+ value.empty? ? nil : Token.new(:TEXT_LINE, value, location)
484
+ end
485
+ end
486
+
487
+ class InIfDirective < LexerState
488
+ def next_token
489
+ until @lexer.content.empty?
490
+ next if discard_heading_comments
491
+ next if scan_escaped_newline(@lexer.content)
492
+
493
+ token = tokenize_pp_token(@lexer.content) ||
494
+ tokenize_new_line(@lexer.content)
495
+
496
+ if token
497
+ break
498
+ else
499
+ @lexer.content.eat!
500
+ end
501
+ end
502
+
503
+ unless token
504
+ token = Token.new(:NEW_LINE, "\n", @lexer.content.location)
505
+ @lexer.notify_eof_newline_not_found(token.location)
506
+ end
507
+
508
+ if token.type == :NEW_LINE
509
+ @lexer.transit(Initial.new(@lexer))
510
+ end
511
+
512
+ token
513
+ end
514
+ end
515
+
516
+ class InIfdefDirective < LexerState
517
+ def next_token
518
+ until @lexer.content.empty?
519
+ next if discard_heading_comments
520
+ next if scan_escaped_newline(@lexer.content)
521
+
522
+ token = tokenize_identifier(@lexer.content) ||
523
+ tokenize_new_line(@lexer.content)
524
+
525
+ if token
526
+ break
527
+ else
528
+ @lexer.content.eat!
529
+ end
530
+ end
531
+
532
+ unless token
533
+ token = Token.new(:NEW_LINE, "\n", @lexer.content.location)
534
+ @lexer.notify_eof_newline_not_found(token.location)
535
+ end
536
+
537
+ if token.type == :NEW_LINE
538
+ @lexer.transit(Initial.new(@lexer))
539
+ end
540
+
541
+ token
542
+ end
543
+ end
544
+
545
+ class InIfndefDirective < InIfdefDirective; end
546
+
547
+ class InElifDirective < InIfDirective; end
548
+
549
+ class InElseDirective < LexerState
550
+ def next_token
551
+ until @lexer.content.empty?
552
+ next if discard_heading_comments
553
+ next if scan_escaped_newline(@lexer.content)
554
+
555
+ if token = tokenize_new_line(@lexer.content)
556
+ break
557
+ else
558
+ @lexer.content.eat!
559
+ end
560
+ end
561
+
562
+ unless token
563
+ token = Token.new(:NEW_LINE, "\n", @lexer.content.location)
564
+ @lexer.notify_eof_newline_not_found(token.location)
565
+ end
566
+
567
+ if token.type == :NEW_LINE
568
+ @lexer.transit(Initial.new(@lexer))
569
+ end
570
+
571
+ token
572
+ end
573
+ end
574
+
575
+ class InEndifDirective < InElseDirective; end
576
+
577
+ class InIncludeDirective < LexerState
578
+ def next_token
579
+ until @lexer.content.empty?
580
+ next if discard_heading_comments
581
+ next if scan_escaped_newline(@lexer.content)
582
+
583
+ token = tokenize_header_name(@lexer.content) ||
584
+ tokenize_pp_token(@lexer.content) ||
585
+ tokenize_new_line(@lexer.content)
586
+
587
+ if token
588
+ break
589
+ else
590
+ @lexer.content.eat!
591
+ end
592
+ end
593
+
594
+ unless token
595
+ token = Token.new(:NEW_LINE, "\n", @lexer.content.location)
596
+ @lexer.notify_eof_newline_not_found(token.location)
597
+ end
598
+
599
+ if token.type == :NEW_LINE
600
+ @lexer.transit(Initial.new(@lexer))
601
+ end
602
+
603
+ token
604
+ end
605
+ end
606
+
607
+ class InIncludeNextDirective < InIncludeDirective; end
608
+
609
+ class InDefineDirective < LexerState
610
+ def initialize(lexer)
611
+ super
612
+ @tokens = []
613
+ end
614
+
615
+ def next_token
616
+ if @tokens.empty?
617
+ tokenize_macro_name(@lexer.content)
618
+ tokenize_pp_tokens(@lexer.content)
619
+ end
620
+
621
+ token = @tokens.shift
622
+ @lexer.transit(Initial.new(@lexer)) if @tokens.empty?
623
+ token
624
+ end
625
+
626
+ private
627
+ def tokenize_macro_name(content)
628
+ until content.empty?
629
+ next if discard_heading_comments
630
+ if token = tokenize_identifier(content)
631
+ @tokens.push(token)
632
+ break
633
+ else
634
+ content.eat!
635
+ end
636
+ end
637
+
638
+ return unless content.check(/\(/)
639
+
640
+ paren_depth = 0
641
+ until content.empty?
642
+ next if discard_heading_comments
643
+ next if scan_escaped_newline(content)
644
+
645
+ if token = tokenize_identifier(content)
646
+ @tokens.push(token)
647
+ next
648
+ end
649
+
650
+ if token = tokenize_punctuator(content)
651
+ @tokens.push(token)
652
+ case token.type
653
+ when "("
654
+ paren_depth += 1
655
+ when ")"
656
+ paren_depth -= 1
657
+ break if paren_depth == 0
658
+ end
659
+ next
660
+ end
661
+
662
+ if token = tokenize_new_line(content)
663
+ @tokens.push(token)
664
+ break
665
+ end
666
+
667
+ content.eat!
668
+ end
669
+ end
670
+
671
+ def tokenize_pp_tokens(content)
672
+ until content.empty?
673
+ next if discard_heading_comments
674
+ next if scan_escaped_newline(content)
675
+
676
+ token = tokenize_pp_token(content) || tokenize_new_line(content)
677
+
678
+ if token
679
+ @tokens.push(token)
680
+ if token.type == :NEW_LINE
681
+ break
682
+ end
683
+ else
684
+ location = content.location
685
+ if eaten = content.eat! and eaten !~ /\A\s\z/
686
+ @lexer.notify_unlexable_char_found(eaten, location)
687
+ end
688
+ end
689
+ end
690
+
691
+ unless @tokens.last && @tokens.last.type == :NEW_LINE
692
+ token = Token.new(:NEW_LINE, "\n", content.location)
693
+ @lexer.notify_eof_newline_not_found(token.location)
694
+ @tokens.push(token)
695
+ end
696
+ end
697
+ end
698
+
699
+ class InUndefDirective < InDefineDirective; end
700
+
701
+ class InLineDirective < InIfDirective; end
702
+
703
+ class InErrorDirective < InLineDirective; end
704
+
705
+ class InPragmaDirective < InLineDirective; end
706
+
707
+ class InAsmDirective < InElseDirective; end
708
+
709
+ class InEndasmDirective < InElseDirective; end
710
+
711
+ class StringToPPTokensLexer < StringLexer
712
+ private
713
+ def create_context(str)
714
+ context = LexerContext.new(create_content(str))
715
+
716
+ class << context
717
+ attr_accessor :last_symbol
718
+ end
719
+
720
+ context
721
+ end
722
+
723
+ def create_content(str)
724
+ StringContent.new(str)
725
+ end
726
+
727
+ def tokenize(context)
728
+ token_array = TokenArray.new
729
+ until context.content.empty?
730
+ next if tokenize_pp_token(context, token_array)
731
+
732
+ location = context.location
733
+ if new_line = context.content.scan(/\n/)
734
+ token_array.push(Token.new(:NEW_LINE, new_line, location))
735
+ break
736
+ else
737
+ context.content.eat!
738
+ end
739
+ end
740
+ token_array
741
+ end
742
+
743
+ def tokenize_pp_token(context, token_array)
744
+ pp_token = tokenize_keyword(context) ||
745
+ tokenize_constant(context) ||
746
+ tokenize_string_literal(context) ||
747
+ tokenize_null_constant(context) ||
748
+ tokenize_identifier(context) ||
749
+ tokenize_punctuator(context)
750
+
751
+ if pp_token
752
+ token_array.push(pp_token)
753
+ return true
754
+ end
755
+
756
+ false
757
+ end
758
+
759
+ def tokenize_keyword(context)
760
+ location = context.location
761
+
762
+ keyword = Language::C.scan_keyword(context.content) ||
763
+ Language::Cpp.scan_keyword(context.content)
764
+
765
+ if keyword
766
+ context.last_symbol = :KEYWORD
767
+ Token.new(:PP_TOKEN, keyword, location, Language::C::KEYWORDS[keyword])
768
+ else
769
+ nil
770
+ end
771
+ end
772
+
773
+ def tokenize_constant(context)
774
+ location = context.location
775
+
776
+ # NOTE: For extended bit-access operators.
777
+ return nil if context.last_symbol == :IDENTIFIER
778
+
779
+ constant = Language::C.scan_char_constant(context.content) ||
780
+ Language::C.scan_floating_constant(context.content) ||
781
+ Language::C.scan_integer_constant(context.content)
782
+
783
+ if constant
784
+ context.last_symbol = :CONSTANT
785
+ return Token.new(:PP_TOKEN, constant, location, :CONSTANT)
786
+ end
787
+
788
+ nil
789
+ end
790
+
791
+ def tokenize_string_literal(context)
792
+ location = context.location
793
+
794
+ string_literal = Language::C.scan_string_literal(context.content)
795
+
796
+ if string_literal
797
+ context.last_symbol = :STRING_LITERAL
798
+ return Token.new(:PP_TOKEN, string_literal, location, :STRING_LITERAL)
799
+ end
800
+
801
+ nil
802
+ end
803
+
804
+ def tokenize_null_constant(context)
805
+ location = context.location
806
+
807
+ null_constant = Language::C.scan_null_constant(context.content)
808
+
809
+ if null_constant
810
+ context.last_symbol = :NULL
811
+ return Token.new(:PP_TOKEN, null_constant, location, :NULL)
812
+ end
813
+
814
+ nil
815
+ end
816
+
817
+ def tokenize_identifier(context)
818
+ location = context.location
819
+
820
+ identifier = Language::C.scan_identifier(context.content)
821
+
822
+ if identifier
823
+ context.last_symbol = :IDENTIFIER
824
+ return Token.new(:PP_TOKEN, identifier, location, :IDENTIFIER)
825
+ end
826
+
827
+ nil
828
+ end
829
+
830
+ def tokenize_punctuator(context)
831
+ location = context.location
832
+
833
+ punctuator = Language::Cpp.scan_punctuator(context.content)
834
+
835
+ if punctuator
836
+ context.last_symbol = :PUNCTUATOR
837
+ return Token.new(:PP_TOKEN, punctuator, location, punctuator)
838
+ end
839
+
840
+ nil
841
+ end
842
+ end
843
+
844
+ class TextLineToPPTokensLexer < StringToPPTokensLexer
845
+ def initialize(text_line)
846
+ super(text_line.token.value)
847
+ @text_line = text_line
848
+ end
849
+
850
+ private
851
+ def create_content(str)
852
+ StringContent.new(str,
853
+ @text_line.location.fpath,
854
+ @text_line.location.line_no,
855
+ @text_line.location.column_no)
856
+ end
857
+ end
858
+
859
+ end
860
+ end