adlint 2.6.14 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (401) hide show
  1. data/AUTHORS +1 -3
  2. data/ChangeLog +511 -0
  3. data/INSTALL +1 -1
  4. data/MANIFEST +57 -37
  5. data/NEWS +36 -7
  6. data/README +2 -2
  7. data/Rakefile +6 -6
  8. data/TODO +1 -1
  9. data/bin/adlint +25 -16
  10. data/bin/adlint_chk +22 -12
  11. data/bin/adlint_cma +17 -12
  12. data/bin/adlint_sma +22 -12
  13. data/bin/adlintize +98 -17
  14. data/etc/conf.d/fallback/cinit.erb +1 -1
  15. data/etc/conf.d/fallback/traits.erb +37 -37
  16. data/etc/conf.d/i686-cygwin/cinit-gcc_4.3.4.erb +1 -1
  17. data/etc/conf.d/i686-cygwin/traits-gcc_4.3.4.erb +41 -41
  18. data/etc/conf.d/i686-devkit/cinit-gcc_4.5.2.erb +1 -1
  19. data/etc/conf.d/i686-devkit/traits-gcc_4.5.2.erb +40 -40
  20. data/etc/conf.d/i686-linux/cinit-gcc_4.5.1.erb +1 -1
  21. data/etc/conf.d/i686-linux/traits-gcc_4.5.1.erb +40 -40
  22. data/etc/conf.d/i686-mingw/cinit-gcc_4.6.1.erb +1 -1
  23. data/etc/conf.d/i686-mingw/traits-gcc_4.6.1.erb +40 -40
  24. data/etc/conf.d/noarch/GNUmakefile.erb +1 -1
  25. data/etc/conf.d/noarch/adlint_all_bat.erb +1 -1
  26. data/etc/conf.d/noarch/adlint_all_sh.erb +1 -1
  27. data/etc/conf.d/noarch/pinit.erb +1 -1
  28. data/etc/conf.d/x86_64-ubuntu_12.04/cinit-gcc_4.6.3.erb +1 -1
  29. data/etc/conf.d/x86_64-ubuntu_12.04/traits-gcc_4.6.3.erb +42 -42
  30. data/etc/mesg.d/c_builtin/en_US/messages.yml +33 -33
  31. data/etc/mesg.d/c_builtin/ja_JP/messages.yml +5 -5
  32. data/etc/mesg.d/core/en_US/messages.yml +2 -2
  33. data/etc/mesg.d/core/ja_JP/messages.yml +2 -2
  34. data/features/code_check/W0018.feature +197 -0
  35. data/features/code_check/W0019.feature +79 -0
  36. data/features/code_check/W0021.feature +81 -0
  37. data/features/code_check/W0023.feature +203 -0
  38. data/features/code_check/W0024.feature +226 -0
  39. data/features/code_check/W0025.feature +5 -0
  40. data/features/code_check/W0088.feature +2 -2
  41. data/features/code_check/W0109.feature +2 -2
  42. data/features/code_check/W0477.feature +0 -3
  43. data/features/code_check/W0478.feature +0 -1
  44. data/features/code_check/W0582.feature +3 -3
  45. data/features/code_check/W0583.feature +4 -7
  46. data/features/code_check/W0646.feature +0 -1
  47. data/features/code_check/W0695.feature +0 -1
  48. data/features/code_check/W0705.feature +8 -0
  49. data/features/code_check/W0723.feature +0 -1
  50. data/features/code_check/W0745.feature +1 -0
  51. data/features/code_check/W0781.feature +1 -0
  52. data/features/code_check/W1057.feature +141 -0
  53. data/features/code_check/W1058.feature +93 -0
  54. data/features/code_check/W1059.feature +86 -0
  55. data/features/code_check/W1060.feature +77 -0
  56. data/features/code_check/W1061.feature +143 -0
  57. data/features/code_check/W1062.feature +162 -0
  58. data/features/code_check/W1063.feature +123 -0
  59. data/features/code_check/W1064.feature +83 -0
  60. data/features/code_check/W1065.feature +82 -0
  61. data/features/code_check/W9003.feature +2 -0
  62. data/features/step_definitions/code_check_steps.rb +1 -0
  63. data/features/support/env.rb +16 -13
  64. data/lib/adlint.rb +7 -4
  65. data/lib/adlint/analyzer.rb +131 -157
  66. data/lib/adlint/annot.rb +149 -0
  67. data/lib/adlint/cc1.rb +57 -0
  68. data/lib/adlint/{c → cc1}/branch.rb +74 -62
  69. data/lib/adlint/{c → cc1}/builtin.rb +21 -21
  70. data/lib/adlint/{c → cc1}/const.rb +119 -117
  71. data/lib/adlint/{c → cc1}/conv.rb +76 -78
  72. data/lib/adlint/{c → cc1}/ctrlexpr.rb +69 -86
  73. data/lib/adlint/cc1/domain.rb +8103 -0
  74. data/lib/adlint/{c → cc1}/enum.rb +3 -3
  75. data/lib/adlint/{c → cc1}/environ.rb +21 -21
  76. data/lib/adlint/{c → cc1}/expr.rb +232 -218
  77. data/lib/adlint/{c → cc1}/format.rb +305 -342
  78. data/lib/adlint/{c → cc1}/interp.rb +269 -220
  79. data/lib/adlint/cc1/lexer.rb +246 -0
  80. data/lib/adlint/{c → cc1}/mediator.rb +78 -84
  81. data/lib/adlint/{c → cc1}/object.rb +261 -264
  82. data/lib/adlint/{c → cc1}/operator.rb +7 -7
  83. data/lib/adlint/{c → cc1}/option.rb +4 -3
  84. data/lib/adlint/{c → cc1}/parser.rb +274 -506
  85. data/lib/adlint/{c → cc1}/parser.y +69 -301
  86. data/lib/adlint/cc1/phase.rb +138 -0
  87. data/lib/adlint/{c → cc1}/resolver.rb +66 -78
  88. data/lib/adlint/{c → cc1}/scanner.rb +57 -49
  89. data/lib/adlint/{c → cc1}/scope.rb +3 -3
  90. data/lib/adlint/{c → cc1}/seqp.rb +13 -5
  91. data/lib/adlint/{c → cc1}/syntax.rb +819 -1122
  92. data/lib/adlint/{c → cc1}/type.rb +1498 -1479
  93. data/lib/adlint/{c → cc1}/util.rb +20 -12
  94. data/lib/adlint/{c → cc1}/value.rb +699 -642
  95. data/lib/adlint/code.rb +163 -164
  96. data/lib/adlint/cpp.rb +2 -2
  97. data/lib/adlint/cpp/asm.rb +13 -14
  98. data/lib/adlint/cpp/constexpr.rb +42 -38
  99. data/lib/adlint/cpp/constexpr.y +44 -40
  100. data/lib/adlint/cpp/eval.rb +435 -435
  101. data/lib/adlint/cpp/lexer.rb +343 -340
  102. data/lib/adlint/cpp/macro.rb +188 -190
  103. data/lib/adlint/cpp/phase.rb +66 -45
  104. data/lib/adlint/cpp/scanner.rb +14 -17
  105. data/lib/adlint/cpp/source.rb +49 -55
  106. data/lib/adlint/cpp/subst.rb +65 -65
  107. data/lib/adlint/cpp/syntax.rb +155 -275
  108. data/lib/adlint/cpp/util.rb +22 -19
  109. data/lib/adlint/driver.rb +86 -93
  110. data/lib/adlint/error.rb +33 -52
  111. data/lib/adlint/exam.rb +158 -24
  112. data/lib/adlint/exam/c_builtin.rb +7 -7
  113. data/lib/adlint/exam/c_builtin/cc1_check.rb +20522 -0
  114. data/lib/adlint/exam/c_builtin/cc1_check_shima.rb +957 -0
  115. data/lib/adlint/exam/c_builtin/cc1_code.rb +459 -0
  116. data/lib/adlint/exam/c_builtin/cc1_metric.rb +794 -0
  117. data/lib/adlint/exam/c_builtin/cpp_check.rb +486 -441
  118. data/lib/adlint/exam/c_builtin/cpp_check_shima.rb +36 -39
  119. data/lib/adlint/exam/c_builtin/cpp_code.rb +63 -65
  120. data/lib/adlint/exam/c_builtin/ld_check.rb +136 -129
  121. data/lib/adlint/exam/c_builtin/ld_metric.rb +11 -11
  122. data/lib/adlint/lang.rb +25 -25
  123. data/lib/adlint/ld.rb +2 -2
  124. data/lib/adlint/ld/object.rb +220 -188
  125. data/lib/adlint/ld/phase.rb +94 -63
  126. data/lib/adlint/ld/typedef.rb +22 -11
  127. data/lib/adlint/ld/util.rb +43 -35
  128. data/lib/adlint/lexer.rb +59 -56
  129. data/lib/adlint/location.rb +140 -0
  130. data/lib/adlint/memo.rb +157 -0
  131. data/lib/adlint/message.rb +207 -156
  132. data/lib/adlint/metric.rb +139 -217
  133. data/lib/adlint/monitor.rb +45 -43
  134. data/lib/adlint/phase.rb +56 -29
  135. data/lib/adlint/prelude.rb +66 -54
  136. data/lib/adlint/report.rb +253 -332
  137. data/lib/adlint/source.rb +26 -27
  138. data/lib/adlint/supp.rb +131 -0
  139. data/lib/adlint/symbol.rb +14 -16
  140. data/lib/adlint/token.rb +19 -91
  141. data/lib/adlint/traits.rb +242 -226
  142. data/lib/adlint/util.rb +116 -205
  143. data/lib/adlint/version.rb +8 -8
  144. data/share/HEADER +2 -2
  145. data/share/doc/developers_guide_ja.html +148 -19
  146. data/share/doc/developers_guide_ja.texi +141 -11
  147. data/share/doc/samples/GNUmakefile +1 -1
  148. data/share/doc/samples/adlint_traits.yml +45 -36
  149. data/share/doc/users_guide_en.html +1321 -1252
  150. data/share/doc/users_guide_en.texi +475 -408
  151. data/share/doc/users_guide_ja.html +1932 -1878
  152. data/share/doc/users_guide_ja.texi +324 -273
  153. data/share/sample/bison-2.5/adlint/GNUmakefile +5 -1
  154. data/share/sample/bison-2.5/adlint/adlint_traits.yml +38 -38
  155. data/share/sample/bison-2.5/adlint/lib/GNUmakefile +1 -1
  156. data/share/sample/bison-2.5/adlint/lib/adlint_cinit.h +1 -1
  157. data/share/sample/bison-2.5/adlint/lib/adlint_pinit.h +1 -1
  158. data/share/sample/bison-2.5/adlint/lib/adlint_traits.yml +50 -42
  159. data/share/sample/bison-2.5/adlint/src/GNUmakefile +1 -1
  160. data/share/sample/bison-2.5/adlint/src/adlint_cinit.h +1 -1
  161. data/share/sample/bison-2.5/adlint/src/adlint_pinit.h +1 -1
  162. data/share/sample/bison-2.5/adlint/src/adlint_traits.yml +50 -42
  163. data/share/sample/ctags-5.8/adlint/GNUmakefile +1 -1
  164. data/share/sample/ctags-5.8/adlint/adlint_cinit.h +1 -1
  165. data/share/sample/ctags-5.8/adlint/adlint_pinit.h +1 -1
  166. data/share/sample/ctags-5.8/adlint/adlint_traits.yml +50 -42
  167. data/share/sample/flex-2.5.35/adlint/GNUmakefile +1 -1
  168. data/share/sample/flex-2.5.35/adlint/adlint_cinit.h +1 -1
  169. data/share/sample/flex-2.5.35/adlint/adlint_pinit.h +1 -1
  170. data/share/sample/flex-2.5.35/adlint/adlint_traits.yml +50 -42
  171. data/share/sample/ruby-1.9.3-p0/adlint/GNUmakefile +1 -1
  172. data/share/sample/ruby-1.9.3-p0/adlint/adlint_traits.yml +46 -38
  173. data/share/sample/ruby-1.9.3-p0/adlint/core/GNUmakefile +1 -1
  174. data/share/sample/ruby-1.9.3-p0/adlint/core/adlint_cinit.h +1 -1
  175. data/share/sample/ruby-1.9.3-p0/adlint/core/adlint_pinit.h +1 -1
  176. data/share/sample/ruby-1.9.3-p0/adlint/core/adlint_traits.yml +50 -42
  177. data/share/sample/ruby-1.9.3-p0/adlint/enc-trans/GNUmakefile +1 -1
  178. data/share/sample/ruby-1.9.3-p0/adlint/enc-trans/adlint_cinit.h +1 -1
  179. data/share/sample/ruby-1.9.3-p0/adlint/enc-trans/adlint_pinit.h +1 -1
  180. data/share/sample/ruby-1.9.3-p0/adlint/enc-trans/adlint_traits.yml +50 -42
  181. data/share/sample/ruby-1.9.3-p0/adlint/enc/GNUmakefile +1 -1
  182. data/share/sample/ruby-1.9.3-p0/adlint/enc/adlint_cinit.h +1 -1
  183. data/share/sample/ruby-1.9.3-p0/adlint/enc/adlint_pinit.h +1 -1
  184. data/share/sample/ruby-1.9.3-p0/adlint/enc/adlint_traits.yml +50 -42
  185. data/share/sample/ruby-1.9.3-p0/adlint/ext-bigdecimal/GNUmakefile +1 -1
  186. data/share/sample/ruby-1.9.3-p0/adlint/ext-bigdecimal/adlint_cinit.h +1 -1
  187. data/share/sample/ruby-1.9.3-p0/adlint/ext-bigdecimal/adlint_pinit.h +1 -1
  188. data/share/sample/ruby-1.9.3-p0/adlint/ext-bigdecimal/adlint_traits.yml +50 -42
  189. data/share/sample/ruby-1.9.3-p0/adlint/ext-continuation/GNUmakefile +1 -1
  190. data/share/sample/ruby-1.9.3-p0/adlint/ext-continuation/adlint_cinit.h +1 -1
  191. data/share/sample/ruby-1.9.3-p0/adlint/ext-continuation/adlint_pinit.h +1 -1
  192. data/share/sample/ruby-1.9.3-p0/adlint/ext-continuation/adlint_traits.yml +50 -42
  193. data/share/sample/ruby-1.9.3-p0/adlint/ext-coverage/GNUmakefile +1 -1
  194. data/share/sample/ruby-1.9.3-p0/adlint/ext-coverage/adlint_cinit.h +1 -1
  195. data/share/sample/ruby-1.9.3-p0/adlint/ext-coverage/adlint_pinit.h +1 -1
  196. data/share/sample/ruby-1.9.3-p0/adlint/ext-coverage/adlint_traits.yml +50 -42
  197. data/share/sample/ruby-1.9.3-p0/adlint/ext-curses/GNUmakefile +1 -1
  198. data/share/sample/ruby-1.9.3-p0/adlint/ext-curses/adlint_cinit.h +1 -1
  199. data/share/sample/ruby-1.9.3-p0/adlint/ext-curses/adlint_pinit.h +1 -1
  200. data/share/sample/ruby-1.9.3-p0/adlint/ext-curses/adlint_traits.yml +50 -42
  201. data/share/sample/ruby-1.9.3-p0/adlint/ext-date/GNUmakefile +1 -1
  202. data/share/sample/ruby-1.9.3-p0/adlint/ext-date/adlint_cinit.h +1 -1
  203. data/share/sample/ruby-1.9.3-p0/adlint/ext-date/adlint_pinit.h +1 -1
  204. data/share/sample/ruby-1.9.3-p0/adlint/ext-date/adlint_traits.yml +50 -42
  205. data/share/sample/ruby-1.9.3-p0/adlint/ext-dbm/GNUmakefile +1 -1
  206. data/share/sample/ruby-1.9.3-p0/adlint/ext-dbm/adlint_cinit.h +1 -1
  207. data/share/sample/ruby-1.9.3-p0/adlint/ext-dbm/adlint_pinit.h +1 -1
  208. data/share/sample/ruby-1.9.3-p0/adlint/ext-dbm/adlint_traits.yml +50 -42
  209. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-bubblebabble/GNUmakefile +1 -1
  210. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-bubblebabble/adlint_cinit.h +1 -1
  211. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-bubblebabble/adlint_pinit.h +1 -1
  212. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-bubblebabble/adlint_traits.yml +50 -42
  213. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-md5/GNUmakefile +1 -1
  214. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-md5/adlint_cinit.h +1 -1
  215. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-md5/adlint_pinit.h +1 -1
  216. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-md5/adlint_traits.yml +50 -42
  217. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-rmd160/GNUmakefile +1 -1
  218. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-rmd160/adlint_cinit.h +1 -1
  219. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-rmd160/adlint_pinit.h +1 -1
  220. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-rmd160/adlint_traits.yml +50 -42
  221. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha1/GNUmakefile +1 -1
  222. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha1/adlint_cinit.h +1 -1
  223. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha1/adlint_pinit.h +1 -1
  224. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha1/adlint_traits.yml +50 -42
  225. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha2/GNUmakefile +1 -1
  226. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha2/adlint_cinit.h +1 -1
  227. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha2/adlint_pinit.h +1 -1
  228. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha2/adlint_traits.yml +50 -42
  229. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest/GNUmakefile +1 -1
  230. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest/adlint_cinit.h +1 -1
  231. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest/adlint_pinit.h +1 -1
  232. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest/adlint_traits.yml +50 -42
  233. data/share/sample/ruby-1.9.3-p0/adlint/ext-dl-callback/GNUmakefile +1 -1
  234. data/share/sample/ruby-1.9.3-p0/adlint/ext-dl-callback/adlint_cinit.h +1 -1
  235. data/share/sample/ruby-1.9.3-p0/adlint/ext-dl-callback/adlint_pinit.h +1 -1
  236. data/share/sample/ruby-1.9.3-p0/adlint/ext-dl-callback/adlint_traits.yml +50 -42
  237. data/share/sample/ruby-1.9.3-p0/adlint/ext-dl/GNUmakefile +1 -1
  238. data/share/sample/ruby-1.9.3-p0/adlint/ext-dl/adlint_cinit.h +1 -1
  239. data/share/sample/ruby-1.9.3-p0/adlint/ext-dl/adlint_pinit.h +1 -1
  240. data/share/sample/ruby-1.9.3-p0/adlint/ext-dl/adlint_traits.yml +50 -42
  241. data/share/sample/ruby-1.9.3-p0/adlint/ext-etc/GNUmakefile +1 -1
  242. data/share/sample/ruby-1.9.3-p0/adlint/ext-etc/adlint_cinit.h +1 -1
  243. data/share/sample/ruby-1.9.3-p0/adlint/ext-etc/adlint_pinit.h +1 -1
  244. data/share/sample/ruby-1.9.3-p0/adlint/ext-etc/adlint_traits.yml +50 -42
  245. data/share/sample/ruby-1.9.3-p0/adlint/ext-fcntl/GNUmakefile +1 -1
  246. data/share/sample/ruby-1.9.3-p0/adlint/ext-fcntl/adlint_cinit.h +1 -1
  247. data/share/sample/ruby-1.9.3-p0/adlint/ext-fcntl/adlint_pinit.h +1 -1
  248. data/share/sample/ruby-1.9.3-p0/adlint/ext-fcntl/adlint_traits.yml +50 -42
  249. data/share/sample/ruby-1.9.3-p0/adlint/ext-fiber/GNUmakefile +1 -1
  250. data/share/sample/ruby-1.9.3-p0/adlint/ext-fiber/adlint_cinit.h +1 -1
  251. data/share/sample/ruby-1.9.3-p0/adlint/ext-fiber/adlint_pinit.h +1 -1
  252. data/share/sample/ruby-1.9.3-p0/adlint/ext-fiber/adlint_traits.yml +50 -42
  253. data/share/sample/ruby-1.9.3-p0/adlint/ext-fiddle/GNUmakefile +1 -1
  254. data/share/sample/ruby-1.9.3-p0/adlint/ext-fiddle/adlint_cinit.h +1 -1
  255. data/share/sample/ruby-1.9.3-p0/adlint/ext-fiddle/adlint_pinit.h +1 -1
  256. data/share/sample/ruby-1.9.3-p0/adlint/ext-fiddle/adlint_traits.yml +50 -42
  257. data/share/sample/ruby-1.9.3-p0/adlint/ext-gdbm/GNUmakefile +1 -1
  258. data/share/sample/ruby-1.9.3-p0/adlint/ext-gdbm/adlint_cinit.h +1 -1
  259. data/share/sample/ruby-1.9.3-p0/adlint/ext-gdbm/adlint_pinit.h +1 -1
  260. data/share/sample/ruby-1.9.3-p0/adlint/ext-gdbm/adlint_traits.yml +50 -42
  261. data/share/sample/ruby-1.9.3-p0/adlint/ext-iconv/GNUmakefile +1 -1
  262. data/share/sample/ruby-1.9.3-p0/adlint/ext-iconv/adlint_cinit.h +1 -1
  263. data/share/sample/ruby-1.9.3-p0/adlint/ext-iconv/adlint_pinit.h +1 -1
  264. data/share/sample/ruby-1.9.3-p0/adlint/ext-iconv/adlint_traits.yml +50 -42
  265. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-console/GNUmakefile +1 -1
  266. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-console/adlint_cinit.h +1 -1
  267. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-console/adlint_pinit.h +1 -1
  268. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-console/adlint_traits.yml +50 -42
  269. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-nonblock/GNUmakefile +1 -1
  270. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-nonblock/adlint_cinit.h +1 -1
  271. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-nonblock/adlint_pinit.h +1 -1
  272. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-nonblock/adlint_traits.yml +50 -42
  273. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-wait/GNUmakefile +1 -1
  274. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-wait/adlint_cinit.h +1 -1
  275. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-wait/adlint_pinit.h +1 -1
  276. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-wait/adlint_traits.yml +50 -42
  277. data/share/sample/ruby-1.9.3-p0/adlint/ext-json-generator/GNUmakefile +1 -1
  278. data/share/sample/ruby-1.9.3-p0/adlint/ext-json-generator/adlint_cinit.h +1 -1
  279. data/share/sample/ruby-1.9.3-p0/adlint/ext-json-generator/adlint_pinit.h +1 -1
  280. data/share/sample/ruby-1.9.3-p0/adlint/ext-json-generator/adlint_traits.yml +50 -42
  281. data/share/sample/ruby-1.9.3-p0/adlint/ext-json-parser/GNUmakefile +1 -1
  282. data/share/sample/ruby-1.9.3-p0/adlint/ext-json-parser/adlint_cinit.h +1 -1
  283. data/share/sample/ruby-1.9.3-p0/adlint/ext-json-parser/adlint_pinit.h +1 -1
  284. data/share/sample/ruby-1.9.3-p0/adlint/ext-json-parser/adlint_traits.yml +50 -42
  285. data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-complex/GNUmakefile +1 -1
  286. data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-complex/adlint_cinit.h +1 -1
  287. data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-complex/adlint_pinit.h +1 -1
  288. data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-complex/adlint_traits.yml +50 -42
  289. data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-rational/GNUmakefile +1 -1
  290. data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-rational/adlint_cinit.h +1 -1
  291. data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-rational/adlint_pinit.h +1 -1
  292. data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-rational/adlint_traits.yml +50 -42
  293. data/share/sample/ruby-1.9.3-p0/adlint/ext-nkf/GNUmakefile +1 -1
  294. data/share/sample/ruby-1.9.3-p0/adlint/ext-nkf/adlint_cinit.h +1 -1
  295. data/share/sample/ruby-1.9.3-p0/adlint/ext-nkf/adlint_pinit.h +1 -1
  296. data/share/sample/ruby-1.9.3-p0/adlint/ext-nkf/adlint_traits.yml +50 -42
  297. data/share/sample/ruby-1.9.3-p0/adlint/ext-openssl/GNUmakefile +1 -1
  298. data/share/sample/ruby-1.9.3-p0/adlint/ext-openssl/adlint_cinit.h +1 -1
  299. data/share/sample/ruby-1.9.3-p0/adlint/ext-openssl/adlint_pinit.h +1 -1
  300. data/share/sample/ruby-1.9.3-p0/adlint/ext-openssl/adlint_traits.yml +50 -42
  301. data/share/sample/ruby-1.9.3-p0/adlint/ext-pathname/GNUmakefile +1 -1
  302. data/share/sample/ruby-1.9.3-p0/adlint/ext-pathname/adlint_cinit.h +1 -1
  303. data/share/sample/ruby-1.9.3-p0/adlint/ext-pathname/adlint_pinit.h +1 -1
  304. data/share/sample/ruby-1.9.3-p0/adlint/ext-pathname/adlint_traits.yml +50 -42
  305. data/share/sample/ruby-1.9.3-p0/adlint/ext-psych/GNUmakefile +1 -1
  306. data/share/sample/ruby-1.9.3-p0/adlint/ext-psych/adlint_cinit.h +1 -1
  307. data/share/sample/ruby-1.9.3-p0/adlint/ext-psych/adlint_pinit.h +1 -1
  308. data/share/sample/ruby-1.9.3-p0/adlint/ext-psych/adlint_traits.yml +50 -42
  309. data/share/sample/ruby-1.9.3-p0/adlint/ext-pty/GNUmakefile +1 -1
  310. data/share/sample/ruby-1.9.3-p0/adlint/ext-pty/adlint_cinit.h +1 -1
  311. data/share/sample/ruby-1.9.3-p0/adlint/ext-pty/adlint_pinit.h +1 -1
  312. data/share/sample/ruby-1.9.3-p0/adlint/ext-pty/adlint_traits.yml +50 -42
  313. data/share/sample/ruby-1.9.3-p0/adlint/ext-racc-cparse/GNUmakefile +1 -1
  314. data/share/sample/ruby-1.9.3-p0/adlint/ext-racc-cparse/adlint_cinit.h +1 -1
  315. data/share/sample/ruby-1.9.3-p0/adlint/ext-racc-cparse/adlint_pinit.h +1 -1
  316. data/share/sample/ruby-1.9.3-p0/adlint/ext-racc-cparse/adlint_traits.yml +50 -42
  317. data/share/sample/ruby-1.9.3-p0/adlint/ext-readline/GNUmakefile +1 -1
  318. data/share/sample/ruby-1.9.3-p0/adlint/ext-readline/adlint_cinit.h +1 -1
  319. data/share/sample/ruby-1.9.3-p0/adlint/ext-readline/adlint_pinit.h +1 -1
  320. data/share/sample/ruby-1.9.3-p0/adlint/ext-readline/adlint_traits.yml +50 -42
  321. data/share/sample/ruby-1.9.3-p0/adlint/ext-ripper/GNUmakefile +1 -1
  322. data/share/sample/ruby-1.9.3-p0/adlint/ext-ripper/adlint_cinit.h +1 -1
  323. data/share/sample/ruby-1.9.3-p0/adlint/ext-ripper/adlint_pinit.h +1 -1
  324. data/share/sample/ruby-1.9.3-p0/adlint/ext-ripper/adlint_traits.yml +50 -42
  325. data/share/sample/ruby-1.9.3-p0/adlint/ext-sdbm/GNUmakefile +1 -1
  326. data/share/sample/ruby-1.9.3-p0/adlint/ext-sdbm/adlint_cinit.h +1 -1
  327. data/share/sample/ruby-1.9.3-p0/adlint/ext-sdbm/adlint_pinit.h +1 -1
  328. data/share/sample/ruby-1.9.3-p0/adlint/ext-sdbm/adlint_traits.yml +50 -42
  329. data/share/sample/ruby-1.9.3-p0/adlint/ext-socket/GNUmakefile +1 -1
  330. data/share/sample/ruby-1.9.3-p0/adlint/ext-socket/adlint_cinit.h +1 -1
  331. data/share/sample/ruby-1.9.3-p0/adlint/ext-socket/adlint_pinit.h +1 -1
  332. data/share/sample/ruby-1.9.3-p0/adlint/ext-socket/adlint_traits.yml +50 -42
  333. data/share/sample/ruby-1.9.3-p0/adlint/ext-stringio/GNUmakefile +1 -1
  334. data/share/sample/ruby-1.9.3-p0/adlint/ext-stringio/adlint_cinit.h +1 -1
  335. data/share/sample/ruby-1.9.3-p0/adlint/ext-stringio/adlint_pinit.h +1 -1
  336. data/share/sample/ruby-1.9.3-p0/adlint/ext-stringio/adlint_traits.yml +50 -42
  337. data/share/sample/ruby-1.9.3-p0/adlint/ext-strscan/GNUmakefile +1 -1
  338. data/share/sample/ruby-1.9.3-p0/adlint/ext-strscan/adlint_cinit.h +1 -1
  339. data/share/sample/ruby-1.9.3-p0/adlint/ext-strscan/adlint_pinit.h +1 -1
  340. data/share/sample/ruby-1.9.3-p0/adlint/ext-strscan/adlint_traits.yml +50 -42
  341. data/share/sample/ruby-1.9.3-p0/adlint/ext-syck/GNUmakefile +1 -1
  342. data/share/sample/ruby-1.9.3-p0/adlint/ext-syck/adlint_cinit.h +1 -1
  343. data/share/sample/ruby-1.9.3-p0/adlint/ext-syck/adlint_pinit.h +1 -1
  344. data/share/sample/ruby-1.9.3-p0/adlint/ext-syck/adlint_traits.yml +50 -42
  345. data/share/sample/ruby-1.9.3-p0/adlint/ext-syslog/GNUmakefile +1 -1
  346. data/share/sample/ruby-1.9.3-p0/adlint/ext-syslog/adlint_cinit.h +1 -1
  347. data/share/sample/ruby-1.9.3-p0/adlint/ext-syslog/adlint_pinit.h +1 -1
  348. data/share/sample/ruby-1.9.3-p0/adlint/ext-syslog/adlint_traits.yml +50 -42
  349. data/share/sample/ruby-1.9.3-p0/adlint/ext-zlib/GNUmakefile +1 -1
  350. data/share/sample/ruby-1.9.3-p0/adlint/ext-zlib/adlint_cinit.h +1 -1
  351. data/share/sample/ruby-1.9.3-p0/adlint/ext-zlib/adlint_pinit.h +1 -1
  352. data/share/sample/ruby-1.9.3-p0/adlint/ext-zlib/adlint_traits.yml +50 -42
  353. data/share/sample/screen-4.0.3/adlint/GNUmakefile +1 -1
  354. data/share/sample/screen-4.0.3/adlint/adlint_cinit.h +1 -1
  355. data/share/sample/screen-4.0.3/adlint/adlint_pinit.h +1 -1
  356. data/share/sample/screen-4.0.3/adlint/adlint_traits.yml +50 -42
  357. data/share/sample/vim-7.3/adlint/vim/GNUmakefile +1 -1
  358. data/share/sample/vim-7.3/adlint/vim/adlint_cinit.h +1 -1
  359. data/share/sample/vim-7.3/adlint/vim/adlint_pinit.h +1 -1
  360. data/share/sample/vim-7.3/adlint/vim/adlint_traits.yml +50 -42
  361. data/share/sample/vim-7.3/adlint/xxd/GNUmakefile +1 -1
  362. data/share/sample/vim-7.3/adlint/xxd/adlint_cinit.h +1 -1
  363. data/share/sample/vim-7.3/adlint/xxd/adlint_pinit.h +1 -1
  364. data/share/sample/vim-7.3/adlint/xxd/adlint_traits.yml +49 -41
  365. data/share/sample/zsh-4.3.15/adlint/GNUmakefile +1 -1
  366. data/share/sample/zsh-4.3.15/adlint/adlint_traits.yml +46 -38
  367. data/share/sample/zsh-4.3.15/adlint/builtins/GNUmakefile +1 -1
  368. data/share/sample/zsh-4.3.15/adlint/builtins/adlint_cinit.h +1 -1
  369. data/share/sample/zsh-4.3.15/adlint/builtins/adlint_pinit.h +1 -1
  370. data/share/sample/zsh-4.3.15/adlint/builtins/adlint_traits.yml +50 -42
  371. data/share/sample/zsh-4.3.15/adlint/core/GNUmakefile +1 -1
  372. data/share/sample/zsh-4.3.15/adlint/core/adlint_cinit.h +1 -1
  373. data/share/sample/zsh-4.3.15/adlint/core/adlint_pinit.h +1 -1
  374. data/share/sample/zsh-4.3.15/adlint/core/adlint_traits.yml +50 -42
  375. data/share/sample/zsh-4.3.15/adlint/modules/GNUmakefile +1 -1
  376. data/share/sample/zsh-4.3.15/adlint/modules/adlint_cinit.h +1 -1
  377. data/share/sample/zsh-4.3.15/adlint/modules/adlint_pinit.h +1 -1
  378. data/share/sample/zsh-4.3.15/adlint/modules/adlint_traits.yml +50 -42
  379. data/share/sample/zsh-4.3.15/adlint/zle/GNUmakefile +1 -1
  380. data/share/sample/zsh-4.3.15/adlint/zle/adlint_cinit.h +1 -1
  381. data/share/sample/zsh-4.3.15/adlint/zle/adlint_pinit.h +1 -1
  382. data/share/sample/zsh-4.3.15/adlint/zle/adlint_traits.yml +50 -42
  383. data/spec/adlint/{c → cc1}/ctrlexpr_spec.rb +51 -49
  384. data/spec/adlint/{c → cc1}/domain_spec.rb +210 -179
  385. data/spec/adlint/{c → cc1}/operator_spec.rb +3 -3
  386. data/spec/adlint/{c → cc1}/syntax_spec.rb +10 -12
  387. data/spec/adlint/{c → cc1}/type_spec.rb +61 -68
  388. data/{lib/adlint/c.rb → spec/adlint/location_spec.rb} +24 -29
  389. data/spec/conf.d/default_traits.yml +38 -37
  390. data/spec/conf.d/empty_cinit.h +1 -1
  391. data/spec/conf.d/empty_pinit.h +1 -1
  392. data/spec/conf.d/project/foo.c +0 -0
  393. data/spec/spec_helper.rb +2 -2
  394. metadata +60 -40
  395. data/lib/adlint/c/domain.rb +0 -7931
  396. data/lib/adlint/c/lexer.rb +0 -252
  397. data/lib/adlint/c/phase.rb +0 -135
  398. data/lib/adlint/exam/c_builtin/c_check.rb +0 -20745
  399. data/lib/adlint/exam/c_builtin/c_check_shima.rb +0 -983
  400. data/lib/adlint/exam/c_builtin/c_code.rb +0 -477
  401. data/lib/adlint/exam/c_builtin/c_metric.rb +0 -818
