adlint 2.6.14 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (401) hide show
  1. data/AUTHORS +1 -3
  2. data/ChangeLog +511 -0
  3. data/INSTALL +1 -1
  4. data/MANIFEST +57 -37
  5. data/NEWS +36 -7
  6. data/README +2 -2
  7. data/Rakefile +6 -6
  8. data/TODO +1 -1
  9. data/bin/adlint +25 -16
  10. data/bin/adlint_chk +22 -12
  11. data/bin/adlint_cma +17 -12
  12. data/bin/adlint_sma +22 -12
  13. data/bin/adlintize +98 -17
  14. data/etc/conf.d/fallback/cinit.erb +1 -1
  15. data/etc/conf.d/fallback/traits.erb +37 -37
  16. data/etc/conf.d/i686-cygwin/cinit-gcc_4.3.4.erb +1 -1
  17. data/etc/conf.d/i686-cygwin/traits-gcc_4.3.4.erb +41 -41
  18. data/etc/conf.d/i686-devkit/cinit-gcc_4.5.2.erb +1 -1
  19. data/etc/conf.d/i686-devkit/traits-gcc_4.5.2.erb +40 -40
  20. data/etc/conf.d/i686-linux/cinit-gcc_4.5.1.erb +1 -1
  21. data/etc/conf.d/i686-linux/traits-gcc_4.5.1.erb +40 -40
  22. data/etc/conf.d/i686-mingw/cinit-gcc_4.6.1.erb +1 -1
  23. data/etc/conf.d/i686-mingw/traits-gcc_4.6.1.erb +40 -40
  24. data/etc/conf.d/noarch/GNUmakefile.erb +1 -1
  25. data/etc/conf.d/noarch/adlint_all_bat.erb +1 -1
  26. data/etc/conf.d/noarch/adlint_all_sh.erb +1 -1
  27. data/etc/conf.d/noarch/pinit.erb +1 -1
  28. data/etc/conf.d/x86_64-ubuntu_12.04/cinit-gcc_4.6.3.erb +1 -1
  29. data/etc/conf.d/x86_64-ubuntu_12.04/traits-gcc_4.6.3.erb +42 -42
  30. data/etc/mesg.d/c_builtin/en_US/messages.yml +33 -33
  31. data/etc/mesg.d/c_builtin/ja_JP/messages.yml +5 -5
  32. data/etc/mesg.d/core/en_US/messages.yml +2 -2
  33. data/etc/mesg.d/core/ja_JP/messages.yml +2 -2
  34. data/features/code_check/W0018.feature +197 -0
  35. data/features/code_check/W0019.feature +79 -0
  36. data/features/code_check/W0021.feature +81 -0
  37. data/features/code_check/W0023.feature +203 -0
  38. data/features/code_check/W0024.feature +226 -0
  39. data/features/code_check/W0025.feature +5 -0
  40. data/features/code_check/W0088.feature +2 -2
  41. data/features/code_check/W0109.feature +2 -2
  42. data/features/code_check/W0477.feature +0 -3
  43. data/features/code_check/W0478.feature +0 -1
  44. data/features/code_check/W0582.feature +3 -3
  45. data/features/code_check/W0583.feature +4 -7
  46. data/features/code_check/W0646.feature +0 -1
  47. data/features/code_check/W0695.feature +0 -1
  48. data/features/code_check/W0705.feature +8 -0
  49. data/features/code_check/W0723.feature +0 -1
  50. data/features/code_check/W0745.feature +1 -0
  51. data/features/code_check/W0781.feature +1 -0
  52. data/features/code_check/W1057.feature +141 -0
  53. data/features/code_check/W1058.feature +93 -0
  54. data/features/code_check/W1059.feature +86 -0
  55. data/features/code_check/W1060.feature +77 -0
  56. data/features/code_check/W1061.feature +143 -0
  57. data/features/code_check/W1062.feature +162 -0
  58. data/features/code_check/W1063.feature +123 -0
  59. data/features/code_check/W1064.feature +83 -0
  60. data/features/code_check/W1065.feature +82 -0
  61. data/features/code_check/W9003.feature +2 -0
  62. data/features/step_definitions/code_check_steps.rb +1 -0
  63. data/features/support/env.rb +16 -13
  64. data/lib/adlint.rb +7 -4
  65. data/lib/adlint/analyzer.rb +131 -157
  66. data/lib/adlint/annot.rb +149 -0
  67. data/lib/adlint/cc1.rb +57 -0
  68. data/lib/adlint/{c → cc1}/branch.rb +74 -62
  69. data/lib/adlint/{c → cc1}/builtin.rb +21 -21
  70. data/lib/adlint/{c → cc1}/const.rb +119 -117
  71. data/lib/adlint/{c → cc1}/conv.rb +76 -78
  72. data/lib/adlint/{c → cc1}/ctrlexpr.rb +69 -86
  73. data/lib/adlint/cc1/domain.rb +8103 -0
  74. data/lib/adlint/{c → cc1}/enum.rb +3 -3
  75. data/lib/adlint/{c → cc1}/environ.rb +21 -21
  76. data/lib/adlint/{c → cc1}/expr.rb +232 -218
  77. data/lib/adlint/{c → cc1}/format.rb +305 -342
  78. data/lib/adlint/{c → cc1}/interp.rb +269 -220
  79. data/lib/adlint/cc1/lexer.rb +246 -0
  80. data/lib/adlint/{c → cc1}/mediator.rb +78 -84
  81. data/lib/adlint/{c → cc1}/object.rb +261 -264
  82. data/lib/adlint/{c → cc1}/operator.rb +7 -7
  83. data/lib/adlint/{c → cc1}/option.rb +4 -3
  84. data/lib/adlint/{c → cc1}/parser.rb +274 -506
  85. data/lib/adlint/{c → cc1}/parser.y +69 -301
  86. data/lib/adlint/cc1/phase.rb +138 -0
  87. data/lib/adlint/{c → cc1}/resolver.rb +66 -78
  88. data/lib/adlint/{c → cc1}/scanner.rb +57 -49
  89. data/lib/adlint/{c → cc1}/scope.rb +3 -3
  90. data/lib/adlint/{c → cc1}/seqp.rb +13 -5
  91. data/lib/adlint/{c → cc1}/syntax.rb +819 -1122
  92. data/lib/adlint/{c → cc1}/type.rb +1498 -1479
  93. data/lib/adlint/{c → cc1}/util.rb +20 -12
  94. data/lib/adlint/{c → cc1}/value.rb +699 -642
  95. data/lib/adlint/code.rb +163 -164
  96. data/lib/adlint/cpp.rb +2 -2
  97. data/lib/adlint/cpp/asm.rb +13 -14
  98. data/lib/adlint/cpp/constexpr.rb +42 -38
  99. data/lib/adlint/cpp/constexpr.y +44 -40
  100. data/lib/adlint/cpp/eval.rb +435 -435
  101. data/lib/adlint/cpp/lexer.rb +343 -340
  102. data/lib/adlint/cpp/macro.rb +188 -190
  103. data/lib/adlint/cpp/phase.rb +66 -45
  104. data/lib/adlint/cpp/scanner.rb +14 -17
  105. data/lib/adlint/cpp/source.rb +49 -55
  106. data/lib/adlint/cpp/subst.rb +65 -65
  107. data/lib/adlint/cpp/syntax.rb +155 -275
  108. data/lib/adlint/cpp/util.rb +22 -19
  109. data/lib/adlint/driver.rb +86 -93
  110. data/lib/adlint/error.rb +33 -52
  111. data/lib/adlint/exam.rb +158 -24
  112. data/lib/adlint/exam/c_builtin.rb +7 -7
  113. data/lib/adlint/exam/c_builtin/cc1_check.rb +20522 -0
  114. data/lib/adlint/exam/c_builtin/cc1_check_shima.rb +957 -0
  115. data/lib/adlint/exam/c_builtin/cc1_code.rb +459 -0
  116. data/lib/adlint/exam/c_builtin/cc1_metric.rb +794 -0
  117. data/lib/adlint/exam/c_builtin/cpp_check.rb +486 -441
  118. data/lib/adlint/exam/c_builtin/cpp_check_shima.rb +36 -39
  119. data/lib/adlint/exam/c_builtin/cpp_code.rb +63 -65
  120. data/lib/adlint/exam/c_builtin/ld_check.rb +136 -129
  121. data/lib/adlint/exam/c_builtin/ld_metric.rb +11 -11
  122. data/lib/adlint/lang.rb +25 -25
  123. data/lib/adlint/ld.rb +2 -2
  124. data/lib/adlint/ld/object.rb +220 -188
  125. data/lib/adlint/ld/phase.rb +94 -63
  126. data/lib/adlint/ld/typedef.rb +22 -11
  127. data/lib/adlint/ld/util.rb +43 -35
  128. data/lib/adlint/lexer.rb +59 -56
  129. data/lib/adlint/location.rb +140 -0
  130. data/lib/adlint/memo.rb +157 -0
  131. data/lib/adlint/message.rb +207 -156
  132. data/lib/adlint/metric.rb +139 -217
  133. data/lib/adlint/monitor.rb +45 -43
  134. data/lib/adlint/phase.rb +56 -29
  135. data/lib/adlint/prelude.rb +66 -54
  136. data/lib/adlint/report.rb +253 -332
  137. data/lib/adlint/source.rb +26 -27
  138. data/lib/adlint/supp.rb +131 -0
  139. data/lib/adlint/symbol.rb +14 -16
  140. data/lib/adlint/token.rb +19 -91
  141. data/lib/adlint/traits.rb +242 -226
  142. data/lib/adlint/util.rb +116 -205
  143. data/lib/adlint/version.rb +8 -8
  144. data/share/HEADER +2 -2
  145. data/share/doc/developers_guide_ja.html +148 -19
  146. data/share/doc/developers_guide_ja.texi +141 -11
  147. data/share/doc/samples/GNUmakefile +1 -1
  148. data/share/doc/samples/adlint_traits.yml +45 -36
  149. data/share/doc/users_guide_en.html +1321 -1252
  150. data/share/doc/users_guide_en.texi +475 -408
  151. data/share/doc/users_guide_ja.html +1932 -1878
  152. data/share/doc/users_guide_ja.texi +324 -273
  153. data/share/sample/bison-2.5/adlint/GNUmakefile +5 -1
  154. data/share/sample/bison-2.5/adlint/adlint_traits.yml +38 -38
  155. data/share/sample/bison-2.5/adlint/lib/GNUmakefile +1 -1
  156. data/share/sample/bison-2.5/adlint/lib/adlint_cinit.h +1 -1
  157. data/share/sample/bison-2.5/adlint/lib/adlint_pinit.h +1 -1
  158. data/share/sample/bison-2.5/adlint/lib/adlint_traits.yml +50 -42
  159. data/share/sample/bison-2.5/adlint/src/GNUmakefile +1 -1
  160. data/share/sample/bison-2.5/adlint/src/adlint_cinit.h +1 -1
  161. data/share/sample/bison-2.5/adlint/src/adlint_pinit.h +1 -1
  162. data/share/sample/bison-2.5/adlint/src/adlint_traits.yml +50 -42
  163. data/share/sample/ctags-5.8/adlint/GNUmakefile +1 -1
  164. data/share/sample/ctags-5.8/adlint/adlint_cinit.h +1 -1
  165. data/share/sample/ctags-5.8/adlint/adlint_pinit.h +1 -1
  166. data/share/sample/ctags-5.8/adlint/adlint_traits.yml +50 -42
  167. data/share/sample/flex-2.5.35/adlint/GNUmakefile +1 -1
  168. data/share/sample/flex-2.5.35/adlint/adlint_cinit.h +1 -1
  169. data/share/sample/flex-2.5.35/adlint/adlint_pinit.h +1 -1
  170. data/share/sample/flex-2.5.35/adlint/adlint_traits.yml +50 -42
  171. data/share/sample/ruby-1.9.3-p0/adlint/GNUmakefile +1 -1
  172. data/share/sample/ruby-1.9.3-p0/adlint/adlint_traits.yml +46 -38
  173. data/share/sample/ruby-1.9.3-p0/adlint/core/GNUmakefile +1 -1
  174. data/share/sample/ruby-1.9.3-p0/adlint/core/adlint_cinit.h +1 -1
  175. data/share/sample/ruby-1.9.3-p0/adlint/core/adlint_pinit.h +1 -1
  176. data/share/sample/ruby-1.9.3-p0/adlint/core/adlint_traits.yml +50 -42
  177. data/share/sample/ruby-1.9.3-p0/adlint/enc-trans/GNUmakefile +1 -1
  178. data/share/sample/ruby-1.9.3-p0/adlint/enc-trans/adlint_cinit.h +1 -1
  179. data/share/sample/ruby-1.9.3-p0/adlint/enc-trans/adlint_pinit.h +1 -1
  180. data/share/sample/ruby-1.9.3-p0/adlint/enc-trans/adlint_traits.yml +50 -42
  181. data/share/sample/ruby-1.9.3-p0/adlint/enc/GNUmakefile +1 -1
  182. data/share/sample/ruby-1.9.3-p0/adlint/enc/adlint_cinit.h +1 -1
  183. data/share/sample/ruby-1.9.3-p0/adlint/enc/adlint_pinit.h +1 -1
  184. data/share/sample/ruby-1.9.3-p0/adlint/enc/adlint_traits.yml +50 -42
  185. data/share/sample/ruby-1.9.3-p0/adlint/ext-bigdecimal/GNUmakefile +1 -1
  186. data/share/sample/ruby-1.9.3-p0/adlint/ext-bigdecimal/adlint_cinit.h +1 -1
  187. data/share/sample/ruby-1.9.3-p0/adlint/ext-bigdecimal/adlint_pinit.h +1 -1
  188. data/share/sample/ruby-1.9.3-p0/adlint/ext-bigdecimal/adlint_traits.yml +50 -42
  189. data/share/sample/ruby-1.9.3-p0/adlint/ext-continuation/GNUmakefile +1 -1
  190. data/share/sample/ruby-1.9.3-p0/adlint/ext-continuation/adlint_cinit.h +1 -1
  191. data/share/sample/ruby-1.9.3-p0/adlint/ext-continuation/adlint_pinit.h +1 -1
  192. data/share/sample/ruby-1.9.3-p0/adlint/ext-continuation/adlint_traits.yml +50 -42
  193. data/share/sample/ruby-1.9.3-p0/adlint/ext-coverage/GNUmakefile +1 -1
  194. data/share/sample/ruby-1.9.3-p0/adlint/ext-coverage/adlint_cinit.h +1 -1
  195. data/share/sample/ruby-1.9.3-p0/adlint/ext-coverage/adlint_pinit.h +1 -1
  196. data/share/sample/ruby-1.9.3-p0/adlint/ext-coverage/adlint_traits.yml +50 -42
  197. data/share/sample/ruby-1.9.3-p0/adlint/ext-curses/GNUmakefile +1 -1
  198. data/share/sample/ruby-1.9.3-p0/adlint/ext-curses/adlint_cinit.h +1 -1
  199. data/share/sample/ruby-1.9.3-p0/adlint/ext-curses/adlint_pinit.h +1 -1
  200. data/share/sample/ruby-1.9.3-p0/adlint/ext-curses/adlint_traits.yml +50 -42
  201. data/share/sample/ruby-1.9.3-p0/adlint/ext-date/GNUmakefile +1 -1
  202. data/share/sample/ruby-1.9.3-p0/adlint/ext-date/adlint_cinit.h +1 -1
  203. data/share/sample/ruby-1.9.3-p0/adlint/ext-date/adlint_pinit.h +1 -1
  204. data/share/sample/ruby-1.9.3-p0/adlint/ext-date/adlint_traits.yml +50 -42
  205. data/share/sample/ruby-1.9.3-p0/adlint/ext-dbm/GNUmakefile +1 -1
  206. data/share/sample/ruby-1.9.3-p0/adlint/ext-dbm/adlint_cinit.h +1 -1
  207. data/share/sample/ruby-1.9.3-p0/adlint/ext-dbm/adlint_pinit.h +1 -1
  208. data/share/sample/ruby-1.9.3-p0/adlint/ext-dbm/adlint_traits.yml +50 -42
  209. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-bubblebabble/GNUmakefile +1 -1
  210. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-bubblebabble/adlint_cinit.h +1 -1
  211. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-bubblebabble/adlint_pinit.h +1 -1
  212. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-bubblebabble/adlint_traits.yml +50 -42
  213. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-md5/GNUmakefile +1 -1
  214. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-md5/adlint_cinit.h +1 -1
  215. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-md5/adlint_pinit.h +1 -1
  216. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-md5/adlint_traits.yml +50 -42
  217. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-rmd160/GNUmakefile +1 -1
  218. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-rmd160/adlint_cinit.h +1 -1
  219. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-rmd160/adlint_pinit.h +1 -1
  220. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-rmd160/adlint_traits.yml +50 -42
  221. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha1/GNUmakefile +1 -1
  222. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha1/adlint_cinit.h +1 -1
  223. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha1/adlint_pinit.h +1 -1
  224. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha1/adlint_traits.yml +50 -42
  225. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha2/GNUmakefile +1 -1
  226. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha2/adlint_cinit.h +1 -1
  227. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha2/adlint_pinit.h +1 -1
  228. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha2/adlint_traits.yml +50 -42
  229. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest/GNUmakefile +1 -1
  230. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest/adlint_cinit.h +1 -1
  231. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest/adlint_pinit.h +1 -1
  232. data/share/sample/ruby-1.9.3-p0/adlint/ext-digest/adlint_traits.yml +50 -42
  233. data/share/sample/ruby-1.9.3-p0/adlint/ext-dl-callback/GNUmakefile +1 -1
  234. data/share/sample/ruby-1.9.3-p0/adlint/ext-dl-callback/adlint_cinit.h +1 -1
  235. data/share/sample/ruby-1.9.3-p0/adlint/ext-dl-callback/adlint_pinit.h +1 -1
  236. data/share/sample/ruby-1.9.3-p0/adlint/ext-dl-callback/adlint_traits.yml +50 -42
  237. data/share/sample/ruby-1.9.3-p0/adlint/ext-dl/GNUmakefile +1 -1
  238. data/share/sample/ruby-1.9.3-p0/adlint/ext-dl/adlint_cinit.h +1 -1
  239. data/share/sample/ruby-1.9.3-p0/adlint/ext-dl/adlint_pinit.h +1 -1
  240. data/share/sample/ruby-1.9.3-p0/adlint/ext-dl/adlint_traits.yml +50 -42
  241. data/share/sample/ruby-1.9.3-p0/adlint/ext-etc/GNUmakefile +1 -1
  242. data/share/sample/ruby-1.9.3-p0/adlint/ext-etc/adlint_cinit.h +1 -1
  243. data/share/sample/ruby-1.9.3-p0/adlint/ext-etc/adlint_pinit.h +1 -1
  244. data/share/sample/ruby-1.9.3-p0/adlint/ext-etc/adlint_traits.yml +50 -42
  245. data/share/sample/ruby-1.9.3-p0/adlint/ext-fcntl/GNUmakefile +1 -1
  246. data/share/sample/ruby-1.9.3-p0/adlint/ext-fcntl/adlint_cinit.h +1 -1
  247. data/share/sample/ruby-1.9.3-p0/adlint/ext-fcntl/adlint_pinit.h +1 -1
  248. data/share/sample/ruby-1.9.3-p0/adlint/ext-fcntl/adlint_traits.yml +50 -42
  249. data/share/sample/ruby-1.9.3-p0/adlint/ext-fiber/GNUmakefile +1 -1
  250. data/share/sample/ruby-1.9.3-p0/adlint/ext-fiber/adlint_cinit.h +1 -1
  251. data/share/sample/ruby-1.9.3-p0/adlint/ext-fiber/adlint_pinit.h +1 -1
  252. data/share/sample/ruby-1.9.3-p0/adlint/ext-fiber/adlint_traits.yml +50 -42
  253. data/share/sample/ruby-1.9.3-p0/adlint/ext-fiddle/GNUmakefile +1 -1
  254. data/share/sample/ruby-1.9.3-p0/adlint/ext-fiddle/adlint_cinit.h +1 -1
  255. data/share/sample/ruby-1.9.3-p0/adlint/ext-fiddle/adlint_pinit.h +1 -1
  256. data/share/sample/ruby-1.9.3-p0/adlint/ext-fiddle/adlint_traits.yml +50 -42
  257. data/share/sample/ruby-1.9.3-p0/adlint/ext-gdbm/GNUmakefile +1 -1
  258. data/share/sample/ruby-1.9.3-p0/adlint/ext-gdbm/adlint_cinit.h +1 -1
  259. data/share/sample/ruby-1.9.3-p0/adlint/ext-gdbm/adlint_pinit.h +1 -1
  260. data/share/sample/ruby-1.9.3-p0/adlint/ext-gdbm/adlint_traits.yml +50 -42
  261. data/share/sample/ruby-1.9.3-p0/adlint/ext-iconv/GNUmakefile +1 -1
  262. data/share/sample/ruby-1.9.3-p0/adlint/ext-iconv/adlint_cinit.h +1 -1
  263. data/share/sample/ruby-1.9.3-p0/adlint/ext-iconv/adlint_pinit.h +1 -1
  264. data/share/sample/ruby-1.9.3-p0/adlint/ext-iconv/adlint_traits.yml +50 -42
  265. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-console/GNUmakefile +1 -1
  266. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-console/adlint_cinit.h +1 -1
  267. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-console/adlint_pinit.h +1 -1
  268. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-console/adlint_traits.yml +50 -42
  269. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-nonblock/GNUmakefile +1 -1
  270. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-nonblock/adlint_cinit.h +1 -1
  271. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-nonblock/adlint_pinit.h +1 -1
  272. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-nonblock/adlint_traits.yml +50 -42
  273. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-wait/GNUmakefile +1 -1
  274. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-wait/adlint_cinit.h +1 -1
  275. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-wait/adlint_pinit.h +1 -1
  276. data/share/sample/ruby-1.9.3-p0/adlint/ext-io-wait/adlint_traits.yml +50 -42
  277. data/share/sample/ruby-1.9.3-p0/adlint/ext-json-generator/GNUmakefile +1 -1
  278. data/share/sample/ruby-1.9.3-p0/adlint/ext-json-generator/adlint_cinit.h +1 -1
  279. data/share/sample/ruby-1.9.3-p0/adlint/ext-json-generator/adlint_pinit.h +1 -1
  280. data/share/sample/ruby-1.9.3-p0/adlint/ext-json-generator/adlint_traits.yml +50 -42
  281. data/share/sample/ruby-1.9.3-p0/adlint/ext-json-parser/GNUmakefile +1 -1
  282. data/share/sample/ruby-1.9.3-p0/adlint/ext-json-parser/adlint_cinit.h +1 -1
  283. data/share/sample/ruby-1.9.3-p0/adlint/ext-json-parser/adlint_pinit.h +1 -1
  284. data/share/sample/ruby-1.9.3-p0/adlint/ext-json-parser/adlint_traits.yml +50 -42
  285. data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-complex/GNUmakefile +1 -1
  286. data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-complex/adlint_cinit.h +1 -1
  287. data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-complex/adlint_pinit.h +1 -1
  288. data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-complex/adlint_traits.yml +50 -42
  289. data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-rational/GNUmakefile +1 -1
  290. data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-rational/adlint_cinit.h +1 -1
  291. data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-rational/adlint_pinit.h +1 -1
  292. data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-rational/adlint_traits.yml +50 -42
  293. data/share/sample/ruby-1.9.3-p0/adlint/ext-nkf/GNUmakefile +1 -1
  294. data/share/sample/ruby-1.9.3-p0/adlint/ext-nkf/adlint_cinit.h +1 -1
  295. data/share/sample/ruby-1.9.3-p0/adlint/ext-nkf/adlint_pinit.h +1 -1
  296. data/share/sample/ruby-1.9.3-p0/adlint/ext-nkf/adlint_traits.yml +50 -42
  297. data/share/sample/ruby-1.9.3-p0/adlint/ext-openssl/GNUmakefile +1 -1
  298. data/share/sample/ruby-1.9.3-p0/adlint/ext-openssl/adlint_cinit.h +1 -1
  299. data/share/sample/ruby-1.9.3-p0/adlint/ext-openssl/adlint_pinit.h +1 -1
  300. data/share/sample/ruby-1.9.3-p0/adlint/ext-openssl/adlint_traits.yml +50 -42
  301. data/share/sample/ruby-1.9.3-p0/adlint/ext-pathname/GNUmakefile +1 -1
  302. data/share/sample/ruby-1.9.3-p0/adlint/ext-pathname/adlint_cinit.h +1 -1
  303. data/share/sample/ruby-1.9.3-p0/adlint/ext-pathname/adlint_pinit.h +1 -1
  304. data/share/sample/ruby-1.9.3-p0/adlint/ext-pathname/adlint_traits.yml +50 -42
  305. data/share/sample/ruby-1.9.3-p0/adlint/ext-psych/GNUmakefile +1 -1
  306. data/share/sample/ruby-1.9.3-p0/adlint/ext-psych/adlint_cinit.h +1 -1
  307. data/share/sample/ruby-1.9.3-p0/adlint/ext-psych/adlint_pinit.h +1 -1
  308. data/share/sample/ruby-1.9.3-p0/adlint/ext-psych/adlint_traits.yml +50 -42
  309. data/share/sample/ruby-1.9.3-p0/adlint/ext-pty/GNUmakefile +1 -1
  310. data/share/sample/ruby-1.9.3-p0/adlint/ext-pty/adlint_cinit.h +1 -1
  311. data/share/sample/ruby-1.9.3-p0/adlint/ext-pty/adlint_pinit.h +1 -1
  312. data/share/sample/ruby-1.9.3-p0/adlint/ext-pty/adlint_traits.yml +50 -42
  313. data/share/sample/ruby-1.9.3-p0/adlint/ext-racc-cparse/GNUmakefile +1 -1
  314. data/share/sample/ruby-1.9.3-p0/adlint/ext-racc-cparse/adlint_cinit.h +1 -1
  315. data/share/sample/ruby-1.9.3-p0/adlint/ext-racc-cparse/adlint_pinit.h +1 -1
  316. data/share/sample/ruby-1.9.3-p0/adlint/ext-racc-cparse/adlint_traits.yml +50 -42
  317. data/share/sample/ruby-1.9.3-p0/adlint/ext-readline/GNUmakefile +1 -1
  318. data/share/sample/ruby-1.9.3-p0/adlint/ext-readline/adlint_cinit.h +1 -1
  319. data/share/sample/ruby-1.9.3-p0/adlint/ext-readline/adlint_pinit.h +1 -1
  320. data/share/sample/ruby-1.9.3-p0/adlint/ext-readline/adlint_traits.yml +50 -42
  321. data/share/sample/ruby-1.9.3-p0/adlint/ext-ripper/GNUmakefile +1 -1
  322. data/share/sample/ruby-1.9.3-p0/adlint/ext-ripper/adlint_cinit.h +1 -1
  323. data/share/sample/ruby-1.9.3-p0/adlint/ext-ripper/adlint_pinit.h +1 -1
  324. data/share/sample/ruby-1.9.3-p0/adlint/ext-ripper/adlint_traits.yml +50 -42
  325. data/share/sample/ruby-1.9.3-p0/adlint/ext-sdbm/GNUmakefile +1 -1
  326. data/share/sample/ruby-1.9.3-p0/adlint/ext-sdbm/adlint_cinit.h +1 -1
  327. data/share/sample/ruby-1.9.3-p0/adlint/ext-sdbm/adlint_pinit.h +1 -1
  328. data/share/sample/ruby-1.9.3-p0/adlint/ext-sdbm/adlint_traits.yml +50 -42
  329. data/share/sample/ruby-1.9.3-p0/adlint/ext-socket/GNUmakefile +1 -1
  330. data/share/sample/ruby-1.9.3-p0/adlint/ext-socket/adlint_cinit.h +1 -1
  331. data/share/sample/ruby-1.9.3-p0/adlint/ext-socket/adlint_pinit.h +1 -1
  332. data/share/sample/ruby-1.9.3-p0/adlint/ext-socket/adlint_traits.yml +50 -42
  333. data/share/sample/ruby-1.9.3-p0/adlint/ext-stringio/GNUmakefile +1 -1
  334. data/share/sample/ruby-1.9.3-p0/adlint/ext-stringio/adlint_cinit.h +1 -1
  335. data/share/sample/ruby-1.9.3-p0/adlint/ext-stringio/adlint_pinit.h +1 -1
  336. data/share/sample/ruby-1.9.3-p0/adlint/ext-stringio/adlint_traits.yml +50 -42
  337. data/share/sample/ruby-1.9.3-p0/adlint/ext-strscan/GNUmakefile +1 -1
  338. data/share/sample/ruby-1.9.3-p0/adlint/ext-strscan/adlint_cinit.h +1 -1
  339. data/share/sample/ruby-1.9.3-p0/adlint/ext-strscan/adlint_pinit.h +1 -1
  340. data/share/sample/ruby-1.9.3-p0/adlint/ext-strscan/adlint_traits.yml +50 -42
  341. data/share/sample/ruby-1.9.3-p0/adlint/ext-syck/GNUmakefile +1 -1
  342. data/share/sample/ruby-1.9.3-p0/adlint/ext-syck/adlint_cinit.h +1 -1
  343. data/share/sample/ruby-1.9.3-p0/adlint/ext-syck/adlint_pinit.h +1 -1
  344. data/share/sample/ruby-1.9.3-p0/adlint/ext-syck/adlint_traits.yml +50 -42
  345. data/share/sample/ruby-1.9.3-p0/adlint/ext-syslog/GNUmakefile +1 -1
  346. data/share/sample/ruby-1.9.3-p0/adlint/ext-syslog/adlint_cinit.h +1 -1
  347. data/share/sample/ruby-1.9.3-p0/adlint/ext-syslog/adlint_pinit.h +1 -1
  348. data/share/sample/ruby-1.9.3-p0/adlint/ext-syslog/adlint_traits.yml +50 -42
  349. data/share/sample/ruby-1.9.3-p0/adlint/ext-zlib/GNUmakefile +1 -1
  350. data/share/sample/ruby-1.9.3-p0/adlint/ext-zlib/adlint_cinit.h +1 -1
  351. data/share/sample/ruby-1.9.3-p0/adlint/ext-zlib/adlint_pinit.h +1 -1
  352. data/share/sample/ruby-1.9.3-p0/adlint/ext-zlib/adlint_traits.yml +50 -42
  353. data/share/sample/screen-4.0.3/adlint/GNUmakefile +1 -1
  354. data/share/sample/screen-4.0.3/adlint/adlint_cinit.h +1 -1
  355. data/share/sample/screen-4.0.3/adlint/adlint_pinit.h +1 -1
  356. data/share/sample/screen-4.0.3/adlint/adlint_traits.yml +50 -42
  357. data/share/sample/vim-7.3/adlint/vim/GNUmakefile +1 -1
  358. data/share/sample/vim-7.3/adlint/vim/adlint_cinit.h +1 -1
  359. data/share/sample/vim-7.3/adlint/vim/adlint_pinit.h +1 -1
  360. data/share/sample/vim-7.3/adlint/vim/adlint_traits.yml +50 -42
  361. data/share/sample/vim-7.3/adlint/xxd/GNUmakefile +1 -1
  362. data/share/sample/vim-7.3/adlint/xxd/adlint_cinit.h +1 -1
  363. data/share/sample/vim-7.3/adlint/xxd/adlint_pinit.h +1 -1
  364. data/share/sample/vim-7.3/adlint/xxd/adlint_traits.yml +49 -41
  365. data/share/sample/zsh-4.3.15/adlint/GNUmakefile +1 -1
  366. data/share/sample/zsh-4.3.15/adlint/adlint_traits.yml +46 -38
  367. data/share/sample/zsh-4.3.15/adlint/builtins/GNUmakefile +1 -1
  368. data/share/sample/zsh-4.3.15/adlint/builtins/adlint_cinit.h +1 -1
  369. data/share/sample/zsh-4.3.15/adlint/builtins/adlint_pinit.h +1 -1
  370. data/share/sample/zsh-4.3.15/adlint/builtins/adlint_traits.yml +50 -42
  371. data/share/sample/zsh-4.3.15/adlint/core/GNUmakefile +1 -1
  372. data/share/sample/zsh-4.3.15/adlint/core/adlint_cinit.h +1 -1
  373. data/share/sample/zsh-4.3.15/adlint/core/adlint_pinit.h +1 -1
  374. data/share/sample/zsh-4.3.15/adlint/core/adlint_traits.yml +50 -42
  375. data/share/sample/zsh-4.3.15/adlint/modules/GNUmakefile +1 -1
  376. data/share/sample/zsh-4.3.15/adlint/modules/adlint_cinit.h +1 -1
  377. data/share/sample/zsh-4.3.15/adlint/modules/adlint_pinit.h +1 -1
  378. data/share/sample/zsh-4.3.15/adlint/modules/adlint_traits.yml +50 -42
  379. data/share/sample/zsh-4.3.15/adlint/zle/GNUmakefile +1 -1
  380. data/share/sample/zsh-4.3.15/adlint/zle/adlint_cinit.h +1 -1
  381. data/share/sample/zsh-4.3.15/adlint/zle/adlint_pinit.h +1 -1
  382. data/share/sample/zsh-4.3.15/adlint/zle/adlint_traits.yml +50 -42
  383. data/spec/adlint/{c → cc1}/ctrlexpr_spec.rb +51 -49
  384. data/spec/adlint/{c → cc1}/domain_spec.rb +210 -179
  385. data/spec/adlint/{c → cc1}/operator_spec.rb +3 -3
  386. data/spec/adlint/{c → cc1}/syntax_spec.rb +10 -12
  387. data/spec/adlint/{c → cc1}/type_spec.rb +61 -68
  388. data/{lib/adlint/c.rb → spec/adlint/location_spec.rb} +24 -29
  389. data/spec/conf.d/default_traits.yml +38 -37
  390. data/spec/conf.d/empty_cinit.h +1 -1
  391. data/spec/conf.d/empty_pinit.h +1 -1
  392. data/spec/conf.d/project/foo.c +0 -0
  393. data/spec/spec_helper.rb +2 -2
  394. metadata +60 -40
  395. data/lib/adlint/c/domain.rb +0 -7931
  396. data/lib/adlint/c/lexer.rb +0 -252
  397. data/lib/adlint/c/phase.rb +0 -135
  398. data/lib/adlint/exam/c_builtin/c_check.rb +0 -20745
  399. data/lib/adlint/exam/c_builtin/c_check_shima.rb +0 -983
  400. data/lib/adlint/exam/c_builtin/c_code.rb +0 -477
  401. data/lib/adlint/exam/c_builtin/c_metric.rb +0 -818