@@ -1,7 +1,7 @@
1
1
  # Lexical analyzer which tokenizes C language source into pp-tokens.
2
2
  #
3
3
  # Author:: Yutaka Yanoh <mailto:yanoh@users.sourceforge.net>
4
- # Copyright:: Copyright (C) 2010-2012, OGIS-RI Co.,Ltd.
4
+ # Copyright:: Copyright (C) 2010-2013, OGIS-RI Co.,Ltd.
5
5
  # License:: GPLv3+: GNU General Public License version 3 or later
6
6
  #
7
7
  # Owner:: Yutaka Yanoh <mailto:yanoh@users.sourceforge.net>
@@ -11,7 +11,7 @@
11
11
  # / | / _ |/ / / / | / /__ __/ Source Code Static Analyzer
12
12
  # / /| | / / / / / / / |/ / / / AdLint - Advanced Lint
13
13
  # / __ |/ /_/ / /___/ / /| / / /
14
- # /_/ |_|_____/_____/_/_/ |_/ /_/ Copyright (C) 2010-2012, OGIS-RI Co.,Ltd.
14
+ # /_/ |_|_____/_____/_/_/ |_/ /_/ Copyright (C) 2010-2013, OGIS-RI Co.,Ltd.
15
15
  #
16
16
  # This file is part of AdLint.