data/lib/adlint/cpp.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # AdLint::Cpp package loader.
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
  #
@@ -1,7 +1,7 @@
1
1
  # Inline assembly notations.
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
  #
@@ -35,20 +35,19 @@ module AdLint #:nodoc:
35
35
  module Cpp #:nodoc:
36
36
 
37
37
  module InlineAssemblyDefinition
38
- def create_inline_assembly_substitutions(source)
39
- [create_cxx_asm_definition(source)] +
40
- create_extended_asm_definitions(source)
38
+ def create_inline_assembly_substitutions(src)
39
+ [create_cxx_asm_definition(src)] + create_extended_asm_definitions(src)
41
40
  end
42
41
 
43
- def create_cxx_asm_definition(source)
44
- CodeSubstitution.new("asm(__adlint__any);", "").tap do |subst|
45
- subst.on_substitution += lambda { |matched_tokens|
46
- source.on_inline_assembly.invoke(matched_tokens)
42
+ def create_cxx_asm_definition(src)
43
+ CodeSubstitution.new("asm(__adlint__any);", "").tap do |sub|
44
+ sub.on_substitution += lambda { |matched_toks|
45
+ src.on_inline_assembly.invoke(matched_toks)
47
46
  }
48
47
  end
49
48
  end
50
49
 
51
- def create_extended_asm_definitions(source)
50
+ def create_extended_asm_definitions(src)
52
51
  [
53
52
  "__asm(__adlint__any);",
54
53
  "asm { __adlint__any }",
@@ -59,10 +58,10 @@ module Cpp #:nodoc:
59
58
  "asm(__adlint__any);",
60
59
  "asm volatile (__adlint__any);",
61
60
  "asm __volatile__ (__adlint__any);"
62
- ].map do |pattern|
63
- CodeSubstitution.new(pattern, "").tap { |subst|
64
- subst.on_substitution += lambda { |matched_tokens|
65
- source.on_inline_assembly.invoke(matched_tokens)
61
+ ].map do |ptn|
62
+ CodeSubstitution.new(ptn, "").tap { |sub|
63
+ sub.on_substitution += lambda { |matched_toks|
64
+ src.on_inline_assembly.invoke(matched_toks)
66
65
  }
67
66
  }
68
67
  end
@@ -19,12 +19,12 @@ module_eval(<<'...end constexpr.y/module_eval...', 'constexpr.y', 311)
19
19
 
20
20
  include ReportUtil
21
21
 
22
- def initialize(context, expr_tokens)
23
- @context = context
24
- @expr_tokens = expr_tokens
25
- @macro_table = context.macro_table
26
- @fpath = expr_tokens.first.location.fpath
27
- @last_line_no = expr_tokens.last.location.line_no
22
+ def initialize(pp_ctxt, expr_toks)
23
+ @pp_ctxt = pp_ctxt
24
+ @expr_toks = expr_toks
25
+ @macro_tbl = pp_ctxt.macro_table
26
+ @fpath = expr_toks.first.location.fpath
27
+ @lst_line_no = expr_toks.last.location.line_no
28
28
  end
29
29
 
30
30
  extend Pluggable
@@ -33,66 +33,70 @@ def_plugin :on_illformed_defined_op_found
33
33
  def_plugin :on_undefined_macro_referred
34
34
 
35
35
  def evaluate
36
- @token_queue = relex(@expr_tokens)
37
- if expression = do_parse
38
- expression
36
+ @tok_queue = relex(@expr_toks)
37
+ if expr = do_parse
38
+ expr
39
39
  else
40
40
  ErrorExpression.new(nil)
41
41
  end
42
42
  end
43
43
 
44
44
  private
45
- def relex(expr_tokens)
46
- token_queue = []
47
- expr_tokens.each do |token|
48
- case token.value
45
+ def relex(expr_toks)
46
+ tok_queue = []
47
+ expr_toks.each do |tok|
48
+ case tok.value
49
49
  when /\A(?:0x[0-9a-f]+|[0-9]+)[UL]*\z/i
50
- token_queue.push(Token.new(:CONSTANT, token.value, token.location))
50
+ tok_queue.push(Token.new(:CONSTANT, tok.value, tok.location))
51
51
  when /\A(?:[0-9]*\.[0-9]*e[+-]?[0-9]+|[0-9]+\.?e[+-]?[0-9]+)[FL]*/i
52
- token_queue.push(Token.new(:CONSTANT, token.value, token.location))
52
+ tok_queue.push(Token.new(:CONSTANT, tok.value, tok.location))
53
53
  when /\AL?'.*'\z/i
54
- token_queue.push(Token.new(:CONSTANT, token.value, token.location))
54
+ tok_queue.push(Token.new(:CONSTANT, tok.value, tok.location))
55
55
  when /\AL?".*"\z/i
56
- token_queue.push(Token.new(:CONSTANT, token.value, token.location))
56
+ tok_queue.push(Token.new(:CONSTANT, tok.value, tok.location))
57
57
  when "(", ")", "+", "-", "~", "!", "*", "/", "%", "<<", ">>", "<", ">",
58
58
  "<=", ">=", "==", "!=", "&", "^", "|", "&&", "||", "?", ":"
59
- token_queue.push(Token.new(token.value, token.value, token.location))
59
+ tok_queue.push(Token.new(tok.value, tok.value, tok.location))
60
60
  when "defined"
61
- token_queue.push(Token.new(:DEFINED, token.value, token.location))
61
+ tok_queue.push(Token.new(:DEFINED, tok.value, tok.location))
62
62
  else
63
- token_queue.push(Token.new(:IDENTIFIER, token.value, token.location))
63
+ tok_queue.push(Token.new(:IDENTIFIER, tok.value, tok.location))
64
64
  end
65
65
  end
66
- token_queue
66
+ tok_queue
67
67
  end
68
68
 
69
69
  def next_token
70
- (token = @token_queue.shift) ? [token.type, token] : nil
70
+ (tok = @tok_queue.shift) ? [tok.type, tok] : nil
71
71
  end
72
72
 
73
- def on_error(error_token_id, error_value, value_stack)
74
- E(:E0007, location_of(error_value), value_of(error_value))
73
+ def on_error(err_tok_id, err_val, *)
74
+ E(:E0007, loc_of(err_val), val_of(err_val))
75
75
  end
76
76
 
77
- def location_of(token)
78
- token == "$" ? Location.new(@fpath, @last_line_no) : token.location
77
+ def loc_of(tok)
78
+ tok == "$" ? Location.new(@fpath, @lst_line_no) : tok.location
79
79
  end
80
80
 
81
- def value_of(token)
82
- token == "$" ? "EOF" : token.value
81
+ def val_of(tok)
82
+ tok == "$" ? "EOF" : tok.value
83
83
  end
84
84
 
85
- def notify_illformed_defined_operator(location, no_args)
86
- on_illformed_defined_op_found.invoke(location, no_args)
85
+ def notify_illformed_defined_operator(loc, no_args)
86
+ on_illformed_defined_op_found.invoke(loc, no_args)
87
87
  end
88
88
 
89
- def notify_undefined_macro_referred(identifier)
90
- on_undefined_macro_referred.invoke(identifier)
89
+ def notify_undefined_macro_referred(id)
90
+ on_undefined_macro_referred.invoke(id)
91
91
  end
92
92
 
93
- def report
94
- @context.report
95
- end
93
+ extend Forwardable
94
+
95
+ def_delegator :@pp_ctxt, :report
96
+ private :report
97
+
98
+ def_delegator :@pp_ctxt, :message_catalog
99
+ private :message_catalog
96
100
 
97
101
  # vim:ft=racc:sw=2:ts=2:sts=2:et:
98
102
  ...end constexpr.y/module_eval...
@@ -456,7 +460,7 @@ module_eval(<<'.,.,', 'constexpr.y', 104)
456
460
 
457
461
  module_eval(<<'.,.,', 'constexpr.y', 109)
458
462
  def _reduce_10(val, _values, result)
459
- if macro = @macro_table.lookup(val[2].value)
463
+ if macro = @macro_tbl.lookup(val[2].value)
460
464
  macro.define_line.mark_as_referred_by(val[2])
461
465
  value = 1
462
466
  else
@@ -470,7 +474,7 @@ module_eval(<<'.,.,', 'constexpr.y', 109)
470
474
 
471
475
  module_eval(<<'.,.,', 'constexpr.y', 119)
472
476
  def _reduce_11(val, _values, result)
473
- if macro = @macro_table.lookup(val[1].value)
477
+ if macro = @macro_tbl.lookup(val[1].value)
474
478
  macro.define_line.mark_as_referred_by(val[1])
475
479
  value = 1
476
480
  else
@@ -484,7 +488,7 @@ module_eval(<<'.,.,', 'constexpr.y', 119)
484
488
 
485
489
  module_eval(<<'.,.,', 'constexpr.y', 129)
486
490
  def _reduce_12(val, _values, result)
487
- notify_illformed_defined_operator(location_of(val[0]), val[1] == "$")
491
+ notify_illformed_defined_operator(loc_of(val[0]), val[1] == "$")
488
492
  result = ErrorExpression.new(val[1])
489
493
 
490
494
  result
@@ -1,7 +1,7 @@
1
1
  # The constant-expression evaluator.
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
  #
@@ -107,7 +107,7 @@ unary_expression
107
107
  }
108
108
  | DEFINED "(" IDENTIFIER ")"
109
109
  {
110
- if macro = @macro_table.lookup(val[2].value)
110
+ if macro = @macro_tbl.lookup(val[2].value)
111
111
  macro.define_line.mark_as_referred_by(val[2])
112
112
  value = 1
113
113
  else
@@ -117,7 +117,7 @@ unary_expression
117
117
  }
118
118
  | DEFINED IDENTIFIER
119
119
  {
120
- if macro = @macro_table.lookup(val[1].value)
120
+ if macro = @macro_tbl.lookup(val[1].value)
121
121
  macro.define_line.mark_as_referred_by(val[1])
122
122
  value = 1
123
123
  else
@@ -127,7 +127,7 @@ unary_expression
127
127
  }
128
128
  | DEFINED error
129
129
  {
130
- notify_illformed_defined_operator(location_of(val[0]), val[1] == "$")
130
+ notify_illformed_defined_operator(loc_of(val[0]), val[1] == "$")
131
131
  result = ErrorExpression.new(val[1])
132
132
  }
133
133
  ;
@@ -311,12 +311,12 @@ require "adlint/cpp/util"
311
311
 
312
312
  include ReportUtil
313
313
 
314
- def initialize(context, expr_tokens)
315
- @context = context
316
- @expr_tokens = expr_tokens
317
- @macro_table = context.macro_table
318
- @fpath = expr_tokens.first.location.fpath
319
- @last_line_no = expr_tokens.last.location.line_no
314
+ def initialize(pp_ctxt, expr_toks)
315
+ @pp_ctxt = pp_ctxt
316
+ @expr_toks = expr_toks
317
+ @macro_tbl = pp_ctxt.macro_table
318
+ @fpath = expr_toks.first.location.fpath
319
+ @lst_line_no = expr_toks.last.location.line_no
320
320
  end
321
321
 
322
322
  extend Pluggable
@@ -325,65 +325,69 @@ def_plugin :on_illformed_defined_op_found
325
325
  def_plugin :on_undefined_macro_referred
326
326
 
327
327
  def evaluate
328
- @token_queue = relex(@expr_tokens)
329
- if expression = do_parse
330
- expression
328
+ @tok_queue = relex(@expr_toks)
329
+ if expr = do_parse
330
+ expr
331
331
  else
332
332
  ErrorExpression.new(nil)
333
333
  end
334
334
  end
335
335
 
336
336
  private
337
- def relex(expr_tokens)
338
- token_queue = []
339
- expr_tokens.each do |token|
340
- case token.value
337
+ def relex(expr_toks)
338
+ tok_queue = []
339
+ expr_toks.each do |tok|
340
+ case tok.value
341
341
  when /\A(?:0x[0-9a-f]+|[0-9]+)[UL]*\z/i
342
- token_queue.push(Token.new(:CONSTANT, token.value, token.location))
342
+ tok_queue.push(Token.new(:CONSTANT, tok.value, tok.location))
343
343
  when /\A(?:[0-9]*\.[0-9]*e[+-]?[0-9]+|[0-9]+\.?e[+-]?[0-9]+)[FL]*/i
344
- token_queue.push(Token.new(:CONSTANT, token.value, token.location))
344
+ tok_queue.push(Token.new(:CONSTANT, tok.value, tok.location))
345
345
  when /\AL?'.*'\z/i
346
- token_queue.push(Token.new(:CONSTANT, token.value, token.location))
346
+ tok_queue.push(Token.new(:CONSTANT, tok.value, tok.location))
347
347
  when /\AL?".*"\z/i
348
- token_queue.push(Token.new(:CONSTANT, token.value, token.location))
348
+ tok_queue.push(Token.new(:CONSTANT, tok.value, tok.location))
349
349
  when "(", ")", "+", "-", "~", "!", "*", "/", "%", "<<", ">>", "<", ">",
350
350
  "<=", ">=", "==", "!=", "&", "^", "|", "&&", "||", "?", ":"
351
- token_queue.push(Token.new(token.value, token.value, token.location))
351
+ tok_queue.push(Token.new(tok.value, tok.value, tok.location))
352
352
  when "defined"
353
- token_queue.push(Token.new(:DEFINED, token.value, token.location))
353
+ tok_queue.push(Token.new(:DEFINED, tok.value, tok.location))
354
354
  else
355
- token_queue.push(Token.new(:IDENTIFIER, token.value, token.location))
355
+ tok_queue.push(Token.new(:IDENTIFIER, tok.value, tok.location))
356
356
  end
357
357
  end
358
- token_queue
358
+ tok_queue
359
359
  end
360
360
 
361
361
  def next_token
362
- (token = @token_queue.shift) ? [token.type, token] : nil
362
+ (tok = @tok_queue.shift) ? [tok.type, tok] : nil
363
363
  end
364
364
 
365
- def on_error(error_token_id, error_value, value_stack)
366
- E(:E0007, location_of(error_value), value_of(error_value))
365
+ def on_error(err_tok_id, err_val, *)
366
+ E(:E0007, loc_of(err_val), val_of(err_val))
367
367
  end
368
368
 
369
- def location_of(token)
370
- token == "$" ? Location.new(@fpath, @last_line_no) : token.location
369
+ def loc_of(tok)
370
+ tok == "$" ? Location.new(@fpath, @lst_line_no) : tok.location
371
371
  end
372
372
 
373
- def value_of(token)
374
- token == "$" ? "EOF" : token.value
373
+ def val_of(tok)
374
+ tok == "$" ? "EOF" : tok.value
375
375
  end
376
376
 
377
- def notify_illformed_defined_operator(location, no_args)
378
- on_illformed_defined_op_found.invoke(location, no_args)
377
+ def notify_illformed_defined_operator(loc, no_args)
378
+ on_illformed_defined_op_found.invoke(loc, no_args)
379
379
  end
380
380
 
381
- def notify_undefined_macro_referred(identifier)
382
- on_undefined_macro_referred.invoke(identifier)
381
+ def notify_undefined_macro_referred(id)
382
+ on_undefined_macro_referred.invoke(id)
383
383
  end
384
384
 
385
- def report
386
- @context.report
387
- end
385
+ extend Forwardable
386
+
387
+ def_delegator :@pp_ctxt, :report
388
+ private :report
389
+
390
+ def_delegator :@pp_ctxt, :message_catalog
391
+ private :message_catalog
388
392
 
389
393
  # vim:ft=racc:sw=2:ts=2:sts=2:et:
@@ -1,7 +1,7 @@
1
1
  # C preprocessor.
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
  #
@@ -32,6 +32,7 @@
32
32
  require "adlint/error"
33
33
  require "adlint/source"
34
34
  require "adlint/report"
35
+ require "adlint/util"
35
36
  require "adlint/cpp/syntax"
36
37
  require "adlint/cpp/source"
37
38
  require "adlint/cpp/macro"
@@ -47,11 +48,12 @@ module Cpp #:nodoc:
47
48
  # Preprocessor executes recursive descent parsing and evaluation at a time.
48
49
  class Preprocessor
49
50
  include ReportUtil
51
+ include LogUtil
50
52
 
51
- def execute(context, source)
52
- @context = context
53
- context.push_lexer(create_lexer(context, source))
54
- preprocessing_file(context)
53
+ def execute(pp_ctxt, src)
54
+ @pp_ctxt = pp_ctxt
55
+ @pp_ctxt.push_lexer(create_lexer(@pp_ctxt, src))
56
+ preprocessing_file(@pp_ctxt)
55
57
  end
56
58
 
57
59
  extend Pluggable
@@ -78,14 +80,14 @@ module Cpp #:nodoc:
78
80
  def_plugin :on_extra_tokens_found
79
81
 
80
82
  private
81
- def preprocessing_file(context)
82
- PreprocessingFile.new(context.translation_unit_fpath, group(context))
83
+ def preprocessing_file(pp_ctxt)
84
+ PreprocessingFile.new(pp_ctxt.tunit_root_fpath, group(pp_ctxt))
83
85
  end
84
86
 
85
- def group(context)
86
- if group_part = group_part(context)
87
+ def group(pp_ctxt)
88
+ if group_part = group_part(pp_ctxt)
87
89
  group = Group.new.push(group_part)
88
- while group_part = group_part(context)
90
+ while group_part = group_part(pp_ctxt)
89
91
  group.push(group_part)
90
92
  end
91
93
  return group
@@ -93,30 +95,30 @@ module Cpp #:nodoc:
93
95
  nil
94
96
  end
95
97
 
96
- def group_part(context)
97
- if top_token = context.top_token
98
- case top_token.type
98
+ def group_part(pp_ctxt)
99
+ if top_tok = pp_ctxt.top_token
100
+ case top_tok.type
99
101
  when :IF, :IFDEF, :IFNDEF
100
- return if_section(context)
102
+ return if_section(pp_ctxt)
101
103
  when :INCLUDE, :INCLUDE_NEXT, :DEFINE, :UNDEF, :LINE, :ERROR, :PRAGMA
102
- return control_line(context)
104
+ return control_line(pp_ctxt)
103
105
  when :ASM
104
- return asm_section(context)
106
+ return asm_section(pp_ctxt)
105
107
  when :NULL_DIRECTIVE
106
- return NullDirective.new(context.next_token)
108
+ return NullDirective.new(pp_ctxt.next_token)
107
109
  when :UNKNOWN_DIRECTIVE
108
- return UnknownDirective.new(context.next_token)
110
+ return UnknownDirective.new(pp_ctxt.next_token)
109
111
  when :TEXT_LINE
110
- text_line = TextLine.new(context.next_token)
111
- tokens = TextLineNormalizer.normalize(text_line, context)
112
- if tokens
113
- context.deferred_text_lines.clear
114
- tokens.each do |token|
115
- context.source.add_token(token)
116
- notify_pp_token_extracted(token)
112
+ text_line = TextLine.new(pp_ctxt.next_token)
113
+ toks = TextLineNormalizer.normalize(text_line, pp_ctxt)
114
+ if toks
115
+ pp_ctxt.deferred_text_lines.clear
116
+ toks.each do |tok|
117
+ pp_ctxt.source.add_token(tok)
118
+ notify_pp_token_extracted(tok)
117
119
  end
118
120
  else
119
- context.deferred_text_lines.push(text_line)
121
+ pp_ctxt.deferred_text_lines.push(text_line)
120
122
  end
121
123
  return text_line
122
124
  end
@@ -124,92 +126,92 @@ module Cpp #:nodoc:
124
126
  nil
125
127
  end
126
128
 
127
- def if_section(context)
128
- context.push_branch
129
- if_group = if_group(context)
129
+ def if_section(pp_ctxt)
130
+ pp_ctxt.push_branch
131
+ if_group = if_group(pp_ctxt)
130
132
 
131
- while top_token = context.top_token
132
- case top_token.type
133
+ while top_tok = pp_ctxt.top_token
134
+ case top_tok.type
133
135
  when :ELIF
134
- elif_groups = elif_groups(context)
136
+ elif_groups = elif_groups(pp_ctxt)
135
137
  when :ELSE
136
- else_group = else_group(context)
138
+ else_group = else_group(pp_ctxt)
137
139
  when :ENDIF
138
- endif_line = endif_line(context)
140
+ endif_line = endif_line(pp_ctxt)
139
141
  break
140
142
  end
141
143
  end
142
144
 
143
145
  E(:E0004, if_group.location) unless endif_line
144
146
 
145
- context.pop_branch
147
+ pp_ctxt.pop_branch
146
148
  IfSection.new(if_group, elif_groups, else_group, endif_line)
147
149
  end
148
150
 
149
- def if_group(context)
150
- if keyword = context.top_token
151
+ def if_group(pp_ctxt)
152
+ if keyword = pp_ctxt.top_token
151
153
  case keyword.type
152
154
  when :IF
153
- return if_statement(context)
155
+ return if_statement(pp_ctxt)
154
156
  when :IFDEF
155
- return ifdef_statement(context)
157
+ return ifdef_statement(pp_ctxt)
156
158
  when :IFNDEF
157
- return ifndef_statement(context)
159
+ return ifndef_statement(pp_ctxt)
158
160
  end
159
161
  end
160
162
  nil
161
163
  end
162
164
 
163
- def if_statement(context)
164
- keyword = context.next_token
165
- unless pp_tokens = pp_tokens(context)
165
+ def if_statement(pp_ctxt)
166
+ keyword = pp_ctxt.next_token
167
+ unless pp_toks = pp_tokens(pp_ctxt)
166
168
  return nil
167
169
  end
168
- discard_extra_tokens_until_newline(context)
169
- expression = ExpressionNormalizer.normalize(pp_tokens, context, self)
170
- if expression.value == 0
171
- context.skip_group
170
+ discard_extra_tokens_until_newline(pp_ctxt)
171
+ expr = ExpressionNormalizer.normalize(pp_toks, pp_ctxt, self)
172
+ if expr.value == 0
173
+ pp_ctxt.skip_group
172
174
  else
173
- group = group(context)
174
- context.branch_evaluated = true
175
+ group = group(pp_ctxt)
176
+ pp_ctxt.branch_evaluated = true
175
177
  end
176
- IfStatement.new(keyword, expression, group)
178
+ IfStatement.new(keyword, expr, group)
177
179
  end
178
180
 
179
- def ifdef_statement(context)
180
- keyword = context.next_token
181
- unless identifier = context.next_token and identifier.type == :IDENTIFIER
181
+ def ifdef_statement(pp_ctxt)
182
+ keyword = pp_ctxt.next_token
183
+ unless id = pp_ctxt.next_token and id.type == :IDENTIFIER
182
184
  return nil
183
185
  end
184
- discard_extra_tokens_until_newline(context)
185
- if macro_defined?(context, identifier)
186
- group = group(context)
187
- context.branch_evaluated = true
186
+ discard_extra_tokens_until_newline(pp_ctxt)
187
+ if macro_defined?(pp_ctxt, id)
188
+ group = group(pp_ctxt)
189
+ pp_ctxt.branch_evaluated = true
188
190
  else
189
- context.skip_group
191
+ pp_ctxt.skip_group
190
192
  end
191
- IfdefStatement.new(keyword, identifier, group)
193
+ IfdefStatement.new(keyword, id, group)
192
194
  end
193
195
 
194
- def ifndef_statement(context)
195
- keyword = context.next_token
196
- unless identifier = context.next_token and identifier.type == :IDENTIFIER
196
+ def ifndef_statement(pp_ctxt)
197
+ keyword = pp_ctxt.next_token
198
+ unless id = pp_ctxt.next_token and id.type == :IDENTIFIER
197
199
  return nil
198
200
  end
199
- discard_extra_tokens_until_newline(context)
200
- if macro_defined?(context, identifier)
201
- context.skip_group
201
+ discard_extra_tokens_until_newline(pp_ctxt)
202
+ if macro_defined?(pp_ctxt, id)
203
+ pp_ctxt.skip_group
202
204
  else
203
- group = group(context)
204
- context.branch_evaluated = true
205
+ group = group(pp_ctxt)
206
+ pp_ctxt.branch_evaluated = true
205
207
  end
206
- IfndefStatement.new(keyword, identifier, group)
208
+ IfndefStatement.new(keyword, id, group)
207
209
  end
208
210
 
209
- def elif_groups(context)
210
- if elif_group = elif_group(context)
211
+ def elif_groups(pp_ctxt)
212
+ if elif_group = elif_group(pp_ctxt)
211
213
  elif_groups = ElifGroups.new.push(elif_group)
212
- while elif_group = elif_group(context)
214
+ while elif_group = elif_group(pp_ctxt)
213
215
  elif_groups.push(elif_group)
214
216
  end
215
217
  return elif_groups
@@ -217,39 +219,39 @@ module Cpp #:nodoc:
217
219
  nil
218
220
  end
219
221
 
220
- def elif_group(context)
221
- unless top_token = context.top_token and top_token.type == :ELIF
222
+ def elif_group(pp_ctxt)
223
+ unless top_tok = pp_ctxt.top_token and top_tok.type == :ELIF
222
224
  return nil
223
225
  end
224
226
 
225
- if keyword = context.next_token
227
+ if keyword = pp_ctxt.next_token
226
228
  if keyword.type == :ELIF
227
- unless pp_tokens = pp_tokens(context)
229
+ unless pp_toks = pp_tokens(pp_ctxt)
228
230
  return nil
229
231
  end
230
- discard_extra_tokens_until_newline(context)
231
- expression = ExpressionNormalizer.normalize(pp_tokens, context, self)
232
- if context.branch_evaluated? || expression.value == 0
233
- context.skip_group
232
+ discard_extra_tokens_until_newline(pp_ctxt)
233
+ expr = ExpressionNormalizer.normalize(pp_toks, pp_ctxt, self)
234
+ if pp_ctxt.branch_evaluated? || expr.value == 0
235
+ pp_ctxt.skip_group
234
236
  else
235
- group = group(context)
236
- context.branch_evaluated = true
237
+ group = group(pp_ctxt)
238
+ pp_ctxt.branch_evaluated = true
237
239
  end
238
- return ElifStatement.new(keyword, expression, group)
240
+ return ElifStatement.new(keyword, expr, group)
239
241
  end
240
242
  end
241
243
  nil
242
244
  end
243
245
 
244
- def else_group(context)
245
- if keyword = context.next_token
246
+ def else_group(pp_ctxt)
247
+ if keyword = pp_ctxt.next_token
246
248
  if keyword.type == :ELSE
247
- discard_extra_tokens_until_newline(context)
248
- if context.branch_evaluated?
249
- context.skip_group
249
+ discard_extra_tokens_until_newline(pp_ctxt)
250
+ if pp_ctxt.branch_evaluated?
251
+ pp_ctxt.skip_group
250
252
  else
251
- group = group(context)
252
- context.branch_evaluated = true
253
+ group = group(pp_ctxt)
254
+ pp_ctxt.branch_evaluated = true
253
255
  end
254
256
  return ElseStatement.new(keyword, group)
255
257
  end
@@ -257,174 +259,174 @@ module Cpp #:nodoc:
257
259
  nil
258
260
  end
259
261
 
260
- def endif_line(context)
261
- if keyword = context.next_token
262
+ def endif_line(pp_ctxt)
263
+ if keyword = pp_ctxt.next_token
262
264
  if keyword.type == :ENDIF
263
- discard_extra_tokens_until_newline(context)
265
+ discard_extra_tokens_until_newline(pp_ctxt)
264
266
  return EndifLine.new(keyword)
265
267
  end
266
268
  end
267
269
  nil
268
270
  end
269
271
 
270
- def control_line(context)
271
- if keyword = context.top_token
272
+ def control_line(pp_ctxt)
273
+ if keyword = pp_ctxt.top_token
272
274
  case keyword.type
273
275
  when :INCLUDE
274
- return include_line(context)
276
+ return include_line(pp_ctxt)
275
277
  when :INCLUDE_NEXT
276
- return include_next_line(context)
278
+ return include_next_line(pp_ctxt)
277
279
  when :DEFINE
278
- return define_line(context)
280
+ return define_line(pp_ctxt)
279
281
  when :UNDEF
280
- return undef_line(context)
282
+ return undef_line(pp_ctxt)
281
283
  when :LINE
282
- return line_line(context)
284
+ return line_line(pp_ctxt)
283
285
  when :ERROR
284
- return error_line(context)
286
+ return error_line(pp_ctxt)
285
287
  when :PRAGMA
286
- return pragma_line(context)
288
+ return pragma_line(pp_ctxt)
287
289
  end
288
290
  end
289
291
  nil
290
292
  end
291
293
 
292
- def include_line(context)
293
- keyword = context.next_token
294
- if header_name = context.top_token
294
+ def include_line(pp_ctxt)
295
+ keyword = pp_ctxt.next_token
296
+ if header_name = pp_ctxt.top_token
295
297
  case header_name.type
296
298
  when :USR_HEADER_NAME
297
- return user_include_line(context, keyword)
299
+ return user_include_line(pp_ctxt, keyword)
298
300
  when :SYS_HEADER_NAME
299
- return system_include_line(context, keyword)
301
+ return system_include_line(pp_ctxt, keyword)
300
302
  else
301
- return macro_include_line(context, keyword)
303
+ return macro_include_line(pp_ctxt, keyword)
302
304
  end
303
305
  end
304
306
  nil
305
307
  end
306
308
 
307
- def include_next_line(context)
308
- keyword = context.next_token
309
- if header_name = context.top_token
309
+ def include_next_line(pp_ctxt)
310
+ keyword = pp_ctxt.next_token
311
+ if header_name = pp_ctxt.top_token
310
312
  case header_name.type
311
313
  when :USR_HEADER_NAME
312
- return user_include_next_line(context, keyword)
314
+ return user_include_next_line(pp_ctxt, keyword)
313
315
  when :SYS_HEADER_NAME
314
- return system_include_next_line(context, keyword)
316
+ return system_include_next_line(pp_ctxt, keyword)
315
317
  else
316
- return macro_include_next_line(context, keyword)
318
+ return macro_include_next_line(pp_ctxt, keyword)
317
319
  end
318
320
  end
319
321
  nil
320
322
  end
321
323
 
322
- def user_include_line(context, keyword)
323
- header_name = context.next_token
324
- discard_extra_tokens_until_newline(context)
325
- user_include_line =
326
- UserIncludeLine.new(keyword, header_name, context.include_depth)
327
- include_first_user_header(user_include_line, context)
328
- user_include_line
324
+ def user_include_line(pp_ctxt, keyword)
325
+ header_name = pp_ctxt.next_token
326
+ discard_extra_tokens_until_newline(pp_ctxt)
327
+ usr_include_line =
328
+ UserIncludeLine.new(keyword, header_name, pp_ctxt.include_depth)
329
+ include_first_user_header(usr_include_line, pp_ctxt)
330
+ usr_include_line
329
331
  end
330
332
 
331
- def user_include_next_line(context, keyword)
332
- header_name = context.next_token
333
- discard_extra_tokens_until_newline(context)
334
- user_include_next_line =
335
- UserIncludeNextLine.new(keyword, header_name, context.include_depth)
336
- include_next_user_header(user_include_next_line, context)
337
- user_include_next_line
333
+ def user_include_next_line(pp_ctxt, keyword)
334
+ header_name = pp_ctxt.next_token
335
+ discard_extra_tokens_until_newline(pp_ctxt)
336
+ usr_include_next_line =
337
+ UserIncludeNextLine.new(keyword, header_name, pp_ctxt.include_depth)
338
+ include_next_user_header(usr_include_next_line, pp_ctxt)
339
+ usr_include_next_line
338
340
  end
339
341
 
340
- def system_include_line(context, keyword)
341
- header_name = context.next_token
342
- discard_extra_tokens_until_newline(context)
343
- system_include_line =
344
- SystemIncludeLine.new(keyword, header_name, context.include_depth)
345
- include_first_system_header(system_include_line, context)
346
- system_include_line
342
+ def system_include_line(pp_ctxt, keyword)
343
+ header_name = pp_ctxt.next_token
344
+ discard_extra_tokens_until_newline(pp_ctxt)
345
+ sys_include_line =
346
+ SystemIncludeLine.new(keyword, header_name, pp_ctxt.include_depth)
347
+ include_first_system_header(sys_include_line, pp_ctxt)
348
+ sys_include_line
347
349
  end
348
350
 
349
- def system_include_next_line(context, keyword)
350
- header_name = context.next_token
351
- discard_extra_tokens_until_newline(context)
352
- system_include_next_line =
353
- SystemIncludeNextLine.new(keyword, header_name, context.include_depth)
354
- include_next_system_header(system_include_next_line, context)
355
- system_include_next_line
351
+ def system_include_next_line(pp_ctxt, keyword)
352
+ header_name = pp_ctxt.next_token
353
+ discard_extra_tokens_until_newline(pp_ctxt)
354
+ sys_include_next_line =
355
+ SystemIncludeNextLine.new(keyword, header_name, pp_ctxt.include_depth)
356
+ include_next_system_header(sys_include_next_line, pp_ctxt)
357
+ sys_include_next_line
356
358
  end
357
359
 
358
- def macro_include_line(context, keyword)
359
- unless pp_tokens = pp_tokens(context)
360
+ def macro_include_line(pp_ctxt, keyword)
361
+ unless pp_toks = pp_tokens(pp_ctxt)
360
362
  return nil
361
363
  end
362
- discard_extra_tokens_until_newline(context)
363
- PPTokensNormalizer.normalize(pp_tokens, context)
364
- return nil if pp_tokens.tokens.empty?
365
- case parameter = pp_tokens.tokens.map { |t| t.value }.join
364
+ discard_extra_tokens_until_newline(pp_ctxt)
365
+ PPTokensNormalizer.normalize(pp_toks, pp_ctxt)
366
+ return nil if pp_toks.tokens.empty?
367
+ case param = pp_toks.tokens.map { |tok| tok.value }.join
366
368
  when /\A".*"\z/
367
- user_include_line = UserIncludeLine.new(
368
- keyword, Token.new(:USR_HEADER_NAME, parameter,
369
- pp_tokens.tokens.first.location),
370
- context.include_depth)
371
- include_first_user_header(user_include_line, context)
372
- return user_include_line
369
+ usr_include_line = UserIncludeLine.new(
370
+ keyword, Token.new(:USR_HEADER_NAME, param,
371
+ pp_toks.tokens.first.location),
372
+ pp_ctxt.include_depth)
373
+ include_first_user_header(usr_include_line, pp_ctxt)
374
+ return usr_include_line
373
375
  when /\A<.*>\z/
374
- system_include_line = SystemIncludeLine.new(
375
- keyword, Token.new(:SYS_HEADER_NAME, parameter,
376
- pp_tokens.tokens.first.location),
377
- context.include_depth)
378
- include_first_system_header(system_include_line, context)
379
- return system_include_line
376
+ sys_include_line = SystemIncludeLine.new(
377
+ keyword, Token.new(:SYS_HEADER_NAME, param,
378
+ pp_toks.tokens.first.location),
379
+ pp_ctxt.include_depth)
380
+ include_first_system_header(sys_include_line, pp_ctxt)
381
+ return sys_include_line
380
382
  end
381
383
  nil
382
384
  end
383
385
 
384
- def macro_include_next_line(context, keyword)
385
- unless pp_tokens = pp_tokens(context)
386
+ def macro_include_next_line(pp_ctxt, keyword)
387
+ unless pp_toks = pp_tokens(pp_ctxt)
386
388
  return nil
387
389
  end
388
- discard_extra_tokens_until_newline(context)
389
- PPTokensNormalizer.normalize(pp_tokens, context)
390
- return nil if pp_tokens.tokens.empty?
391
- case parameter = pp_tokens.tokens.map { |t| t.value }.join
390
+ discard_extra_tokens_until_newline(pp_ctxt)
391
+ PPTokensNormalizer.normalize(pp_toks, pp_ctxt)
392
+ return nil if pp_toks.tokens.empty?
393
+ case param = pp_toks.tokens.map { |tok| tok.value }.join
392
394
  when /\A".*"\z/
393
- user_include_next_line = UserIncludeNextLine.new(
394
- keyword, Token.new(:USR_HEADER_NAME, parameter,
395
- pp_tokens.tokens.first.location),
396
- context.include_depth)
397
- include_next_user_header(user_include_next_line, context)
398
- return user_include_next_line
395
+ usr_include_next_line = UserIncludeNextLine.new(
396
+ keyword, Token.new(:USR_HEADER_NAME, param,
397
+ pp_toks.tokens.first.location),
398
+ pp_ctxt.include_depth)
399
+ include_next_user_header(usr_include_next_line, pp_ctxt)
400
+ return usr_include_next_line
399
401
  when /\A<.*>\z/
400
- system_include_next_line = SystemIncludeNextLine.new(
401
- keyword, Token.new(:SYS_HEADER_NAME, parameter,
402
- pp_tokens.tokens.first.location),
403
- context.include_depth)
404
- include_next_system_header(system_include_next_line, context)
405
- return system_include_next_line
402
+ sys_include_next_line = SystemIncludeNextLine.new(
403
+ keyword, Token.new(:SYS_HEADER_NAME, param,
404
+ pp_toks.tokens.first.location),
405
+ pp_ctxt.include_depth)
406
+ include_next_system_header(sys_include_next_line, pp_ctxt)
407
+ return sys_include_next_line
406
408
  end
407
409
  nil
408
410
  end
409
411
 
410
- def define_line(context)
411
- keyword = context.next_token
412
- unless identifier = context.next_token and identifier.type == :IDENTIFIER
412
+ def define_line(pp_ctxt)
413
+ keyword = pp_ctxt.next_token
414
+ unless id = pp_ctxt.next_token and id.type == :IDENTIFIER
413
415
  return nil
414
416
  end
415
- symbol = context.symbol_table.create_new_symbol(MacroName, identifier)
417
+ sym = pp_ctxt.symbol_table.create_new_symbol(MacroName, id)
416
418
 
417
- if paren = context.top_token and paren.type == "("
418
- context.next_token
419
- identifier_list = identifier_list(context)
420
- unless paren_or_ellipsis = context.next_token
419
+ if paren = pp_ctxt.top_token and paren.type == "("
420
+ pp_ctxt.next_token
421
+ id_list = identifier_list(pp_ctxt)
422
+ unless paren_or_ellipsis = pp_ctxt.next_token
421
423
  return nil
422
424
  end
423
425
  case paren_or_ellipsis.type
424
426
  when "..."
425
427
  ellipsis = paren_or_ellipsis
426
- if paren = context.top_token and paren.type == ")"
427
- context.next_token
428
+ if paren = pp_ctxt.top_token and paren.type == ")"
429
+ pp_ctxt.next_token
428
430
  else
429
431
  return nil
430
432
  end
@@ -433,54 +435,51 @@ module Cpp #:nodoc:
433
435
  else
434
436
  return nil
435
437
  end
436
- replacement_list = replacement_list(context)
437
- discard_extra_tokens_until_newline(context)
438
+ repl_list = replacement_list(pp_ctxt)
439
+ discard_extra_tokens_until_newline(pp_ctxt)
438
440
  if ellipsis
439
- define_line = VaFunctionLikeDefineLine.new(keyword, identifier,
440
- identifier_list,
441
- replacement_list, symbol)
441
+ define_line = VaFunctionLikeDefineLine.new(keyword, id, id_list,
442
+ repl_list, sym)
442
443
  macro = FunctionLikeMacro.new(define_line)
443
444
  notify_va_function_like_macro_defined(define_line, macro)
444
445
  else
445
- define_line = FunctionLikeDefineLine.new(keyword, identifier,
446
- identifier_list,
447
- replacement_list, symbol)
446
+ define_line = FunctionLikeDefineLine.new(keyword, id, id_list,
447
+ repl_list, sym)
448
448
  macro = FunctionLikeMacro.new(define_line)
449
449
  notify_function_like_macro_defined(define_line, macro)
450
450
  end
451
451
  else
452
- replacement_list = replacement_list(context)
453
- discard_extra_tokens_until_newline(context)
454
- define_line = ObjectLikeDefineLine.new(keyword, identifier,
455
- replacement_list, symbol)
452
+ repl_list = replacement_list(pp_ctxt)
453
+ discard_extra_tokens_until_newline(pp_ctxt)
454
+ define_line = ObjectLikeDefineLine.new(keyword, id, repl_list, sym)
456
455
  macro = ObjectLikeMacro.new(define_line)
457
456
  notify_object_like_macro_defined(define_line, macro)
458
457
  end
459
458
 
460
- context.macro_table.define(macro)
459
+ pp_ctxt.macro_table.define(macro)
461
460
  define_line
462
461
  end
463
462
 
464
- def undef_line(context)
465
- keyword = context.next_token
466
- unless identifier = context.next_token and identifier.type == :IDENTIFIER
463
+ def undef_line(pp_ctxt)
464
+ keyword = pp_ctxt.next_token
465
+ unless id = pp_ctxt.next_token and id.type == :IDENTIFIER
467
466
  return nil
468
467
  end
469
- discard_extra_tokens_until_newline(context)
468
+ discard_extra_tokens_until_newline(pp_ctxt)
470
469
 
471
- undef_line = UndefLine.new(keyword, identifier)
472
- macro = context.macro_table.lookup(identifier.value)
470
+ undef_line = UndefLine.new(keyword, id)
471
+ macro = pp_ctxt.macro_table.lookup(id.value)
473
472
  # NOTE: Undefining macro may be nil if not defined.
474
473
  notify_macro_undefined(undef_line, macro)
475
474
 
476
- context.macro_table.undef(identifier.value)
475
+ pp_ctxt.macro_table.undef(id.value)
477
476
  undef_line
478
477
  end
479
478
 
480
- def line_line(context)
481
- keyword = context.next_token
482
- pp_tokens = pp_tokens(context)
483
- discard_extra_tokens_until_newline(context)
479
+ def line_line(pp_ctxt)
480
+ keyword = pp_ctxt.next_token
481
+ pp_toks = pp_tokens(pp_ctxt)
482
+ discard_extra_tokens_until_newline(pp_ctxt)
484
483
 
485
484
  # NOTE: The ISO C99 standard says;
486
485
  #
@@ -496,262 +495,258 @@ module Cpp #:nodoc:
496
495
  # is replaced by its replacement list of preprocessing tokens). The
497
496
  # directive resulting after all replacements shall match one of the two
498
497
  # previous forms and is then processed as appropriate.
499
- PPTokensNormalizer.normalize(pp_tokens, context) if pp_tokens
498
+ PPTokensNormalizer.normalize(pp_toks, pp_ctxt) if pp_toks
500
499
 
501
- LineLine.new(keyword, pp_tokens)
500
+ LineLine.new(keyword, pp_toks)
502
501
  end
503
502
 
504
- def error_line(context)
505
- keyword = context.next_token
506
- pp_tokens = pp_tokens(context)
507
- discard_extra_tokens_until_newline(context)
508
- ErrorLine.new(keyword, pp_tokens)
503
+ def error_line(pp_ctxt)
504
+ keyword = pp_ctxt.next_token
505
+ pp_toks = pp_tokens(pp_ctxt)
506
+ discard_extra_tokens_until_newline(pp_ctxt)
507
+ ErrorLine.new(keyword, pp_toks)
509
508
  end
510
509
 
511
- def pragma_line(context)
512
- keyword = context.next_token
513
- pp_tokens = pp_tokens(context)
514
- discard_extra_tokens_until_newline(context)
515
- pragma_line = PragmaLine.new(keyword, pp_tokens)
516
- if pp_tokens && pp_tokens.tokens.size == 1 &&
517
- pp_tokens.tokens.first.value == "once"
518
- context.once_set.add(keyword.location.fpath)
510
+ def pragma_line(pp_ctxt)
511
+ keyword = pp_ctxt.next_token
512
+ pp_toks = pp_tokens(pp_ctxt)
513
+ discard_extra_tokens_until_newline(pp_ctxt)
514
+ pragma_line = PragmaLine.new(keyword, pp_toks)
515
+ if pp_toks and
516
+ pp_toks.tokens.size == 1 && pp_toks.tokens.first.value == "once"
517
+ pp_ctxt.once_set.add(keyword.location.fpath)
519
518
  else
520
519
  notify_unknown_pragma_evaled(pragma_line)
521
520
  end
522
521
  pragma_line
523
522
  end
524
523
 
525
- def identifier_list(context)
526
- unless identifier = context.top_token and identifier.type == :IDENTIFIER
524
+ def identifier_list(pp_ctxt)
525
+ unless id = pp_ctxt.top_token and id.type == :IDENTIFIER
527
526
  return nil
528
527
  end
529
- identifier_list = IdentifierList.new
530
- while token = context.next_token
531
- if token.type == :IDENTIFIER
532
- identifier_list.push(token)
528
+ id_list = IdentifierList.new
529
+ while tok = pp_ctxt.next_token
530
+ if tok.type == :IDENTIFIER
531
+ id_list.push(tok)
533
532
  end
534
- if comma = context.top_token and comma.type == ","
535
- context.next_token
533
+ if comma = pp_ctxt.top_token and comma.type == ","
534
+ pp_ctxt.next_token
536
535
  else
537
536
  break
538
537
  end
539
- unless identifier = context.top_token and
540
- identifier.type == :IDENTIFIER
538
+ unless id = pp_ctxt.top_token and id.type == :IDENTIFIER
541
539
  break
542
540
  end
543
541
  end
544
- identifier_list
542
+ id_list
545
543
  end
546
544
 
547
- def replacement_list(context)
548
- pp_tokens(context)
545
+ def replacement_list(pp_ctxt)
546
+ pp_tokens(pp_ctxt)
549
547
  end
550
548
 
551
- def pp_tokens(context)
552
- unless pp_token = context.top_token and pp_token.type == :PP_TOKEN
549
+ def pp_tokens(pp_ctxt)
550
+ unless pp_tok = pp_ctxt.top_token and pp_tok.type == :PP_TOKEN
553
551
  return nil
554
552
  end
555
- pp_tokens = PPTokens.new
556
- while token = context.top_token
557
- if token.type == :PP_TOKEN
558
- pp_tokens.push(context.next_token)
553
+ pp_toks = PPTokens.new
554
+ while tok = pp_ctxt.top_token
555
+ if tok.type == :PP_TOKEN
556
+ pp_toks.push(pp_ctxt.next_token)
559
557
  else
560
558
  break
561
559
  end
562
560
  end
563
- pp_tokens
561
+ pp_toks
564
562
  end
565
563
 
566
- def asm_section(context)
567
- asm_line = asm_line(context)
568
- context.skip_group
569
- endasm_line = endasm_line(context)
564
+ def asm_section(pp_ctxt)
565
+ asm_line = asm_line(pp_ctxt)
566
+ pp_ctxt.skip_group
567
+ endasm_line = endasm_line(pp_ctxt)
570
568
  asm_section = AsmSection.new(asm_line, endasm_line)
571
569
  notify_asm_section_evaled(asm_section)
572
570
  asm_section
573
571
  end
574
572
 
575
- def asm_line(context)
576
- if keyword = context.next_token
573
+ def asm_line(pp_ctxt)
574
+ if keyword = pp_ctxt.next_token
577
575
  if keyword.type == :ASM
578
- discard_extra_tokens_until_newline(context)
576
+ discard_extra_tokens_until_newline(pp_ctxt)
579
577
  return AsmLine.new(keyword)
580
578
  end
581
579
  end
582
580
  nil
583
581
  end
584
582
 
585
- def endasm_line(context)
586
- if keyword = context.next_token
583
+ def endasm_line(pp_ctxt)
584
+ if keyword = pp_ctxt.next_token
587
585
  if keyword.type == :ENDASM
588
- discard_extra_tokens_until_newline(context)
586
+ discard_extra_tokens_until_newline(pp_ctxt)
589
587
  return EndasmLine.new(keyword)
590
588
  end
591
589
  end
592
590
  nil
593
591
  end
594
592
 
595
- def include_first_user_header(user_include_line, context)
596
- basename =
597
- user_include_line.header_name.value.sub(/\A"(.*)"\z/, "\\1")
598
- current_dpath = user_include_line.location.fpath.dirname
599
- if fpath = resolve_first_user_header(basename, current_dpath)
600
- include_user_header(fpath, user_include_line, context)
593
+ def include_first_user_header(include_line, pp_ctxt)
594
+ basename = include_line.header_name.value.sub(/\A"(.*)"\z/, "\\1")
595
+ cur_dpath = include_line.location.fpath.dirname
596
+ if fpath = resolve_first_user_header(basename, cur_dpath, pp_ctxt)
597
+ include_user_header(fpath, include_line, pp_ctxt)
601
598
  else
602
- E(:E0010, user_include_line.location, basename)
603
- raise MissingUserHeaderError.new(user_include_line.location, basename,
604
- context.msg_fpath, context.log_fpath)
599
+ E(:E0010, include_line.location, basename)
600
+ raise MissingUserHeaderError.new(include_line.location, basename,
601
+ pp_ctxt.msg_fpath, pp_ctxt.log_fpath)
605
602
  end
606
603
  end
607
604
 
608
- def include_next_user_header(user_include_next_line, context)
609
- basename =
610
- user_include_next_line.header_name.value.sub(/\A"(.*)"\z/, "\\1")
611
- current_dpath = user_include_next_line.location.fpath.dirname
612
- if fpath = resolve_next_user_header(basename, current_dpath)
613
- include_user_header(fpath, user_include_next_line, context)
605
+ def include_next_user_header(include_line, pp_ctxt)
606
+ basename = include_line.header_name.value.sub(/\A"(.*)"\z/, "\\1")
607
+ cur_dpath = include_line.location.fpath.dirname
608
+ if fpath = resolve_next_user_header(basename, cur_dpath, pp_ctxt)
609
+ include_user_header(fpath, include_line, pp_ctxt)
614
610
  else
615
- E(:E0010, user_include_next_line.location, basename)
616
- raise MissingUserHeaderError.new(user_include_next_line.location,
617
- basename,
618
- context.msg_fpath, context.log_fpath)
611
+ E(:E0010, include_line.location, basename)
612
+ raise MissingUserHeaderError.new(include_line.location, basename,
613
+ pp_ctxt.msg_fpath, pp_ctxt.log_fpath)
619
614
  end
620
615
  end
621
616
 
622
- def include_user_header(fpath, user_include_line, context)
623
- unless context.once_set.include?(fpath)
624
- Analyzer.current.info("including \"#{fpath}\" at " +
625
- "#{user_include_line.location.to_s}")
626
- user_include_line.fpath = fpath
627
- user_header = UserHeader.new(fpath, user_include_line.location)
628
- context.push_lexer(create_lexer(context, user_header))
629
- context.sources.push(user_header)
630
- notify_user_header_included(user_include_line, user_header)
617
+ def include_user_header(fpath, include_line, pp_ctxt)
618
+ unless pp_ctxt.once_set.include?(fpath)
619
+ LOG_I("including \"#{fpath}\" at #{include_line.location.to_s}")
620
+ include_line.fpath = fpath
621
+ usr_header =
622
+ UserHeader.new(fpath, pp_ctxt.traits.of_project.file_encoding,
623
+ include_line.location)
624
+ pp_ctxt.push_lexer(create_lexer(pp_ctxt, usr_header))
625
+ pp_ctxt.sources.push(usr_header)
626
+ notify_user_header_included(include_line, usr_header)
631
627
  end
632
628
  end
633
629
 
634
- def include_first_system_header(system_include_line, context)
635
- basename =
636
- system_include_line.header_name.value.sub(/\A<(.*)>\z/, "\\1")
637
- if fpath = resolve_first_system_header(basename)
638
- include_system_header(fpath, system_include_line, context)
630
+ def include_first_system_header(include_line, pp_ctxt)
631
+ basename = include_line.header_name.value.sub(/\A<(.*)>\z/, "\\1")
632
+ if fpath = resolve_first_system_header(basename, pp_ctxt)
633
+ include_system_header(fpath, include_line, pp_ctxt)
639
634
  else
640
- E(:E0009, system_include_line.location, basename)
641
- raise MissingSystemHeaderError.new(system_include_line.location,
642
- basename,
643
- context.msg_fpath,
644
- context.log_fpath)
635
+ E(:E0009, include_line.location, basename)
636
+ raise MissingSystemHeaderError.new(include_line.location, basename,
637
+ pp_ctxt.msg_fpath,
638
+ pp_ctxt.log_fpath)
645
639
  end
646
640
  end
647
641
 
648
- def include_next_system_header(system_include_next_line, context)
649
- basename =
650
- system_include_next_line.header_name.value.sub(/\A<(.*)>\z/, "\\1")
651
- if fpath = resolve_next_system_header(basename)
652
- include_system_header(fpath, system_include_next_line, context)
642
+ def include_next_system_header(include_line, pp_ctxt)
643
+ basename = include_line.header_name.value.sub(/\A<(.*)>\z/, "\\1")
644
+ if fpath = resolve_next_system_header(basename, pp_ctxt)
645
+ include_system_header(fpath, include_line, pp_ctxt)
653
646
  else
654
- E(:E0009, system_include_line.location, basename)
655
- raise MissingSystemHeaderError.new(system_include_next_line.location,
656
- basename,
657
- context.msg_fpath,
658
- context.log_fpath)
647
+ E(:E0009, include_line.location, basename)
648
+ raise MissingSystemHeaderError.new(include_line.location, basename,
649
+ pp_ctxt.msg_fpath,
650
+ pp_ctxt.log_fpath)
659
651
  end
660
652
  end
661
653
 
662
- def include_system_header(fpath, system_include_line, context)
663
- unless context.once_set.include?(fpath)
664
- Analyzer.current.info("including <#{fpath}> at " +
665
- "#{system_include_line.location.to_s}")
666
- system_include_line.fpath = fpath
667
- system_header = SystemHeader.new(fpath, system_include_line.location)
668
- context.push_lexer(create_lexer(context, system_header))
669
- context.sources.push(system_header)
670
- notify_system_header_included(system_include_line, system_header)
654
+ def include_system_header(fpath, include_line, pp_ctxt)
655
+ unless pp_ctxt.once_set.include?(fpath)
656
+ LOG_I("including <#{fpath}> at #{include_line.location.to_s}")
657
+ include_line.fpath = fpath
658
+ # FIXME: The character encoding of system headers may not be same as
659
+ # one of project's source files.
660
+ sys_header =
661
+ SystemHeader.new(fpath, pp_ctxt.traits.of_project.file_encoding,
662
+ include_line.location)
663
+ pp_ctxt.push_lexer(create_lexer(pp_ctxt, sys_header))
664
+ pp_ctxt.sources.push(sys_header)
665
+ notify_system_header_included(include_line, sys_header)
671
666
  end
672
667
  end
673
668
 
674
- def resolve_first_user_header(basename, current_dpath)
675
- resolve_user_headers(basename, current_dpath, 1).first
669
+ def resolve_first_user_header(basename, cur_dpath, pp_ctxt)
670
+ resolve_user_headers(basename, cur_dpath, 1, pp_ctxt).first
676
671
  end
677
672
 
678
- def resolve_next_user_header(basename, current_dpath)
679
- resolve_user_headers(basename, current_dpath, 2).last
673
+ def resolve_next_user_header(basename, cur_dpath, pp_ctxt)
674
+ resolve_user_headers(basename, cur_dpath, 2, pp_ctxt).last
680
675
  end
681
676
 
682
- def resolve_user_headers(basename, current_dpath, max_num)
683
- include_paths = [current_dpath]
684
- include_paths += Traits.instance.of_project.include_path
685
- include_paths += Traits.instance.of_compiler.include_path
677
+ def resolve_user_headers(basename, cur_dpath, max_num, pp_ctxt)
678
+ search_paths = [cur_dpath]
679
+ search_paths += pp_ctxt.traits.of_project.file_search_paths
680
+ search_paths += pp_ctxt.traits.of_compiler.file_search_paths
686
681
 
687
682
  base_fpath = Pathname.new(basename)
688
683
  if base_fpath.absolute? && base_fpath.readable?
689
684
  [base_fpath]
690
685
  else
691
- result = []
692
- include_paths.each do |dpath|
686
+ resolved = []
687
+ search_paths.each do |dpath|
693
688
  fpath = dpath.join(base_fpath)
694
689
  fpath = Pathname.new(fpath.to_s.gsub(/\\\\|\\/, "/"))
695
- result.push(fpath) if fpath.readable?
696
- break if result.size == max_num
690
+ resolved.push(fpath) if fpath.readable?
691
+ break if resolved.size == max_num
697
692
  end
698
- result
693
+ resolved
699
694
  end
700
695
  end
701
696
 
702
- def resolve_first_system_header(basename)
703
- resolve_system_headers(basename, 1).first
697
+ def resolve_first_system_header(basename, pp_ctxt)
698
+ resolve_system_headers(basename, 1, pp_ctxt).first
704
699
  end
705
700
 
706
- def resolve_next_system_header(basename)
707
- resolve_system_headers(basename, 2).last
701
+ def resolve_next_system_header(basename, pp_ctxt)
702
+ resolve_system_headers(basename, 2, pp_ctxt).last
708
703
  end
709
704
 
710
- def resolve_system_headers(basename, max_num)
711
- include_paths = Traits.instance.of_project.include_path
712
- include_paths += Traits.instance.of_compiler.include_path
705
+ def resolve_system_headers(basename, max_num, pp_ctxt)
706
+ search_paths = pp_ctxt.traits.of_project.file_search_paths
707
+ search_paths += pp_ctxt.traits.of_compiler.file_search_paths
713
708
 
714
709
  base_fpath = Pathname.new(basename)
715
710
  if base_fpath.absolute? && base_fpath.readable?
716
711
  [base_fpath]
717
712
  else
718
- result = []
719
- include_paths.each do |dpath|
713
+ resolved = []
714
+ search_paths.each do |dpath|
720
715
  fpath = dpath.join(base_fpath)
721
716
  fpath = Pathname.new(fpath.to_s.gsub(/\\\\|\\/, "/"))
722
- result.push(fpath) if fpath.readable?
723
- break if result.size == max_num
717
+ resolved.push(fpath) if fpath.readable?
718
+ break if resolved.size == max_num
724
719
  end
725
- result
720
+ resolved
726
721
  end
727
722
  end
728
723
 
729
- def macro_defined?(context, identifier)
730
- if macro = context.macro_table.lookup(identifier.value)
731
- macro.define_line.mark_as_referred_by(identifier)
724
+ def macro_defined?(pp_ctxt, id)
725
+ if macro = pp_ctxt.macro_table.lookup(id.value)
726
+ macro.define_line.mark_as_referred_by(id)
732
727
  true
733
728
  else
734
729
  false
735
730
  end
736
731
  end
737
732
 
738
- def discard_extra_tokens_until_newline(context)
739
- extra_tokens = []
740
- while token = context.next_token
741
- if token.type == :NEW_LINE
733
+ def discard_extra_tokens_until_newline(pp_ctxt)
734
+ extra_toks = []
735
+ while tok = pp_ctxt.next_token
736
+ if tok.type == :NEW_LINE
742
737
  break
743
738
  else
744
- extra_tokens.push(token)
739
+ extra_toks.push(tok)
745
740
  end
746
741
  end
747
- notify_extra_tokens_found(extra_tokens) unless extra_tokens.empty?
742
+ notify_extra_tokens_found(extra_toks) unless extra_toks.empty?
748
743
  end
749
744
 
750
- def create_lexer(context, source)
751
- Lexer.new(source).tap { |lexer| attach_lexer_plugin(lexer, context) }
745
+ def create_lexer(pp_ctxt, src)
746
+ Lexer.new(src, pp_ctxt.traits).tap { |lexer| attach_lexer_plugin(lexer) }
752
747
  end
753
748
 
754
- def attach_lexer_plugin(lexer, context)
749
+ def attach_lexer_plugin(lexer)
755
750
  lexer.on_block_comment_found +=
756
751
  lambda { |*args| on_block_comment_found.invoke(*args) }
757
752
  lexer.on_line_comment_found +=
@@ -772,12 +767,12 @@ module Cpp #:nodoc:
772
767
  lambda { |*args| on_illformed_newline_escape_found.invoke(*args) }
773
768
  end
774
769
 
775
- def notify_user_header_included(user_include_line, user_header)
776
- on_user_header_included.invoke(user_include_line, user_header)
770
+ def notify_user_header_included(usr_include_line, usr_header)
771
+ on_user_header_included.invoke(usr_include_line, usr_header)
777
772
  end
778
773
 
779
- def notify_system_header_included(system_include_line, system_header)
780
- on_system_header_included.invoke(system_include_line, system_header)
774
+ def notify_system_header_included(sys_include_line, sys_header)
775
+ on_system_header_included.invoke(sys_include_line, sys_header)
781
776
  end
782
777
 
783
778
  def notify_object_like_macro_defined(define_line, macro)
@@ -804,75 +799,79 @@ module Cpp #:nodoc:
804
799
  on_unknown_pragma_evaled.invoke(pragma_line)
805
800
  end
806
801
 
807
- def notify_pp_token_extracted(pp_token)
808
- on_pp_token_extracted.invoke(pp_token)
802
+ def notify_pp_token_extracted(pp_tok)
803
+ on_pp_token_extracted.invoke(pp_tok)
809
804
  end
810
805
 
811
- def notify_illformed_defined_op_found(location, no_args)
812
- on_illformed_defined_op_found.invoke(location, no_args)
806
+ def notify_illformed_defined_op_found(loc, no_args)
807
+ on_illformed_defined_op_found.invoke(loc, no_args)
813
808
  end
814
809
 
815
- def notify_undefined_macro_referred(identifier)
816
- on_undefined_macro_referred.invoke(identifier)
810
+ def notify_undefined_macro_referred(id)
811
+ on_undefined_macro_referred.invoke(id)
817
812
  end
818
813
 
819
- def notify_extra_tokens_found(extra_tokens)
820
- on_extra_tokens_found.invoke(extra_tokens)
814
+ def notify_extra_tokens_found(extra_toks)
815
+ on_extra_tokens_found.invoke(extra_toks)
821
816
  end
822
817
 
823
- def handle_unterminated_block_comment(context, location)
824
- E(:E0016, location)
825
- raise UnterminatedCommentError.new(location,
826
- context.msg_fpath, context.log_fpath)
818
+ def handle_unterminated_block_comment(pp_ctxt, loc)
819
+ E(:E0016, loc)
820
+ raise UnterminatedCommentError.new(loc, pp_ctxt.msg_fpath,
821
+ pp_ctxt.log_fpath)
827
822
  end
828
823
 
829
- def report
830
- @context.report
831
- end
824
+ extend Forwardable
825
+
826
+ def_delegator :@pp_ctxt, :report
827
+ private :report
828
+
829
+ def_delegator :@pp_ctxt, :message_catalog
830
+ private :message_catalog
831
+
832
+ def_delegator :@pp_ctxt, :logger
833
+ private :logger
832
834
  end
833
835
 
834
836
  class PreprocessContext
835
- def initialize(phase_context)
836
- @phase_context = phase_context
837
+ def initialize(phase_ctxt)
838
+ @phase_ctxt = phase_ctxt
837
839
  @deferred_text_lines = []
838
- @lexer_stack = []
839
- @branch_stack = []
840
- @once_set = Set.new
840
+ @lexer_stack = []
841
+ @branch_stack = []
842
+ @once_set = Set.new
841
843
  end
842
844
 
843
845
  attr_reader :deferred_text_lines
844
846
  attr_reader :once_set
845
847
 
846
- def translation_unit_fpath
847
- @phase_context[:sources].first.fpath
848
+ extend Forwardable
849
+
850
+ def_delegator :@phase_ctxt, :traits
851
+ def_delegator :@phase_ctxt, :message_catalog
852
+ def_delegator :@phase_ctxt, :report
853
+ def_delegator :@phase_ctxt, :logger
854
+ def_delegator :@phase_ctxt, :msg_fpath
855
+ def_delegator :@phase_ctxt, :log_fpath
856
+
857
+ def tunit_root_fpath
858
+ @phase_ctxt[:sources].first.fpath
848
859
  end
849
860
 
850
861
  def source
851
- @phase_context[:c_source]
862
+ @phase_ctxt[:cc1_source]
852
863
  end
853
864
 
854
865
  def sources
855
- @phase_context[:sources]
866
+ @phase_ctxt[:sources]
856
867
  end
857
868
 
858
869
  def symbol_table
859
- @phase_context[:symbol_table]
870
+ @phase_ctxt[:symbol_table]
860
871
  end
861
872
 
862
873
  def macro_table
863
- @phase_context[:cpp_macro_table]
864
- end
865
-
866
- def report
867
- @phase_context.report
868
- end
869
-
870
- def msg_fpath
871
- @phase_context.msg_fpath
872
- end
873
-
874
- def log_fpath
875
- @phase_context.log_fpath
874
+ @phase_ctxt[:cpp_macro_table]
876
875
  end
877
876
 
878
877
  def push_lexer(lexer)
@@ -881,11 +880,11 @@ module Cpp #:nodoc:
881
880
 
882
881
  def top_token
883
882
  return nil if @lexer_stack.empty?
884
- unless token = @lexer_stack.last.top_token
883
+ unless tok = @lexer_stack.last.top_token
885
884
  @lexer_stack.pop
886
885
  top_token
887
886
  else
888
- token
887
+ tok
889
888
  end
890
889
  end
891
890
 
@@ -923,17 +922,17 @@ module Cpp #:nodoc:
923
922
  end
924
923
 
925
924
  module PPTokensNormalizer
926
- def normalize(pp_tokens, context)
927
- context.macro_table.replace(pp_tokens.tokens)
928
- pp_tokens
925
+ def normalize(pp_toks, pp_ctxt)
926
+ pp_ctxt.macro_table.replace(pp_toks.tokens)
927
+ pp_toks
929
928
  end
930
929
  module_function :normalize
931
930
  end
932
931
 
933
932
  module ExpressionNormalizer
934
- def normalize(pp_tokens, context, preprocessor = nil)
935
- PPTokensNormalizer.normalize(pp_tokens, context)
936
- const_expr = ConstantExpression.new(context, pp_tokens.tokens)
933
+ def normalize(pp_toks, pp_ctxt, preprocessor = nil)
934
+ PPTokensNormalizer.normalize(pp_toks, pp_ctxt)
935
+ const_expr = ConstantExpression.new(pp_ctxt, pp_toks.tokens)
937
936
  if preprocessor
938
937
  const_expr.on_illformed_defined_op_found +=
939
938
  preprocessor.method(:notify_illformed_defined_op_found)
@@ -946,72 +945,73 @@ module Cpp #:nodoc:
946
945
  end
947
946
 
948
947
  module TextLineNormalizer
949
- def normalize(text_line, context)
950
- pp_tokens = []
951
- unless context.deferred_text_lines.empty?
952
- context.deferred_text_lines.each do |deferred_line|
953
- lexer = TextLineToPPTokensLexer.new(deferred_line)
954
- pp_tokens += lexer.execute.to_a
948
+ def normalize(text_line, pp_ctxt)
949
+ tab_width = pp_ctxt.traits.of_project.coding_style.tab_width
950
+ pp_toks = []
951
+ unless pp_ctxt.deferred_text_lines.empty?
952
+ pp_ctxt.deferred_text_lines.each do |deferred_line|
953
+ lexer = TextLineToPPTokensLexer.new(deferred_line, tab_width)
954
+ pp_toks += lexer.execute.to_a
955
955
  end
956
956
  end
957
957
 
958
- lexer = TextLineToPPTokensLexer.new(text_line)
959
- pp_tokens += lexer.execute.to_a
958
+ lexer = TextLineToPPTokensLexer.new(text_line, tab_width)
959
+ pp_toks += lexer.execute.to_a
960
960
 
961
- function_like_macro_referred = pp_tokens.any? { |t|
962
- (macro = context.macro_table.lookup(t.value)) ?
961
+ fun_like_macro_referred = pp_toks.any? { |tok|
962
+ (macro = pp_ctxt.macro_table.lookup(tok.value)) ?
963
963
  macro.function_like? : false
964
964
  }
965
965
 
966
- if function_like_macro_referred
967
- return nil unless complete_macro_reference?(pp_tokens, context)
966
+ if fun_like_macro_referred
967
+ return nil unless complete_macro_reference?(pp_toks, pp_ctxt)
968
968
  end
969
969
 
970
- context.macro_table.replace(pp_tokens)
971
- pp_tokens
970
+ pp_ctxt.macro_table.replace(pp_toks)
971
+ pp_toks
972
972
  end
973
973
  module_function :normalize
974
974
 
975
- def complete_macro_reference?(pp_tokens, context)
976
- index = 0
977
- while token = pp_tokens[index]
978
- index += 1
979
- macro = context.macro_table.lookup(token.value)
975
+ def complete_macro_reference?(pp_toks, pp_ctxt)
976
+ idx = 0
977
+ while tok = pp_toks[idx]
978
+ idx += 1
979
+ macro = pp_ctxt.macro_table.lookup(tok.value)
980
980
  if macro && macro.function_like?
981
- next if not_calling_function_like_macro?(pp_tokens, index)
981
+ next if not_calling_function_like_macro?(pp_toks, idx)
982
982
  else
983
983
  next
984
984
  end
985
985
 
986
986
  # NOTE: It's not completed when a new-line appears after the macro
987
987
  # name.
988
- return false unless pp_tokens[index..-1].any? { |t| t.value == "(" }
988
+ return false unless pp_toks[idx..-1].any? { |t| t.value == "(" }
989
989
 
990
- paren_count = 0
991
- while token = pp_tokens[index]
992
- case token.value
990
+ paren_cnt = 0
991
+ while tok = pp_toks[idx]
992
+ case tok.value
993
993
  when "("
994
- paren_count += 1
994
+ paren_cnt += 1
995
995
  when ")"
996
- paren_count -= 1
997
- break if paren_count == 0
996
+ paren_cnt -= 1
997
+ break if paren_cnt == 0
998
998
  end
999
- index += 1
999
+ idx += 1
1000
1000
  end
1001
1001
 
1002
- return false if paren_count > 0
1002
+ return false if paren_cnt > 0
1003
1003
  end
1004
1004
  true
1005
1005
  end
1006
1006
  module_function :complete_macro_reference?
1007
1007
 
1008
- def not_calling_function_like_macro?(pp_tokens, index)
1009
- while pp_token = pp_tokens[index]
1008
+ def not_calling_function_like_macro?(pp_toks, idx)
1009
+ while pp_tok = pp_toks[idx]
1010
1010
  case
1011
- when pp_token.value == "("
1011
+ when pp_tok.value == "("
1012
1012
  return false
1013
- when pp_token.type == :NEW_LINE
1014
- index += 1
1013
+ when pp_tok.type == :NEW_LINE
1014
+ idx += 1
1015
1015
  else
1016
1016
  return true
1017
1017
  end