17
17
  #
@@ -37,17 +37,18 @@ module AdLint #:nodoc:
37
37
  module Cpp #:nodoc:
38
38
 
39
39
  class Lexer
40
- def initialize(source)
41
- source.on_cr_at_eol_found += lambda { |location|
42
- on_cr_at_eol_found.invoke(location)
40
+ def initialize(src, traits)
41
+ src.on_cr_at_eol_found += lambda { |loc|
42
+ on_cr_at_eol_found.invoke(loc)
43
43
  }
44
- source.on_eof_mark_at_eof_found += lambda { |location|
45
- on_eof_mark_at_eof_found.invoke(location)
44
+ src.on_eof_mark_at_eof_found += lambda { |loc|
45
+ on_eof_mark_at_eof_found.invoke(loc)
46
46
  }
47
- source.on_eof_newline_not_found += method(:notify_eof_newline_not_found)
47
+ src.on_eof_newline_not_found += method(:notify_eof_newline_not_found)
48
48
 
49
- @content = SourceContent.lazy_new(source)
50
- @state = Initial.new(self)
49
+ tab_width = traits.of_project.coding_style.tab_width
50
+ @content = SourceContent.lazy_new(src, tab_width)
51
+ @state = Initial.new(self)
51
52
  @top_token = nil
52
53
  end
53
54
 
@@ -67,9 +68,9 @@ module Cpp #:nodoc:
67
68
 
68
69
  def next_token
69
70
  if @top_token
70
- token = @top_token
71
+ tok = @top_token
71
72
  @top_token = nil
72
- return token
73
+ return tok
73
74
  end
74
75
  @state.next_token
75
76
  end
@@ -104,17 +105,17 @@ module Cpp #:nodoc:
104
105
  def discard_heading_comments
105
106
  case
106
107
  when @content.check(/\/\*/)
107
- location = @content.location
108
+ loc = @content.location
108
109
  comment = scan_block_comment(@content)
109
110
  unless comment.empty?
110
- notify_block_comment_found(comment, location)
111
+ notify_block_comment_found(comment, loc)
111
112
  return true
112
113
  end
113
114
  when @content.check(/\/\//)
114
- location = @content.location
115
+ loc = @content.location
115
116
  comment = scan_line_comment(@content)
116
117
  unless comment.empty?
117
- notify_line_comment_found(comment, location)
118
+ notify_line_comment_found(comment, loc)
118
119
  return true
119
120
  end
120
121
  end
@@ -125,32 +126,32 @@ module Cpp #:nodoc:
125
126
  @state = next_state
126
127
  end
127
128
 
128
- def notify_block_comment_found(comment, location)
129
- on_block_comment_found.invoke(comment, location)
129
+ def notify_block_comment_found(comment, loc)
130
+ on_block_comment_found.invoke(comment, loc)
130
131
  end
131
132
 
132
- def notify_line_comment_found(comment, location)
133
- on_line_comment_found.invoke(comment, location)
133
+ def notify_line_comment_found(comment, loc)
134
+ on_line_comment_found.invoke(comment, loc)
134
135
  end
135
136
 
136
- def notify_nested_block_comment_found(location)
137
- on_nested_block_comment_found.invoke(location)
137
+ def notify_nested_block_comment_found(loc)
138
+ on_nested_block_comment_found.invoke(loc)
138
139
  end
139
140
 
140
- def notify_unterminated_block_comment(location)
141
- on_unterminated_block_comment.invoke(location)
141
+ def notify_unterminated_block_comment(loc)
142
+ on_unterminated_block_comment.invoke(loc)
142
143
  end
143
144
 
144
- def notify_eof_newline_not_found(location)
145
- on_eof_newline_not_found.invoke(location)
145
+ def notify_eof_newline_not_found(loc)
146
+ on_eof_newline_not_found.invoke(loc)
146
147
  end
147
148
 
148
- def notify_unlexable_char_found(char, location)
149
- on_unlexable_char_found.invoke(char, location)
149
+ def notify_unlexable_char_found(char, loc)
150
+ on_unlexable_char_found.invoke(char, loc)
150
151
  end
151
152
 
152
- def notify_illformed_newline_escape_found(location)
153
- on_illformed_newline_escape_found.invoke(location)
153
+ def notify_illformed_newline_escape_found(loc)
154
+ on_illformed_newline_escape_found.invoke(loc)
154
155
  end
155
156
 
156
157
  private
@@ -158,37 +159,37 @@ module Cpp #:nodoc:
158
159
  /^[ \t]*#[ \t]*(?:if|ifdef|ifndef|asm|else|elif|endif|endasm)\b/
159
160
  private_constant :GROUP_DIRECTIVE_RE
160
161
 
161
- def scan_until_next_directive_or_comment(content)
162
- content.scan(/.*?(?=#{GROUP_DIRECTIVE_RE}|\/\*|\/\/)/m)
162
+ def scan_until_next_directive_or_comment(cont)
163
+ cont.scan(/.*?(?=#{GROUP_DIRECTIVE_RE}|\/\*|\/\/)/m)
163
164
  end
164
165
 
165
- def scan_block_comment(content)
166
- result = ""
166
+ def scan_block_comment(cont)
167
+ comment = ""
167
168
  block_depth = 0
168
- until content.empty?
169
- location = content.location
169
+ until cont.empty?
170
+ loc = cont.location
170
171
  case
171
- when content.scan(/\/\*/)
172
+ when cont.scan(/\/\*/)
172
173
  block_depth += 1
173
- result += "/*"
174
- notify_nested_block_comment_found(location) if block_depth > 1
175
- when content.scan(/\*\//)
176
- result += "*/"
174
+ comment += "/*"
175
+ notify_nested_block_comment_found(loc) if block_depth > 1
176
+ when cont.scan(/\*\//)
177
+ comment += "*/"
177
178
  break
178
179
  else
179
180
  return nil if block_depth == 0
180
- if comment = content.scan(/.*?(?=\/\*|\*\/)/m)
181
- result += comment
181
+ if scanned = cont.scan(/.*?(?=\/\*|\*\/)/m)
182
+ comment += scanned
182
183
  else
183
- notify_unterminated_block_comment(location)
184
+ notify_unterminated_block_comment(loc)
184
185
  end
185
186
  end
186
187
  end
187
- result
188
+ comment
188
189
  end
189
190
 
190
- def scan_line_comment(content)
191
- content.scan(/\/\/.*?(?=\n)/)
191
+ def scan_line_comment(cont)
192
+ cont.scan(/\/\/.*?(?=\n)/)
192
193
  end
193
194
  end
194
195
 
@@ -206,80 +207,80 @@ module Cpp #:nodoc:
206
207
  @lexer.discard_heading_comments
207
208
  end
208
209
 
209
- def scan_escaped_newline(content)
210
- location = content.location
210
+ def scan_escaped_newline(cont)
211
+ loc = cont.location
211
212
  case
212
- when escaped_newline = content.scan(/\\\n/)
213
- escaped_newline
214
- when escaped_newline = content.scan(/\\[ \t]+\n/)
215
- @lexer.notify_illformed_newline_escape_found(location)
216
- escaped_newline
213
+ when escaped_nl = cont.scan(/\\\n/)
214
+ escaped_nl
215
+ when escaped_nl = cont.scan(/\\[ \t]+\n/)
216
+ @lexer.notify_illformed_newline_escape_found(loc)
217
+ escaped_nl
217
218
  else
218
219
  nil
219
220
  end
220
221
  end
221
222
 
222
- def tokenize_pp_token(content)
223
- location = content.location
223
+ def tokenize_pp_token(cont)
224
+ loc = cont.location
224
225
  case
225
- when value = Language::C.scan_keyword(content),
226
- value = Language::Cpp.scan_keyword(content)
227
- Token.new(:PP_TOKEN, value, location, Language::C::KEYWORDS[value])
228
- when value = Language::C.scan_char_constant(content),
229
- value = Language::C.scan_floating_constant(content),
230
- value = Language::C.scan_integer_constant(content)
231
- Token.new(:PP_TOKEN, value, location, :CONSTANT)
232
- when value = Language::C.scan_string_literal(content)
233
- Token.new(:PP_TOKEN, value, location, :STRING_LITERAL)
234
- when value = Language::C.scan_null_constant(content)
235
- Token.new(:PP_TOKEN, value, location, :NULL)
236
- when value = Language::C.scan_identifier(content)
237
- Token.new(:PP_TOKEN, value, location, :IDENTIFIER)
238
- when value = Language::Cpp.scan_punctuator(content)
239
- Token.new(:PP_TOKEN, value, location, value)
226
+ when val = Language::C.scan_keyword(cont),
227
+ val = Language::Cpp.scan_keyword(cont)
228
+ Token.new(:PP_TOKEN, val, loc, Language::C::KEYWORDS[val])
229
+ when val = Language::C.scan_char_constant(cont),
230
+ val = Language::C.scan_floating_constant(cont),
231
+ val = Language::C.scan_integer_constant(cont)
232
+ Token.new(:PP_TOKEN, val, loc, :CONSTANT)
233
+ when val = Language::C.scan_string_literal(cont)
234
+ Token.new(:PP_TOKEN, val, loc, :STRING_LITERAL)
235
+ when val = Language::C.scan_null_constant(cont)
236
+ Token.new(:PP_TOKEN, val, loc, :NULL)
237
+ when val = Language::C.scan_identifier(cont)
238
+ Token.new(:PP_TOKEN, val, loc, :IDENTIFIER)
239
+ when val = Language::Cpp.scan_punctuator(cont)
240
+ Token.new(:PP_TOKEN, val, loc, val)
240
241
  else
241
242
  nil
242
243
  end
243
244
  end
244
245
 
245
- def tokenize_new_line(content)
246
- location = content.location
247
- if value = content.scan(/\n/)
248
- return Token.new(:NEW_LINE, value, location)
246
+ def tokenize_new_line(cont)
247
+ loc = cont.location
248
+ if val = cont.scan(/\n/)
249
+ return Token.new(:NEW_LINE, val, loc)
249
250
  end
250
251
  nil
251
252
  end
252
253
 
253
- def tokenize_header_name(content)
254
- location = content.location
255
- if value = Language::Cpp.scan_system_header_name(content)
256
- return Token.new(:SYS_HEADER_NAME, value, location)
257
- elsif value = Language::Cpp.scan_user_header_name(content)
258
- return Token.new(:USR_HEADER_NAME, value, location)
254
+ def tokenize_header_name(cont)
255
+ loc = cont.location
256
+ if val = Language::Cpp.scan_system_header_name(cont)
257
+ return Token.new(:SYS_HEADER_NAME, val, loc)
258
+ elsif val = Language::Cpp.scan_user_header_name(cont)
259
+ return Token.new(:USR_HEADER_NAME, val, loc)
259
260
  end
260
261
  nil
261
262
  end
262
263
 
263
- def tokenize_identifier(content)
264
- location = content.location
265
- if value = Language::C.scan_identifier(content)
266
- return Token.new(:IDENTIFIER, value, location)
264
+ def tokenize_identifier(cont)
265
+ loc = cont.location
266
+ if val = Language::C.scan_identifier(cont)
267
+ return Token.new(:IDENTIFIER, val, loc)
267
268
  end
268
269
  nil
269
270
  end
270
271
 
271
- def tokenize_punctuator(content)
272
- location = content.location
273
- if punctuator = Language::Cpp.scan_punctuator(content)
274
- return Token.new(punctuator, punctuator, location)
272
+ def tokenize_punctuator(cont)
273
+ loc = cont.location
274
+ if punctuator = Language::Cpp.scan_punctuator(cont)
275
+ return Token.new(punctuator, punctuator, loc)
275
276
  end
276
277
  nil
277
278
  end
278
279
 
279
- def tokenize_extra_token(content)
280
+ def tokenize_extra_token(cont)
280
281
  # NOTE: #tokenize_pp_token can tokenize almost all types of tokens.
281
- if token = tokenize_pp_token(content)
282
- Token.new(:EXTRA_TOKEN, token.value, token.location)
282
+ if tok = tokenize_pp_token(cont)
283
+ Token.new(:EXTRA_TOKEN, tok.value, tok.location)
283
284
  else
284
285
  nil
285
286
  end
@@ -295,225 +296,225 @@ module Cpp #:nodoc:
295
296
  case
296
297
  when @lexer.content.check(/[ \t]*#/)
297
298
  case
298
- when token = tokenize_if_directive(@lexer.content)
299
+ when tok = tokenize_if_directive(@lexer.content)
299
300
  @lexer.transit(InIfDirective.new(@lexer))
300
- when token = tokenize_ifdef_directive(@lexer.content)
301
+ when tok = tokenize_ifdef_directive(@lexer.content)
301
302
  @lexer.transit(InIfdefDirective.new(@lexer))
302
- when token = tokenize_ifndef_directive(@lexer.content)
303
+ when tok = tokenize_ifndef_directive(@lexer.content)
303
304
  @lexer.transit(InIfndefDirective.new(@lexer))
304
- when token = tokenize_elif_directive(@lexer.content)
305
+ when tok = tokenize_elif_directive(@lexer.content)
305
306
  @lexer.transit(InElifDirective.new(@lexer))
306
- when token = tokenize_else_directive(@lexer.content)
307
+ when tok = tokenize_else_directive(@lexer.content)
307
308
  @lexer.transit(InElseDirective.new(@lexer))
308
- when token = tokenize_endif_directive(@lexer.content)
309
+ when tok = tokenize_endif_directive(@lexer.content)
309
310
  @lexer.transit(InEndifDirective.new(@lexer))
310
- when token = tokenize_include_directive(@lexer.content)
311
+ when tok = tokenize_include_directive(@lexer.content)
311
312
  @lexer.transit(InIncludeDirective.new(@lexer))
312
- when token = tokenize_include_next_directive(@lexer.content)
313
+ when tok = tokenize_include_next_directive(@lexer.content)
313
314
  @lexer.transit(InIncludeNextDirective.new(@lexer))
314
- when token = tokenize_define_directive(@lexer.content)
315
+ when tok = tokenize_define_directive(@lexer.content)
315
316
  @lexer.transit(InDefineDirective.new(@lexer))
316
- when token = tokenize_undef_directive(@lexer.content)
317
+ when tok = tokenize_undef_directive(@lexer.content)
317
318
  @lexer.transit(InUndefDirective.new(@lexer))
318
- when token = tokenize_line_directive(@lexer.content)
319
+ when tok = tokenize_line_directive(@lexer.content)
319
320
  @lexer.transit(InLineDirective.new(@lexer))
320
- when token = tokenize_error_directive(@lexer.content)
321
+ when tok = tokenize_error_directive(@lexer.content)
321
322
  @lexer.transit(InErrorDirective.new(@lexer))
322
- when token = tokenize_pragma_directive(@lexer.content)
323
+ when tok = tokenize_pragma_directive(@lexer.content)
323
324
  @lexer.transit(InPragmaDirective.new(@lexer))
324
- when token = tokenize_asm_directive(@lexer.content)
325
+ when tok = tokenize_asm_directive(@lexer.content)
325
326
  @lexer.transit(InAsmDirective.new(@lexer))
326
- when token = tokenize_endasm_directive(@lexer.content)
327
+ when tok = tokenize_endasm_directive(@lexer.content)
327
328
  @lexer.transit(InEndasmDirective.new(@lexer))
328
329
  else
329
- token = tokenize_null_directive(@lexer.content) ||
330
- tokenize_unknown_directive(@lexer.content)
330
+ tok = tokenize_null_directive(@lexer.content) ||
331
+ tokenize_unknown_directive(@lexer.content)
331
332
  end
332
333
  else
333
- token = tokenize_text_line(@lexer.content)
334
+ tok = tokenize_text_line(@lexer.content)
334
335
  end
335
336
 
336
- token
337
+ tok
337
338
  end
338
339
 
339
340
  private
340
- def tokenize_if_directive(content)
341
- location = content.location
342
- if value = content.scan(/[ \t]*#[ \t]*if\b/)
343
- return Token.new(:IF, value, location)
341
+ def tokenize_if_directive(cont)
342
+ loc = cont.location
343
+ if val = cont.scan(/[ \t]*#[ \t]*if\b/)
344
+ return Token.new(:IF, val, loc)
344
345
  end
345
346
  nil
346
347
  end
347
348
 
348
- def tokenize_ifdef_directive(content)
349
- location = content.location
350
- if value = content.scan(/[ \t]*#[ \t]*ifdef\b/)
351
- return Token.new(:IFDEF, value, location)
349
+ def tokenize_ifdef_directive(cont)
350
+ loc = cont.location
351
+ if val = cont.scan(/[ \t]*#[ \t]*ifdef\b/)
352
+ return Token.new(:IFDEF, val, loc)
352
353
  end
353
354
  nil
354
355
  end
355
356
 
356
- def tokenize_ifndef_directive(content)
357
- location = content.location
358
- if value = content.scan(/[ \t]*#[ \t]*ifndef\b/)
359
- return Token.new(:IFNDEF, value, location)
357
+ def tokenize_ifndef_directive(cont)
358
+ loc = cont.location
359
+ if val = cont.scan(/[ \t]*#[ \t]*ifndef\b/)
360
+ return Token.new(:IFNDEF, val, loc)
360
361
  end
361
362
  nil
362
363
  end
363
364
 
364
- def tokenize_elif_directive(content)
365
- location = content.location
366
- if value = content.scan(/[ \t]*#[ \t]*elif\b/)
367
- return Token.new(:ELIF, value, location)
365
+ def tokenize_elif_directive(cont)
366
+ loc = cont.location
367
+ if val = cont.scan(/[ \t]*#[ \t]*elif\b/)
368
+ return Token.new(:ELIF, val, loc)
368
369
  end
369
370
  nil
370
371
  end
371
372
 
372
- def tokenize_else_directive(content)
373
- location = content.location
374
- if value = content.scan(/[ \t]*#[ \t]*else\b/)
375
- return Token.new(:ELSE, value, location)
373
+ def tokenize_else_directive(cont)
374
+ loc = cont.location
375
+ if val = cont.scan(/[ \t]*#[ \t]*else\b/)
376
+ return Token.new(:ELSE, val, loc)
376
377
  end
377
378
  nil
378
379
  end
379
380
 
380
- def tokenize_endif_directive(content)
381
- location = content.location
382
- if value = content.scan(/[ \t]*#[ \t]*endif\b/)
383
- return Token.new(:ENDIF, value, location)
381
+ def tokenize_endif_directive(cont)
382
+ loc = cont.location
383
+ if val = cont.scan(/[ \t]*#[ \t]*endif\b/)
384
+ return Token.new(:ENDIF, val, loc)
384
385
  end
385
386
  nil
386
387
  end
387
388
 
388
- def tokenize_include_directive(content)
389
- location = content.location
390
- if value = content.scan(/[ \t]*#[ \t]*include\b/)
391
- return Token.new(:INCLUDE, value, location)
389
+ def tokenize_include_directive(cont)
390
+ loc = cont.location
391
+ if val = cont.scan(/[ \t]*#[ \t]*include\b/)
392
+ return Token.new(:INCLUDE, val, loc)
392
393
  end
393
394
  nil
394
395
  end
395
396
 
396
- def tokenize_include_next_directive(content)
397
+ def tokenize_include_next_directive(cont)
397
398
  # NOTE: #include_next directive is a GCC extension.
398
- location = content.location
399
- if value = content.scan(/[ \t]*#[ \t]*include_next\b/)
400
- return Token.new(:INCLUDE_NEXT, value, location)
399
+ loc = cont.location
400
+ if val = cont.scan(/[ \t]*#[ \t]*include_next\b/)
401
+ return Token.new(:INCLUDE_NEXT, val, loc)
401
402
  end
402
403
  nil
403
404
  end
404
405
 
405
- def tokenize_define_directive(content)
406
- location = content.location
407
- if value = content.scan(/[ \t]*#[ \t]*define\b/)
408
- return Token.new(:DEFINE, value, location)
406
+ def tokenize_define_directive(cont)
407
+ loc = cont.location
408
+ if val = cont.scan(/[ \t]*#[ \t]*define\b/)
409
+ return Token.new(:DEFINE, val, loc)
409
410
  end
410
411
  nil
411
412
  end
412
413
 
413
- def tokenize_undef_directive(content)
414
- location = content.location
415
- if value = content.scan(/[ \t]*#[ \t]*undef\b/)
416
- return Token.new(:UNDEF, value, location)
414
+ def tokenize_undef_directive(cont)
415
+ loc = cont.location
416
+ if val = cont.scan(/[ \t]*#[ \t]*undef\b/)
417
+ return Token.new(:UNDEF, val, loc)
417
418
  end
418
419
  nil
419
420
  end
420
421
 
421
- def tokenize_line_directive(content)
422
- location = content.location
423
- if value = content.scan(/[ \t]*#[ \t]*line\b/)
424
- return Token.new(:LINE, value, location)
422
+ def tokenize_line_directive(cont)
423
+ loc = cont.location
424
+ if val = cont.scan(/[ \t]*#[ \t]*line\b/)
425
+ return Token.new(:LINE, val, loc)
425
426
  end
426
427
  nil
427
428
  end
428
429
 
429
- def tokenize_error_directive(content)
430
- location = content.location
431
- if value = content.scan(/[ \t]*#[ \t]*error\b/)
432
- return Token.new(:ERROR, value, location)
430
+ def tokenize_error_directive(cont)
431
+ loc = cont.location
432
+ if val = cont.scan(/[ \t]*#[ \t]*error\b/)
433
+ return Token.new(:ERROR, val, loc)
433
434
  end
434
435
  nil
435
436
  end
436
437
 
437
- def tokenize_pragma_directive(content)
438
- location = content.location
439
- if value = content.scan(/[ \t]*#[ \t]*pragma\b/)
440
- return Token.new(:PRAGMA, value, location)
438
+ def tokenize_pragma_directive(cont)
439
+ loc = cont.location
440
+ if val = cont.scan(/[ \t]*#[ \t]*pragma\b/)
441
+ return Token.new(:PRAGMA, val, loc)
441
442
  end
442
443
  nil
443
444
  end
444
445
 
445
- def tokenize_asm_directive(content)
446
- location = content.location
447
- if value = content.scan(/[ \t]*#[ \t]*asm\b/)
448
- return Token.new(:ASM, value, location)
446
+ def tokenize_asm_directive(cont)
447
+ loc = cont.location
448
+ if val = cont.scan(/[ \t]*#[ \t]*asm\b/)
449
+ return Token.new(:ASM, val, loc)
449
450
  end
450
451
  nil
451
452
  end
452
453
 
453
- def tokenize_endasm_directive(content)
454
- location = content.location
455
- if value = content.scan(/[ \t]*#[ \t]*endasm\b/)
456
- return Token.new(:ENDASM, value, location)
454
+ def tokenize_endasm_directive(cont)
455
+ loc = cont.location
456
+ if val = cont.scan(/[ \t]*#[ \t]*endasm\b/)
457
+ return Token.new(:ENDASM, val, loc)
457
458
  end
458
459
  nil
459
460
  end
460
461
 
461
- def tokenize_null_directive(content)
462
- location = content.location
463
- if value = content.scan(/[ \t]*#[ \t]\n/)
464
- return Token.new(:NULL_DIRECTIVE, value, location)
462
+ def tokenize_null_directive(cont)
463
+ loc = cont.location
464
+ if val = cont.scan(/[ \t]*#[ \t]\n/)
465
+ return Token.new(:NULL_DIRECTIVE, val, loc)
465
466
  end
466
467
  nil
467
468
  end
468
469
 
469
- def tokenize_unknown_directive(content)
470
- location = content.location
471
- value = content.scan(/[ \t]*#/)
472
- until content.empty?
473
- next if discard_heading_comments || scan_escaped_newline(content)
470
+ def tokenize_unknown_directive(cont)
471
+ loc = cont.location
472
+ val = cont.scan(/[ \t]*#/)
473
+ until cont.empty?
474
+ next if discard_heading_comments || scan_escaped_newline(cont)
474
475
 
475
476
  case
476
- when str = content.scan(/.+?(?=\/\*|\/\/|\\[ \t]*\n|L?"|L?'|\n)/i)
477
- value += str
478
- when str = content.scan(/\n/)
479
- value += str
477
+ when str = cont.scan(/.+?(?=\/\*|\/\/|\\[ \t]*\n|L?"|L?'|\n)/i)
478
+ val += str
479
+ when str = cont.scan(/\n/)
480
+ val += str
480
481
  break
481
482
  end
482
483
  end
483
- Token.new(:UNKNOWN_DIRECTIVE, value, location)
484
+ Token.new(:UNKNOWN_DIRECTIVE, val, loc)
484
485
  end
485
486
 
486
- def tokenize_text_line(content)
487
- location = content.location
488
- value = ""
487
+ def tokenize_text_line(cont)
488
+ loc = cont.location
489
+ val = ""
489
490
 
490
- until content.empty?
491
- if token = content.scan(/.*?(?=\/\*|\/\/|\\[ \t]*\n|L?"|L?'|\n)/i)
492
- value += token
491
+ until cont.empty?
492
+ if tok = cont.scan(/.*?(?=\/\*|\/\/|\\[ \t]*\n|L?"|L?'|\n)/i)
493
+ val += tok
493
494
  end
494
495
 
495
- if token = content.scan(/\n/)
496
- value += token
496
+ if tok = cont.scan(/\n/)
497
+ val += tok
497
498
  break
498
499
  end
499
500
 
500
- next if scan_escaped_newline(content)
501
+ next if scan_escaped_newline(cont)
501
502
 
502
503
  case
503
- when content.check(/\/\*/)
504
+ when cont.check(/\/\*/)
504
505
  discard_heading_comments
505
- when content.check(/\/\//)
506
+ when cont.check(/\/\//)
506
507
  discard_heading_comments
507
- when content.check(/L?"/i)
508
- string_literal = Language::C.scan_string_literal(content)
509
- value += string_literal
510
- when content.check(/L?'/i)
511
- char_constant = Language::C.scan_char_constant(content)
512
- value += char_constant
508
+ when cont.check(/L?"/i)
509
+ string_literal = Language::C.scan_string_literal(cont)
510
+ val += string_literal
511
+ when cont.check(/L?'/i)
512
+ char_constant = Language::C.scan_char_constant(cont)
513
+ val += char_constant
513
514
  end
514
515
  end
515
516
 
516
- value.empty? ? nil : Token.new(:TEXT_LINE, value, location)
517
+ val.empty? ? nil : Token.new(:TEXT_LINE, val, loc)
517
518
  end
518
519
  end
519
520
 
@@ -524,27 +525,27 @@ module Cpp #:nodoc:
524
525
  next
525
526
  end
526
527
 
527
- token = tokenize_pp_token(@lexer.content) ||
528
- tokenize_new_line(@lexer.content) ||
529
- tokenize_extra_token(@lexer.content)
528
+ tok = tokenize_pp_token(@lexer.content) ||
529
+ tokenize_new_line(@lexer.content) ||
530
+ tokenize_extra_token(@lexer.content)
530
531
 
531
- if token
532
+ if tok
532
533
  break
533
534
  else
534
535
  @lexer.content.eat!
535
536
  end
536
537
  end
537
538
 
538
- unless token
539
- token = Token.new(:NEW_LINE, "\n", @lexer.content.location)
540
- @lexer.notify_eof_newline_not_found(token.location)
539
+ unless tok
540
+ tok = Token.new(:NEW_LINE, "\n", @lexer.content.location)
541
+ @lexer.notify_eof_newline_not_found(tok.location)
541
542
  end
542
543
 
543
- if token.type == :NEW_LINE
544
+ if tok.type == :NEW_LINE
544
545
  @lexer.transit(Initial.new(@lexer))
545
546
  end
546
547
 
547
- token
548
+ tok
548
549
  end
549
550
  end
550
551
 
@@ -555,27 +556,27 @@ module Cpp #:nodoc:
555
556
  next
556
557
  end
557
558
 
558
- token = tokenize_identifier(@lexer.content) ||
559
- tokenize_new_line(@lexer.content) ||
560
- tokenize_extra_token(@lexer.content)
559
+ tok = tokenize_identifier(@lexer.content) ||
560
+ tokenize_new_line(@lexer.content) ||
561
+ tokenize_extra_token(@lexer.content)
561
562
 
562
- if token
563
+ if tok
563
564
  break
564
565
  else
565
566
  @lexer.content.eat!
566
567
  end
567
568
  end
568
569
 
569
- unless token
570
- token = Token.new(:NEW_LINE, "\n", @lexer.content.location)
571
- @lexer.notify_eof_newline_not_found(token.location)
570
+ unless tok
571
+ tok = Token.new(:NEW_LINE, "\n", @lexer.content.location)
572
+ @lexer.notify_eof_newline_not_found(tok.location)
572
573
  end
573
574
 
574
- if token.type == :NEW_LINE
575
+ if tok.type == :NEW_LINE
575
576
  @lexer.transit(Initial.new(@lexer))
576
577
  end
577
578
 
578
- token
579
+ tok
579
580
  end
580
581
  end
581
582
 
@@ -590,26 +591,26 @@ module Cpp #:nodoc:
590
591
  next
591
592
  end
592
593
 
593
- token = tokenize_new_line(@lexer.content) ||
594
- tokenize_extra_token(@lexer.content)
594
+ tok = tokenize_new_line(@lexer.content) ||
595
+ tokenize_extra_token(@lexer.content)
595
596
 
596
- if token
597
+ if tok
597
598
  break
598
599
  else
599
600
  @lexer.content.eat!
600
601
  end
601
602
  end
602
603
 
603
- unless token
604
- token = Token.new(:NEW_LINE, "\n", @lexer.content.location)
605
- @lexer.notify_eof_newline_not_found(token.location)
604
+ unless tok
605
+ tok = Token.new(:NEW_LINE, "\n", @lexer.content.location)
606
+ @lexer.notify_eof_newline_not_found(tok.location)
606
607
  end
607
608
 
608
- if token.type == :NEW_LINE
609
+ if tok.type == :NEW_LINE
609
610
  @lexer.transit(Initial.new(@lexer))
610
611
  end
611
612
 
612
- token
613
+ tok
613
614
  end
614
615
  end
615
616
 
@@ -622,28 +623,28 @@ module Cpp #:nodoc:
622
623
  next
623
624
  end
624
625
 
625
- token = tokenize_header_name(@lexer.content) ||
626
- tokenize_pp_token(@lexer.content) ||
627
- tokenize_new_line(@lexer.content) ||
628
- tokenize_extra_token(@lexer.content)
626
+ tok = tokenize_header_name(@lexer.content) ||
627
+ tokenize_pp_token(@lexer.content) ||
628
+ tokenize_new_line(@lexer.content) ||
629
+ tokenize_extra_token(@lexer.content)
629
630
 
630
- if token
631
+ if tok
631
632
  break
632
633
  else
633
634
  @lexer.content.eat!
634
635
  end
635
636
  end
636
637
 
637
- unless token
638
- token = Token.new(:NEW_LINE, "\n", @lexer.content.location)
639
- @lexer.notify_eof_newline_not_found(token.location)
638
+ unless tok
639
+ tok = Token.new(:NEW_LINE, "\n", @lexer.content.location)
640
+ @lexer.notify_eof_newline_not_found(tok.location)
640
641
  end
641
642
 
642
- if token.type == :NEW_LINE
643
+ if tok.type == :NEW_LINE
643
644
  @lexer.transit(Initial.new(@lexer))
644
645
  end
645
646
 
646
- token
647
+ tok
647
648
  end
648
649
  end
649
650
 
@@ -661,38 +662,38 @@ module Cpp #:nodoc:
661
662
  tokenize_pp_tokens(@lexer.content)
662
663
  end
663
664
 
664
- token = @tokens.shift
665
+ tok = @tokens.shift
665
666
  @lexer.transit(Initial.new(@lexer)) if @tokens.empty?
666
- token
667
+ tok
667
668
  end
668
669
 
669
670
  private
670
- def tokenize_macro_name(content)
671
- until content.empty?
672
- next if discard_heading_comments || scan_escaped_newline(content)
671
+ def tokenize_macro_name(cont)
672
+ until cont.empty?
673
+ next if discard_heading_comments || scan_escaped_newline(cont)
673
674
 
674
- if token = tokenize_identifier(content)
675
- @tokens.push(token)
675
+ if tok = tokenize_identifier(cont)
676
+ @tokens.push(tok)
676
677
  break
677
678
  else
678
- content.eat!
679
+ cont.eat!
679
680
  end
680
681
  end
681
682
 
682
- return unless content.check(/\(/)
683
+ return unless cont.check(/\(/)
683
684
 
684
685
  paren_depth = 0
685
- until content.empty?
686
- next if discard_heading_comments || scan_escaped_newline(content)
686
+ until cont.empty?
687
+ next if discard_heading_comments || scan_escaped_newline(cont)
687
688
 
688
- if token = tokenize_identifier(content)
689
- @tokens.push(token)
689
+ if tok = tokenize_identifier(cont)
690
+ @tokens.push(tok)
690
691
  next
691
692
  end
692
693
 
693
- if token = tokenize_punctuator(content)
694
- @tokens.push(token)
695
- case token.type
694
+ if tok = tokenize_punctuator(cont)
695
+ @tokens.push(tok)
696
+ case tok.type
696
697
  when "("
697
698
  paren_depth += 1
698
699
  when ")"
@@ -702,38 +703,38 @@ module Cpp #:nodoc:
702
703
  next
703
704
  end
704
705
 
705
- if token = tokenize_new_line(content)
706
- @tokens.push(token)
706
+ if tok = tokenize_new_line(cont)
707
+ @tokens.push(tok)
707
708
  break
708
709
  end
709
710
 
710
- content.eat!
711
+ cont.eat!
711
712
  end
712
713
  end
713
714
 
714
- def tokenize_pp_tokens(content)
715
- until content.empty?
716
- next if discard_heading_comments || scan_escaped_newline(content)
715
+ def tokenize_pp_tokens(cont)
716
+ until cont.empty?
717
+ next if discard_heading_comments || scan_escaped_newline(cont)
717
718
 
718
- token = tokenize_pp_token(content) || tokenize_new_line(content)
719
+ tok = tokenize_pp_token(cont) || tokenize_new_line(cont)
719
720
 
720
- if token
721
- @tokens.push(token)
722
- if token.type == :NEW_LINE
721
+ if tok
722
+ @tokens.push(tok)
723
+ if tok.type == :NEW_LINE
723
724
  break
724
725
  end
725
726
  else
726
- location = content.location
727
- if eaten = content.eat! and eaten !~ /\A\s\z/
728
- @lexer.notify_unlexable_char_found(eaten, location)
727
+ loc = cont.location
728
+ if eaten = cont.eat! and eaten !~ /\A\s\z/
729
+ @lexer.notify_unlexable_char_found(eaten, loc)
729
730
  end
730
731
  end
731
732
  end
732
733
 
733
734
  unless @tokens.last && @tokens.last.type == :NEW_LINE
734
- token = Token.new(:NEW_LINE, "\n", content.location)
735
- @lexer.notify_eof_newline_not_found(token.location)
736
- @tokens.push(token)
735
+ tok = Token.new(:NEW_LINE, "\n", cont.location)
736
+ @lexer.notify_eof_newline_not_found(tok.location)
737
+ @tokens.push(tok)
737
738
  end
738
739
  end
739
740
  end
@@ -751,146 +752,151 @@ module Cpp #:nodoc:
751
752
  class InEndasmDirective < InElseDirective; end
752
753
 
753
754
  class StringToPPTokensLexer < StringLexer
755
+ def initialize(str, tab_width = 8)
756
+ super(str)
757
+ @tab_width = tab_width
758
+ end
759
+
754
760
  private
755
- def create_context(str)
756
- context = LexerContext.new(create_content(str))
761
+ def create_lexer_context(str)
762
+ lexer_ctxt = LexerContext.new(create_content(str))
757
763
 
758
- class << context
764
+ class << lexer_ctxt
759
765
  attr_accessor :last_symbol
760
766
  end
761
767
 
762
- context
768
+ lexer_ctxt
763
769
  end
764
770
 
765
771
  def create_content(str)
766
- StringContent.new(str)
772
+ StringContent.new(str, @tab_width)
767
773
  end
768
774
 
769
- def tokenize(context)
770
- token_array = TokenArray.new
771
- until context.content.empty?
772
- next if tokenize_pp_token(context, token_array)
775
+ def tokenize(lexer_ctxt)
776
+ tok_ary = TokenArray.new
777
+ until lexer_ctxt.content.empty?
778
+ next if tokenize_pp_token(lexer_ctxt, tok_ary)
773
779
 
774
- location = context.location
775
- if new_line = context.content.scan(/\n/)
776
- token_array.push(Token.new(:NEW_LINE, new_line, location))
780
+ loc = lexer_ctxt.location
781
+ if new_line = lexer_ctxt.content.scan(/\n/)
782
+ tok_ary.push(Token.new(:NEW_LINE, new_line, loc))
777
783
  break
778
784
  else
779
- context.content.eat!
785
+ lexer_ctxt.content.eat!
780
786
  end
781
787
  end
782
- token_array
788
+ tok_ary
783
789
  end
784
790
 
785
- def tokenize_pp_token(context, token_array)
786
- pp_token = tokenize_keyword(context) ||
787
- tokenize_constant(context) ||
788
- tokenize_string_literal(context) ||
789
- tokenize_null_constant(context) ||
790
- tokenize_identifier(context) ||
791
- tokenize_punctuator(context) ||
792
- tokenize_backslash(context)
791
+ def tokenize_pp_token(lexer_ctxt, tok_ary)
792
+ pp_tok = tokenize_keyword(lexer_ctxt) ||
793
+ tokenize_constant(lexer_ctxt) ||
794
+ tokenize_string_literal(lexer_ctxt) ||
795
+ tokenize_null_constant(lexer_ctxt) ||
796
+ tokenize_identifier(lexer_ctxt) ||
797
+ tokenize_punctuator(lexer_ctxt) ||
798
+ tokenize_backslash(lexer_ctxt)
793
799
 
794
- if pp_token
795
- token_array.push(pp_token)
800
+ if pp_tok
801
+ tok_ary.push(pp_tok)
796
802
  return true
797
803
  end
798
804
 
799
805
  false
800
806
  end
801
807
 
802
- def tokenize_keyword(context)
803
- location = context.location
808
+ def tokenize_keyword(lexer_ctxt)
809
+ loc = lexer_ctxt.location
804
810
 
805
- keyword = Language::C.scan_keyword(context.content) ||
806
- Language::Cpp.scan_keyword(context.content)
811
+ keyword = Language::C.scan_keyword(lexer_ctxt.content) ||
812
+ Language::Cpp.scan_keyword(lexer_ctxt.content)
807
813
 
808
814
  if keyword
809
- context.last_symbol = :KEYWORD
810
- Token.new(:PP_TOKEN, keyword, location, Language::C::KEYWORDS[keyword])
815
+ lexer_ctxt.last_symbol = :KEYWORD
816
+ Token.new(:PP_TOKEN, keyword, loc, Language::C::KEYWORDS[keyword])
811
817
  else
812
818
  nil
813
819
  end
814
820
  end
815
821
 
816
- def tokenize_constant(context)
817
- location = context.location
822
+ def tokenize_constant(lexer_ctxt)
823
+ loc = lexer_ctxt.location
818
824
 
819
825
  # NOTE: For extended bit-access operators.
820
- return nil if context.last_symbol == :IDENTIFIER
826
+ return nil if lexer_ctxt.last_symbol == :IDENTIFIER
821
827
 
822
- constant = Language::C.scan_char_constant(context.content) ||
823
- Language::C.scan_floating_constant(context.content) ||
824
- Language::C.scan_integer_constant(context.content)
828
+ constant = Language::C.scan_char_constant(lexer_ctxt.content) ||
829
+ Language::C.scan_floating_constant(lexer_ctxt.content) ||
830
+ Language::C.scan_integer_constant(lexer_ctxt.content)
825
831
 
826
832
  if constant
827
- context.last_symbol = :CONSTANT
828
- return Token.new(:PP_TOKEN, constant, location, :CONSTANT)
833
+ lexer_ctxt.last_symbol = :CONSTANT
834
+ return Token.new(:PP_TOKEN, constant, loc, :CONSTANT)
829
835
  end
830
836
 
831
837
  nil
832
838
  end
833
839
 
834
- def tokenize_string_literal(context)
835
- location = context.location
840
+ def tokenize_string_literal(lexer_ctxt)
841
+ loc = lexer_ctxt.location
836
842
 
837
- string_literal = Language::C.scan_string_literal(context.content)
843
+ string_literal = Language::C.scan_string_literal(lexer_ctxt.content)
838
844
 
839
845
  if string_literal
840
- context.last_symbol = :STRING_LITERAL
841
- return Token.new(:PP_TOKEN, string_literal, location, :STRING_LITERAL)
846
+ lexer_ctxt.last_symbol = :STRING_LITERAL
847
+ return Token.new(:PP_TOKEN, string_literal, loc, :STRING_LITERAL)
842
848
  end
843
849
 
844
850
  nil
845
851
  end
846
852
 
847
- def tokenize_null_constant(context)
848
- location = context.location
853
+ def tokenize_null_constant(lexer_ctxt)
854
+ loc = lexer_ctxt.location
849
855
 
850
- null_constant = Language::C.scan_null_constant(context.content)
856
+ null_constant = Language::C.scan_null_constant(lexer_ctxt.content)
851
857
 
852
858
  if null_constant
853
- context.last_symbol = :NULL
854
- return Token.new(:PP_TOKEN, null_constant, location, :NULL)
859
+ lexer_ctxt.last_symbol = :NULL
860
+ return Token.new(:PP_TOKEN, null_constant, loc, :NULL)
855
861
  end
856
862
 
857
863
  nil
858
864
  end
859
865
 
860
- def tokenize_identifier(context)
861
- location = context.location
866
+ def tokenize_identifier(lexer_ctxt)
867
+ loc = lexer_ctxt.location
862
868
 
863
- identifier = Language::C.scan_identifier(context.content)
869
+ identifier = Language::C.scan_identifier(lexer_ctxt.content)
864
870
 
865
871
  if identifier
866
- context.last_symbol = :IDENTIFIER
867
- return Token.new(:PP_TOKEN, identifier, location, :IDENTIFIER)
872
+ lexer_ctxt.last_symbol = :IDENTIFIER
873
+ return Token.new(:PP_TOKEN, identifier, loc, :IDENTIFIER)
868
874
  end
869
875
 
870
876
  nil
871
877
  end
872
878
 
873
- def tokenize_punctuator(context)
874
- location = context.location
879
+ def tokenize_punctuator(lexer_ctxt)
880
+ loc = lexer_ctxt.location
875
881
 
876
- punctuator = Language::Cpp.scan_punctuator(context.content)
882
+ punctuator = Language::Cpp.scan_punctuator(lexer_ctxt.content)
877
883
 
878
884
  if punctuator
879
- context.last_symbol = :PUNCTUATOR
880
- return Token.new(:PP_TOKEN, punctuator, location, punctuator)
885
+ lexer_ctxt.last_symbol = :PUNCTUATOR
886
+ return Token.new(:PP_TOKEN, punctuator, loc, punctuator)
881
887
  end
882
888
 
883
889
  nil
884
890
  end
885
891
 
886
- def tokenize_backslash(context)
887
- location = context.location
892
+ def tokenize_backslash(lexer_ctxt)
893
+ loc = lexer_ctxt.location
888
894
 
889
- backslash = context.content.scan(/\\/)
895
+ backslash = lexer_ctxt.content.scan(/\\/)
890
896
 
891
897
  if backslash
892
- context.last_symbol = :BACKSLASH
893
- return Token.new(:PP_TOKEN, backslash, location, backslash)
898
+ lexer_ctxt.last_symbol = :BACKSLASH
899
+ return Token.new(:PP_TOKEN, backslash, loc, backslash)
894
900
  end
895
901
 
896
902
  nil
@@ -898,17 +904,14 @@ module Cpp #:nodoc:
898
904
  end
899
905
 
900
906
  class TextLineToPPTokensLexer < StringToPPTokensLexer
901
- def initialize(text_line)
902
- super(text_line.token.value)
907
+ def initialize(text_line, tab_width)
908
+ super(text_line.token.value, tab_width)
903
909
  @text_line = text_line
904
910
  end
905
911
 
906
912
  private
907
913
  def create_content(str)
908
- StringContent.new(str,
909
- @text_line.location.fpath,
910
- @text_line.location.line_no,
911
- @text_line.location.column_no)
914
+ StringContent.new(str, @tab_width, *@text_line.location.to_a)
912
915
  end
913
916
  end
914
917