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.
- data/AUTHORS +1 -3
- data/ChangeLog +511 -0
- data/INSTALL +1 -1
- data/MANIFEST +57 -37
- data/NEWS +36 -7
- data/README +2 -2
- data/Rakefile +6 -6
- data/TODO +1 -1
- data/bin/adlint +25 -16
- data/bin/adlint_chk +22 -12
- data/bin/adlint_cma +17 -12
- data/bin/adlint_sma +22 -12
- data/bin/adlintize +98 -17
- data/etc/conf.d/fallback/cinit.erb +1 -1
- data/etc/conf.d/fallback/traits.erb +37 -37
- data/etc/conf.d/i686-cygwin/cinit-gcc_4.3.4.erb +1 -1
- data/etc/conf.d/i686-cygwin/traits-gcc_4.3.4.erb +41 -41
- data/etc/conf.d/i686-devkit/cinit-gcc_4.5.2.erb +1 -1
- data/etc/conf.d/i686-devkit/traits-gcc_4.5.2.erb +40 -40
- data/etc/conf.d/i686-linux/cinit-gcc_4.5.1.erb +1 -1
- data/etc/conf.d/i686-linux/traits-gcc_4.5.1.erb +40 -40
- data/etc/conf.d/i686-mingw/cinit-gcc_4.6.1.erb +1 -1
- data/etc/conf.d/i686-mingw/traits-gcc_4.6.1.erb +40 -40
- data/etc/conf.d/noarch/GNUmakefile.erb +1 -1
- data/etc/conf.d/noarch/adlint_all_bat.erb +1 -1
- data/etc/conf.d/noarch/adlint_all_sh.erb +1 -1
- data/etc/conf.d/noarch/pinit.erb +1 -1
- data/etc/conf.d/x86_64-ubuntu_12.04/cinit-gcc_4.6.3.erb +1 -1
- data/etc/conf.d/x86_64-ubuntu_12.04/traits-gcc_4.6.3.erb +42 -42
- data/etc/mesg.d/c_builtin/en_US/messages.yml +33 -33
- data/etc/mesg.d/c_builtin/ja_JP/messages.yml +5 -5
- data/etc/mesg.d/core/en_US/messages.yml +2 -2
- data/etc/mesg.d/core/ja_JP/messages.yml +2 -2
- data/features/code_check/W0018.feature +197 -0
- data/features/code_check/W0019.feature +79 -0
- data/features/code_check/W0021.feature +81 -0
- data/features/code_check/W0023.feature +203 -0
- data/features/code_check/W0024.feature +226 -0
- data/features/code_check/W0025.feature +5 -0
- data/features/code_check/W0088.feature +2 -2
- data/features/code_check/W0109.feature +2 -2
- data/features/code_check/W0477.feature +0 -3
- data/features/code_check/W0478.feature +0 -1
- data/features/code_check/W0582.feature +3 -3
- data/features/code_check/W0583.feature +4 -7
- data/features/code_check/W0646.feature +0 -1
- data/features/code_check/W0695.feature +0 -1
- data/features/code_check/W0705.feature +8 -0
- data/features/code_check/W0723.feature +0 -1
- data/features/code_check/W0745.feature +1 -0
- data/features/code_check/W0781.feature +1 -0
- data/features/code_check/W1057.feature +141 -0
- data/features/code_check/W1058.feature +93 -0
- data/features/code_check/W1059.feature +86 -0
- data/features/code_check/W1060.feature +77 -0
- data/features/code_check/W1061.feature +143 -0
- data/features/code_check/W1062.feature +162 -0
- data/features/code_check/W1063.feature +123 -0
- data/features/code_check/W1064.feature +83 -0
- data/features/code_check/W1065.feature +82 -0
- data/features/code_check/W9003.feature +2 -0
- data/features/step_definitions/code_check_steps.rb +1 -0
- data/features/support/env.rb +16 -13
- data/lib/adlint.rb +7 -4
- data/lib/adlint/analyzer.rb +131 -157
- data/lib/adlint/annot.rb +149 -0
- data/lib/adlint/cc1.rb +57 -0
- data/lib/adlint/{c → cc1}/branch.rb +74 -62
- data/lib/adlint/{c → cc1}/builtin.rb +21 -21
- data/lib/adlint/{c → cc1}/const.rb +119 -117
- data/lib/adlint/{c → cc1}/conv.rb +76 -78
- data/lib/adlint/{c → cc1}/ctrlexpr.rb +69 -86
- data/lib/adlint/cc1/domain.rb +8103 -0
- data/lib/adlint/{c → cc1}/enum.rb +3 -3
- data/lib/adlint/{c → cc1}/environ.rb +21 -21
- data/lib/adlint/{c → cc1}/expr.rb +232 -218
- data/lib/adlint/{c → cc1}/format.rb +305 -342
- data/lib/adlint/{c → cc1}/interp.rb +269 -220
- data/lib/adlint/cc1/lexer.rb +246 -0
- data/lib/adlint/{c → cc1}/mediator.rb +78 -84
- data/lib/adlint/{c → cc1}/object.rb +261 -264
- data/lib/adlint/{c → cc1}/operator.rb +7 -7
- data/lib/adlint/{c → cc1}/option.rb +4 -3
- data/lib/adlint/{c → cc1}/parser.rb +274 -506
- data/lib/adlint/{c → cc1}/parser.y +69 -301
- data/lib/adlint/cc1/phase.rb +138 -0
- data/lib/adlint/{c → cc1}/resolver.rb +66 -78
- data/lib/adlint/{c → cc1}/scanner.rb +57 -49
- data/lib/adlint/{c → cc1}/scope.rb +3 -3
- data/lib/adlint/{c → cc1}/seqp.rb +13 -5
- data/lib/adlint/{c → cc1}/syntax.rb +819 -1122
- data/lib/adlint/{c → cc1}/type.rb +1498 -1479
- data/lib/adlint/{c → cc1}/util.rb +20 -12
- data/lib/adlint/{c → cc1}/value.rb +699 -642
- data/lib/adlint/code.rb +163 -164
- data/lib/adlint/cpp.rb +2 -2
- data/lib/adlint/cpp/asm.rb +13 -14
- data/lib/adlint/cpp/constexpr.rb +42 -38
- data/lib/adlint/cpp/constexpr.y +44 -40
- data/lib/adlint/cpp/eval.rb +435 -435
- data/lib/adlint/cpp/lexer.rb +343 -340
- data/lib/adlint/cpp/macro.rb +188 -190
- data/lib/adlint/cpp/phase.rb +66 -45
- data/lib/adlint/cpp/scanner.rb +14 -17
- data/lib/adlint/cpp/source.rb +49 -55
- data/lib/adlint/cpp/subst.rb +65 -65
- data/lib/adlint/cpp/syntax.rb +155 -275
- data/lib/adlint/cpp/util.rb +22 -19
- data/lib/adlint/driver.rb +86 -93
- data/lib/adlint/error.rb +33 -52
- data/lib/adlint/exam.rb +158 -24
- data/lib/adlint/exam/c_builtin.rb +7 -7
- data/lib/adlint/exam/c_builtin/cc1_check.rb +20522 -0
- data/lib/adlint/exam/c_builtin/cc1_check_shima.rb +957 -0
- data/lib/adlint/exam/c_builtin/cc1_code.rb +459 -0
- data/lib/adlint/exam/c_builtin/cc1_metric.rb +794 -0
- data/lib/adlint/exam/c_builtin/cpp_check.rb +486 -441
- data/lib/adlint/exam/c_builtin/cpp_check_shima.rb +36 -39
- data/lib/adlint/exam/c_builtin/cpp_code.rb +63 -65
- data/lib/adlint/exam/c_builtin/ld_check.rb +136 -129
- data/lib/adlint/exam/c_builtin/ld_metric.rb +11 -11
- data/lib/adlint/lang.rb +25 -25
- data/lib/adlint/ld.rb +2 -2
- data/lib/adlint/ld/object.rb +220 -188
- data/lib/adlint/ld/phase.rb +94 -63
- data/lib/adlint/ld/typedef.rb +22 -11
- data/lib/adlint/ld/util.rb +43 -35
- data/lib/adlint/lexer.rb +59 -56
- data/lib/adlint/location.rb +140 -0
- data/lib/adlint/memo.rb +157 -0
- data/lib/adlint/message.rb +207 -156
- data/lib/adlint/metric.rb +139 -217
- data/lib/adlint/monitor.rb +45 -43
- data/lib/adlint/phase.rb +56 -29
- data/lib/adlint/prelude.rb +66 -54
- data/lib/adlint/report.rb +253 -332
- data/lib/adlint/source.rb +26 -27
- data/lib/adlint/supp.rb +131 -0
- data/lib/adlint/symbol.rb +14 -16
- data/lib/adlint/token.rb +19 -91
- data/lib/adlint/traits.rb +242 -226
- data/lib/adlint/util.rb +116 -205
- data/lib/adlint/version.rb +8 -8
- data/share/HEADER +2 -2
- data/share/doc/developers_guide_ja.html +148 -19
- data/share/doc/developers_guide_ja.texi +141 -11
- data/share/doc/samples/GNUmakefile +1 -1
- data/share/doc/samples/adlint_traits.yml +45 -36
- data/share/doc/users_guide_en.html +1321 -1252
- data/share/doc/users_guide_en.texi +475 -408
- data/share/doc/users_guide_ja.html +1932 -1878
- data/share/doc/users_guide_ja.texi +324 -273
- data/share/sample/bison-2.5/adlint/GNUmakefile +5 -1
- data/share/sample/bison-2.5/adlint/adlint_traits.yml +38 -38
- data/share/sample/bison-2.5/adlint/lib/GNUmakefile +1 -1
- data/share/sample/bison-2.5/adlint/lib/adlint_cinit.h +1 -1
- data/share/sample/bison-2.5/adlint/lib/adlint_pinit.h +1 -1
- data/share/sample/bison-2.5/adlint/lib/adlint_traits.yml +50 -42
- data/share/sample/bison-2.5/adlint/src/GNUmakefile +1 -1
- data/share/sample/bison-2.5/adlint/src/adlint_cinit.h +1 -1
- data/share/sample/bison-2.5/adlint/src/adlint_pinit.h +1 -1
- data/share/sample/bison-2.5/adlint/src/adlint_traits.yml +50 -42
- data/share/sample/ctags-5.8/adlint/GNUmakefile +1 -1
- data/share/sample/ctags-5.8/adlint/adlint_cinit.h +1 -1
- data/share/sample/ctags-5.8/adlint/adlint_pinit.h +1 -1
- data/share/sample/ctags-5.8/adlint/adlint_traits.yml +50 -42
- data/share/sample/flex-2.5.35/adlint/GNUmakefile +1 -1
- data/share/sample/flex-2.5.35/adlint/adlint_cinit.h +1 -1
- data/share/sample/flex-2.5.35/adlint/adlint_pinit.h +1 -1
- data/share/sample/flex-2.5.35/adlint/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/adlint_traits.yml +46 -38
- data/share/sample/ruby-1.9.3-p0/adlint/core/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/core/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/core/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/core/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/enc-trans/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/enc-trans/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/enc-trans/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/enc-trans/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/enc/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/enc/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/enc/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/enc/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-bigdecimal/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-bigdecimal/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-bigdecimal/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-bigdecimal/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-continuation/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-continuation/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-continuation/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-continuation/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-coverage/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-coverage/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-coverage/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-coverage/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-curses/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-curses/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-curses/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-curses/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-date/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-date/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-date/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-date/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-dbm/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-dbm/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-dbm/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-dbm/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-bubblebabble/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-bubblebabble/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-bubblebabble/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-bubblebabble/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-md5/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-md5/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-md5/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-md5/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-rmd160/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-rmd160/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-rmd160/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-rmd160/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha1/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha1/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha1/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha1/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha2/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha2/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha2/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha2/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-dl-callback/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-dl-callback/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-dl-callback/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-dl-callback/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-dl/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-dl/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-dl/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-dl/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-etc/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-etc/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-etc/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-etc/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-fcntl/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-fcntl/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-fcntl/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-fcntl/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-fiber/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-fiber/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-fiber/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-fiber/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-fiddle/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-fiddle/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-fiddle/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-fiddle/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-gdbm/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-gdbm/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-gdbm/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-gdbm/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-iconv/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-iconv/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-iconv/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-iconv/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-io-console/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-io-console/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-io-console/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-io-console/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-io-nonblock/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-io-nonblock/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-io-nonblock/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-io-nonblock/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-io-wait/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-io-wait/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-io-wait/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-io-wait/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-json-generator/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-json-generator/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-json-generator/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-json-generator/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-json-parser/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-json-parser/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-json-parser/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-json-parser/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-complex/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-complex/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-complex/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-complex/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-rational/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-rational/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-rational/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-rational/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-nkf/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-nkf/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-nkf/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-nkf/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-openssl/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-openssl/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-openssl/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-openssl/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-pathname/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-pathname/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-pathname/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-pathname/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-psych/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-psych/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-psych/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-psych/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-pty/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-pty/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-pty/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-pty/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-racc-cparse/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-racc-cparse/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-racc-cparse/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-racc-cparse/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-readline/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-readline/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-readline/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-readline/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-ripper/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-ripper/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-ripper/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-ripper/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-sdbm/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-sdbm/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-sdbm/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-sdbm/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-socket/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-socket/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-socket/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-socket/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-stringio/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-stringio/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-stringio/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-stringio/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-strscan/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-strscan/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-strscan/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-strscan/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-syck/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-syck/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-syck/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-syck/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-syslog/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-syslog/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-syslog/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-syslog/adlint_traits.yml +50 -42
- data/share/sample/ruby-1.9.3-p0/adlint/ext-zlib/GNUmakefile +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-zlib/adlint_cinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-zlib/adlint_pinit.h +1 -1
- data/share/sample/ruby-1.9.3-p0/adlint/ext-zlib/adlint_traits.yml +50 -42
- data/share/sample/screen-4.0.3/adlint/GNUmakefile +1 -1
- data/share/sample/screen-4.0.3/adlint/adlint_cinit.h +1 -1
- data/share/sample/screen-4.0.3/adlint/adlint_pinit.h +1 -1
- data/share/sample/screen-4.0.3/adlint/adlint_traits.yml +50 -42
- data/share/sample/vim-7.3/adlint/vim/GNUmakefile +1 -1
- data/share/sample/vim-7.3/adlint/vim/adlint_cinit.h +1 -1
- data/share/sample/vim-7.3/adlint/vim/adlint_pinit.h +1 -1
- data/share/sample/vim-7.3/adlint/vim/adlint_traits.yml +50 -42
- data/share/sample/vim-7.3/adlint/xxd/GNUmakefile +1 -1
- data/share/sample/vim-7.3/adlint/xxd/adlint_cinit.h +1 -1
- data/share/sample/vim-7.3/adlint/xxd/adlint_pinit.h +1 -1
- data/share/sample/vim-7.3/adlint/xxd/adlint_traits.yml +49 -41
- data/share/sample/zsh-4.3.15/adlint/GNUmakefile +1 -1
- data/share/sample/zsh-4.3.15/adlint/adlint_traits.yml +46 -38
- data/share/sample/zsh-4.3.15/adlint/builtins/GNUmakefile +1 -1
- data/share/sample/zsh-4.3.15/adlint/builtins/adlint_cinit.h +1 -1
- data/share/sample/zsh-4.3.15/adlint/builtins/adlint_pinit.h +1 -1
- data/share/sample/zsh-4.3.15/adlint/builtins/adlint_traits.yml +50 -42
- data/share/sample/zsh-4.3.15/adlint/core/GNUmakefile +1 -1
- data/share/sample/zsh-4.3.15/adlint/core/adlint_cinit.h +1 -1
- data/share/sample/zsh-4.3.15/adlint/core/adlint_pinit.h +1 -1
- data/share/sample/zsh-4.3.15/adlint/core/adlint_traits.yml +50 -42
- data/share/sample/zsh-4.3.15/adlint/modules/GNUmakefile +1 -1
- data/share/sample/zsh-4.3.15/adlint/modules/adlint_cinit.h +1 -1
- data/share/sample/zsh-4.3.15/adlint/modules/adlint_pinit.h +1 -1
- data/share/sample/zsh-4.3.15/adlint/modules/adlint_traits.yml +50 -42
- data/share/sample/zsh-4.3.15/adlint/zle/GNUmakefile +1 -1
- data/share/sample/zsh-4.3.15/adlint/zle/adlint_cinit.h +1 -1
- data/share/sample/zsh-4.3.15/adlint/zle/adlint_pinit.h +1 -1
- data/share/sample/zsh-4.3.15/adlint/zle/adlint_traits.yml +50 -42
- data/spec/adlint/{c → cc1}/ctrlexpr_spec.rb +51 -49
- data/spec/adlint/{c → cc1}/domain_spec.rb +210 -179
- data/spec/adlint/{c → cc1}/operator_spec.rb +3 -3
- data/spec/adlint/{c → cc1}/syntax_spec.rb +10 -12
- data/spec/adlint/{c → cc1}/type_spec.rb +61 -68
- data/{lib/adlint/c.rb → spec/adlint/location_spec.rb} +24 -29
- data/spec/conf.d/default_traits.yml +38 -37
- data/spec/conf.d/empty_cinit.h +1 -1
- data/spec/conf.d/empty_pinit.h +1 -1
- data/spec/conf.d/project/foo.c +0 -0
- data/spec/spec_helper.rb +2 -2
- metadata +60 -40
- data/lib/adlint/c/domain.rb +0 -7931
- data/lib/adlint/c/lexer.rb +0 -252
- data/lib/adlint/c/phase.rb +0 -135
- data/lib/adlint/exam/c_builtin/c_check.rb +0 -20745
- data/lib/adlint/exam/c_builtin/c_check_shima.rb +0 -983
- data/lib/adlint/exam/c_builtin/c_code.rb +0 -477
- data/lib/adlint/exam/c_builtin/c_metric.rb +0 -818
data/lib/adlint/cpp/lexer.rb
CHANGED
|
@@ -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-
|
|
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-
|
|
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(
|
|
41
|
-
|
|
42
|
-
on_cr_at_eol_found.invoke(
|
|
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
|
-
|
|
45
|
-
on_eof_mark_at_eof_found.invoke(
|
|
44
|
+
src.on_eof_mark_at_eof_found += lambda { |loc|
|
|
45
|
+
on_eof_mark_at_eof_found.invoke(loc)
|
|
46
46
|
}
|
|
47
|
-
|
|
47
|
+
src.on_eof_newline_not_found += method(:notify_eof_newline_not_found)
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
@
|
|
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
|
-
|
|
71
|
+
tok = @top_token
|
|
71
72
|
@top_token = nil
|
|
72
|
-
return
|
|
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
|
-
|
|
108
|
+
loc = @content.location
|
|
108
109
|
comment = scan_block_comment(@content)
|
|
109
110
|
unless comment.empty?
|
|
110
|
-
notify_block_comment_found(comment,
|
|
111
|
+
notify_block_comment_found(comment, loc)
|
|
111
112
|
return true
|
|
112
113
|
end
|
|
113
114
|
when @content.check(/\/\//)
|
|
114
|
-
|
|
115
|
+
loc = @content.location
|
|
115
116
|
comment = scan_line_comment(@content)
|
|
116
117
|
unless comment.empty?
|
|
117
|
-
notify_line_comment_found(comment,
|
|
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,
|
|
129
|
-
on_block_comment_found.invoke(comment,
|
|
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,
|
|
133
|
-
on_line_comment_found.invoke(comment,
|
|
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(
|
|
137
|
-
on_nested_block_comment_found.invoke(
|
|
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(
|
|
141
|
-
on_unterminated_block_comment.invoke(
|
|
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(
|
|
145
|
-
on_eof_newline_not_found.invoke(
|
|
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,
|
|
149
|
-
on_unlexable_char_found.invoke(char,
|
|
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(
|
|
153
|
-
on_illformed_newline_escape_found.invoke(
|
|
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(
|
|
162
|
-
|
|
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(
|
|
166
|
-
|
|
166
|
+
def scan_block_comment(cont)
|
|
167
|
+
comment = ""
|
|
167
168
|
block_depth = 0
|
|
168
|
-
until
|
|
169
|
-
|
|
169
|
+
until cont.empty?
|
|
170
|
+
loc = cont.location
|
|
170
171
|
case
|
|
171
|
-
when
|
|
172
|
+
when cont.scan(/\/\*/)
|
|
172
173
|
block_depth += 1
|
|
173
|
-
|
|
174
|
-
notify_nested_block_comment_found(
|
|
175
|
-
when
|
|
176
|
-
|
|
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
|
|
181
|
-
|
|
181
|
+
if scanned = cont.scan(/.*?(?=\/\*|\*\/)/m)
|
|
182
|
+
comment += scanned
|
|
182
183
|
else
|
|
183
|
-
notify_unterminated_block_comment(
|
|
184
|
+
notify_unterminated_block_comment(loc)
|
|
184
185
|
end
|
|
185
186
|
end
|
|
186
187
|
end
|
|
187
|
-
|
|
188
|
+
comment
|
|
188
189
|
end
|
|
189
190
|
|
|
190
|
-
def scan_line_comment(
|
|
191
|
-
|
|
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(
|
|
210
|
-
|
|
210
|
+
def scan_escaped_newline(cont)
|
|
211
|
+
loc = cont.location
|
|
211
212
|
case
|
|
212
|
-
when
|
|
213
|
-
|
|
214
|
-
when
|
|
215
|
-
@lexer.notify_illformed_newline_escape_found(
|
|
216
|
-
|
|
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(
|
|
223
|
-
|
|
223
|
+
def tokenize_pp_token(cont)
|
|
224
|
+
loc = cont.location
|
|
224
225
|
case
|
|
225
|
-
when
|
|
226
|
-
|
|
227
|
-
Token.new(:PP_TOKEN,
|
|
228
|
-
when
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
Token.new(:PP_TOKEN,
|
|
232
|
-
when
|
|
233
|
-
Token.new(:PP_TOKEN,
|
|
234
|
-
when
|
|
235
|
-
Token.new(:PP_TOKEN,
|
|
236
|
-
when
|
|
237
|
-
Token.new(:PP_TOKEN,
|
|
238
|
-
when
|
|
239
|
-
Token.new(:PP_TOKEN,
|
|
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(
|
|
246
|
-
|
|
247
|
-
if
|
|
248
|
-
return Token.new(:NEW_LINE,
|
|
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(
|
|
254
|
-
|
|
255
|
-
if
|
|
256
|
-
return Token.new(:SYS_HEADER_NAME,
|
|
257
|
-
elsif
|
|
258
|
-
return Token.new(:USR_HEADER_NAME,
|
|
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(
|
|
264
|
-
|
|
265
|
-
if
|
|
266
|
-
return Token.new(:IDENTIFIER,
|
|
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(
|
|
272
|
-
|
|
273
|
-
if punctuator = Language::Cpp.scan_punctuator(
|
|
274
|
-
return Token.new(punctuator, punctuator,
|
|
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(
|
|
280
|
+
def tokenize_extra_token(cont)
|
|
280
281
|
# NOTE: #tokenize_pp_token can tokenize almost all types of tokens.
|
|
281
|
-
if
|
|
282
|
-
Token.new(:EXTRA_TOKEN,
|
|
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
|
|
299
|
+
when tok = tokenize_if_directive(@lexer.content)
|
|
299
300
|
@lexer.transit(InIfDirective.new(@lexer))
|
|
300
|
-
when
|
|
301
|
+
when tok = tokenize_ifdef_directive(@lexer.content)
|
|
301
302
|
@lexer.transit(InIfdefDirective.new(@lexer))
|
|
302
|
-
when
|
|
303
|
+
when tok = tokenize_ifndef_directive(@lexer.content)
|
|
303
304
|
@lexer.transit(InIfndefDirective.new(@lexer))
|
|
304
|
-
when
|
|
305
|
+
when tok = tokenize_elif_directive(@lexer.content)
|
|
305
306
|
@lexer.transit(InElifDirective.new(@lexer))
|
|
306
|
-
when
|
|
307
|
+
when tok = tokenize_else_directive(@lexer.content)
|
|
307
308
|
@lexer.transit(InElseDirective.new(@lexer))
|
|
308
|
-
when
|
|
309
|
+
when tok = tokenize_endif_directive(@lexer.content)
|
|
309
310
|
@lexer.transit(InEndifDirective.new(@lexer))
|
|
310
|
-
when
|
|
311
|
+
when tok = tokenize_include_directive(@lexer.content)
|
|
311
312
|
@lexer.transit(InIncludeDirective.new(@lexer))
|
|
312
|
-
when
|
|
313
|
+
when tok = tokenize_include_next_directive(@lexer.content)
|
|
313
314
|
@lexer.transit(InIncludeNextDirective.new(@lexer))
|
|
314
|
-
when
|
|
315
|
+
when tok = tokenize_define_directive(@lexer.content)
|
|
315
316
|
@lexer.transit(InDefineDirective.new(@lexer))
|
|
316
|
-
when
|
|
317
|
+
when tok = tokenize_undef_directive(@lexer.content)
|
|
317
318
|
@lexer.transit(InUndefDirective.new(@lexer))
|
|
318
|
-
when
|
|
319
|
+
when tok = tokenize_line_directive(@lexer.content)
|
|
319
320
|
@lexer.transit(InLineDirective.new(@lexer))
|
|
320
|
-
when
|
|
321
|
+
when tok = tokenize_error_directive(@lexer.content)
|
|
321
322
|
@lexer.transit(InErrorDirective.new(@lexer))
|
|
322
|
-
when
|
|
323
|
+
when tok = tokenize_pragma_directive(@lexer.content)
|
|
323
324
|
@lexer.transit(InPragmaDirective.new(@lexer))
|
|
324
|
-
when
|
|
325
|
+
when tok = tokenize_asm_directive(@lexer.content)
|
|
325
326
|
@lexer.transit(InAsmDirective.new(@lexer))
|
|
326
|
-
when
|
|
327
|
+
when tok = tokenize_endasm_directive(@lexer.content)
|
|
327
328
|
@lexer.transit(InEndasmDirective.new(@lexer))
|
|
328
329
|
else
|
|
329
|
-
|
|
330
|
-
|
|
330
|
+
tok = tokenize_null_directive(@lexer.content) ||
|
|
331
|
+
tokenize_unknown_directive(@lexer.content)
|
|
331
332
|
end
|
|
332
333
|
else
|
|
333
|
-
|
|
334
|
+
tok = tokenize_text_line(@lexer.content)
|
|
334
335
|
end
|
|
335
336
|
|
|
336
|
-
|
|
337
|
+
tok
|
|
337
338
|
end
|
|
338
339
|
|
|
339
340
|
private
|
|
340
|
-
def tokenize_if_directive(
|
|
341
|
-
|
|
342
|
-
if
|
|
343
|
-
return Token.new(:IF,
|
|
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(
|
|
349
|
-
|
|
350
|
-
if
|
|
351
|
-
return Token.new(:IFDEF,
|
|
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(
|
|
357
|
-
|
|
358
|
-
if
|
|
359
|
-
return Token.new(:IFNDEF,
|
|
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(
|
|
365
|
-
|
|
366
|
-
if
|
|
367
|
-
return Token.new(:ELIF,
|
|
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(
|
|
373
|
-
|
|
374
|
-
if
|
|
375
|
-
return Token.new(:ELSE,
|
|
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(
|
|
381
|
-
|
|
382
|
-
if
|
|
383
|
-
return Token.new(:ENDIF,
|
|
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(
|
|
389
|
-
|
|
390
|
-
if
|
|
391
|
-
return Token.new(:INCLUDE,
|
|
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(
|
|
397
|
+
def tokenize_include_next_directive(cont)
|
|
397
398
|
# NOTE: #include_next directive is a GCC extension.
|
|
398
|
-
|
|
399
|
-
if
|
|
400
|
-
return Token.new(:INCLUDE_NEXT,
|
|
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(
|
|
406
|
-
|
|
407
|
-
if
|
|
408
|
-
return Token.new(:DEFINE,
|
|
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(
|
|
414
|
-
|
|
415
|
-
if
|
|
416
|
-
return Token.new(:UNDEF,
|
|
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(
|
|
422
|
-
|
|
423
|
-
if
|
|
424
|
-
return Token.new(:LINE,
|
|
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(
|
|
430
|
-
|
|
431
|
-
if
|
|
432
|
-
return Token.new(:ERROR,
|
|
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(
|
|
438
|
-
|
|
439
|
-
if
|
|
440
|
-
return Token.new(:PRAGMA,
|
|
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(
|
|
446
|
-
|
|
447
|
-
if
|
|
448
|
-
return Token.new(:ASM,
|
|
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(
|
|
454
|
-
|
|
455
|
-
if
|
|
456
|
-
return Token.new(:ENDASM,
|
|
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(
|
|
462
|
-
|
|
463
|
-
if
|
|
464
|
-
return Token.new(:NULL_DIRECTIVE,
|
|
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(
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
until
|
|
473
|
-
next if discard_heading_comments || scan_escaped_newline(
|
|
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 =
|
|
477
|
-
|
|
478
|
-
when str =
|
|
479
|
-
|
|
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,
|
|
484
|
+
Token.new(:UNKNOWN_DIRECTIVE, val, loc)
|
|
484
485
|
end
|
|
485
486
|
|
|
486
|
-
def tokenize_text_line(
|
|
487
|
-
|
|
488
|
-
|
|
487
|
+
def tokenize_text_line(cont)
|
|
488
|
+
loc = cont.location
|
|
489
|
+
val = ""
|
|
489
490
|
|
|
490
|
-
until
|
|
491
|
-
if
|
|
492
|
-
|
|
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
|
|
496
|
-
|
|
496
|
+
if tok = cont.scan(/\n/)
|
|
497
|
+
val += tok
|
|
497
498
|
break
|
|
498
499
|
end
|
|
499
500
|
|
|
500
|
-
next if scan_escaped_newline(
|
|
501
|
+
next if scan_escaped_newline(cont)
|
|
501
502
|
|
|
502
503
|
case
|
|
503
|
-
when
|
|
504
|
+
when cont.check(/\/\*/)
|
|
504
505
|
discard_heading_comments
|
|
505
|
-
when
|
|
506
|
+
when cont.check(/\/\//)
|
|
506
507
|
discard_heading_comments
|
|
507
|
-
when
|
|
508
|
-
string_literal = Language::C.scan_string_literal(
|
|
509
|
-
|
|
510
|
-
when
|
|
511
|
-
char_constant = Language::C.scan_char_constant(
|
|
512
|
-
|
|
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
|
-
|
|
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
|
-
|
|
528
|
-
|
|
529
|
-
|
|
528
|
+
tok = tokenize_pp_token(@lexer.content) ||
|
|
529
|
+
tokenize_new_line(@lexer.content) ||
|
|
530
|
+
tokenize_extra_token(@lexer.content)
|
|
530
531
|
|
|
531
|
-
if
|
|
532
|
+
if tok
|
|
532
533
|
break
|
|
533
534
|
else
|
|
534
535
|
@lexer.content.eat!
|
|
535
536
|
end
|
|
536
537
|
end
|
|
537
538
|
|
|
538
|
-
unless
|
|
539
|
-
|
|
540
|
-
@lexer.notify_eof_newline_not_found(
|
|
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
|
|
544
|
+
if tok.type == :NEW_LINE
|
|
544
545
|
@lexer.transit(Initial.new(@lexer))
|
|
545
546
|
end
|
|
546
547
|
|
|
547
|
-
|
|
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
|
-
|
|
559
|
-
|
|
560
|
-
|
|
559
|
+
tok = tokenize_identifier(@lexer.content) ||
|
|
560
|
+
tokenize_new_line(@lexer.content) ||
|
|
561
|
+
tokenize_extra_token(@lexer.content)
|
|
561
562
|
|
|
562
|
-
if
|
|
563
|
+
if tok
|
|
563
564
|
break
|
|
564
565
|
else
|
|
565
566
|
@lexer.content.eat!
|
|
566
567
|
end
|
|
567
568
|
end
|
|
568
569
|
|
|
569
|
-
unless
|
|
570
|
-
|
|
571
|
-
@lexer.notify_eof_newline_not_found(
|
|
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
|
|
575
|
+
if tok.type == :NEW_LINE
|
|
575
576
|
@lexer.transit(Initial.new(@lexer))
|
|
576
577
|
end
|
|
577
578
|
|
|
578
|
-
|
|
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
|
-
|
|
594
|
-
|
|
594
|
+
tok = tokenize_new_line(@lexer.content) ||
|
|
595
|
+
tokenize_extra_token(@lexer.content)
|
|
595
596
|
|
|
596
|
-
if
|
|
597
|
+
if tok
|
|
597
598
|
break
|
|
598
599
|
else
|
|
599
600
|
@lexer.content.eat!
|
|
600
601
|
end
|
|
601
602
|
end
|
|
602
603
|
|
|
603
|
-
unless
|
|
604
|
-
|
|
605
|
-
@lexer.notify_eof_newline_not_found(
|
|
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
|
|
609
|
+
if tok.type == :NEW_LINE
|
|
609
610
|
@lexer.transit(Initial.new(@lexer))
|
|
610
611
|
end
|
|
611
612
|
|
|
612
|
-
|
|
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
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
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
|
|
631
|
+
if tok
|
|
631
632
|
break
|
|
632
633
|
else
|
|
633
634
|
@lexer.content.eat!
|
|
634
635
|
end
|
|
635
636
|
end
|
|
636
637
|
|
|
637
|
-
unless
|
|
638
|
-
|
|
639
|
-
@lexer.notify_eof_newline_not_found(
|
|
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
|
|
643
|
+
if tok.type == :NEW_LINE
|
|
643
644
|
@lexer.transit(Initial.new(@lexer))
|
|
644
645
|
end
|
|
645
646
|
|
|
646
|
-
|
|
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
|
-
|
|
665
|
+
tok = @tokens.shift
|
|
665
666
|
@lexer.transit(Initial.new(@lexer)) if @tokens.empty?
|
|
666
|
-
|
|
667
|
+
tok
|
|
667
668
|
end
|
|
668
669
|
|
|
669
670
|
private
|
|
670
|
-
def tokenize_macro_name(
|
|
671
|
-
until
|
|
672
|
-
next if discard_heading_comments || scan_escaped_newline(
|
|
671
|
+
def tokenize_macro_name(cont)
|
|
672
|
+
until cont.empty?
|
|
673
|
+
next if discard_heading_comments || scan_escaped_newline(cont)
|
|
673
674
|
|
|
674
|
-
if
|
|
675
|
-
@tokens.push(
|
|
675
|
+
if tok = tokenize_identifier(cont)
|
|
676
|
+
@tokens.push(tok)
|
|
676
677
|
break
|
|
677
678
|
else
|
|
678
|
-
|
|
679
|
+
cont.eat!
|
|
679
680
|
end
|
|
680
681
|
end
|
|
681
682
|
|
|
682
|
-
return unless
|
|
683
|
+
return unless cont.check(/\(/)
|
|
683
684
|
|
|
684
685
|
paren_depth = 0
|
|
685
|
-
until
|
|
686
|
-
next if discard_heading_comments || scan_escaped_newline(
|
|
686
|
+
until cont.empty?
|
|
687
|
+
next if discard_heading_comments || scan_escaped_newline(cont)
|
|
687
688
|
|
|
688
|
-
if
|
|
689
|
-
@tokens.push(
|
|
689
|
+
if tok = tokenize_identifier(cont)
|
|
690
|
+
@tokens.push(tok)
|
|
690
691
|
next
|
|
691
692
|
end
|
|
692
693
|
|
|
693
|
-
if
|
|
694
|
-
@tokens.push(
|
|
695
|
-
case
|
|
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
|
|
706
|
-
@tokens.push(
|
|
706
|
+
if tok = tokenize_new_line(cont)
|
|
707
|
+
@tokens.push(tok)
|
|
707
708
|
break
|
|
708
709
|
end
|
|
709
710
|
|
|
710
|
-
|
|
711
|
+
cont.eat!
|
|
711
712
|
end
|
|
712
713
|
end
|
|
713
714
|
|
|
714
|
-
def tokenize_pp_tokens(
|
|
715
|
-
until
|
|
716
|
-
next if discard_heading_comments || scan_escaped_newline(
|
|
715
|
+
def tokenize_pp_tokens(cont)
|
|
716
|
+
until cont.empty?
|
|
717
|
+
next if discard_heading_comments || scan_escaped_newline(cont)
|
|
717
718
|
|
|
718
|
-
|
|
719
|
+
tok = tokenize_pp_token(cont) || tokenize_new_line(cont)
|
|
719
720
|
|
|
720
|
-
if
|
|
721
|
-
@tokens.push(
|
|
722
|
-
if
|
|
721
|
+
if tok
|
|
722
|
+
@tokens.push(tok)
|
|
723
|
+
if tok.type == :NEW_LINE
|
|
723
724
|
break
|
|
724
725
|
end
|
|
725
726
|
else
|
|
726
|
-
|
|
727
|
-
if eaten =
|
|
728
|
-
@lexer.notify_unlexable_char_found(eaten,
|
|
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
|
-
|
|
735
|
-
@lexer.notify_eof_newline_not_found(
|
|
736
|
-
@tokens.push(
|
|
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
|
|
756
|
-
|
|
761
|
+
def create_lexer_context(str)
|
|
762
|
+
lexer_ctxt = LexerContext.new(create_content(str))
|
|
757
763
|
|
|
758
|
-
class <<
|
|
764
|
+
class << lexer_ctxt
|
|
759
765
|
attr_accessor :last_symbol
|
|
760
766
|
end
|
|
761
767
|
|
|
762
|
-
|
|
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(
|
|
770
|
-
|
|
771
|
-
until
|
|
772
|
-
next if tokenize_pp_token(
|
|
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
|
-
|
|
775
|
-
if new_line =
|
|
776
|
-
|
|
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
|
-
|
|
785
|
+
lexer_ctxt.content.eat!
|
|
780
786
|
end
|
|
781
787
|
end
|
|
782
|
-
|
|
788
|
+
tok_ary
|
|
783
789
|
end
|
|
784
790
|
|
|
785
|
-
def tokenize_pp_token(
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
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
|
|
795
|
-
|
|
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(
|
|
803
|
-
|
|
808
|
+
def tokenize_keyword(lexer_ctxt)
|
|
809
|
+
loc = lexer_ctxt.location
|
|
804
810
|
|
|
805
|
-
keyword = Language::C.scan_keyword(
|
|
806
|
-
Language::Cpp.scan_keyword(
|
|
811
|
+
keyword = Language::C.scan_keyword(lexer_ctxt.content) ||
|
|
812
|
+
Language::Cpp.scan_keyword(lexer_ctxt.content)
|
|
807
813
|
|
|
808
814
|
if keyword
|
|
809
|
-
|
|
810
|
-
Token.new(:PP_TOKEN, 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(
|
|
817
|
-
|
|
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
|
|
826
|
+
return nil if lexer_ctxt.last_symbol == :IDENTIFIER
|
|
821
827
|
|
|
822
|
-
constant = Language::C.scan_char_constant(
|
|
823
|
-
Language::C.scan_floating_constant(
|
|
824
|
-
Language::C.scan_integer_constant(
|
|
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
|
-
|
|
828
|
-
return Token.new(:PP_TOKEN, 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(
|
|
835
|
-
|
|
840
|
+
def tokenize_string_literal(lexer_ctxt)
|
|
841
|
+
loc = lexer_ctxt.location
|
|
836
842
|
|
|
837
|
-
string_literal = Language::C.scan_string_literal(
|
|
843
|
+
string_literal = Language::C.scan_string_literal(lexer_ctxt.content)
|
|
838
844
|
|
|
839
845
|
if string_literal
|
|
840
|
-
|
|
841
|
-
return Token.new(:PP_TOKEN, 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(
|
|
848
|
-
|
|
853
|
+
def tokenize_null_constant(lexer_ctxt)
|
|
854
|
+
loc = lexer_ctxt.location
|
|
849
855
|
|
|
850
|
-
null_constant = Language::C.scan_null_constant(
|
|
856
|
+
null_constant = Language::C.scan_null_constant(lexer_ctxt.content)
|
|
851
857
|
|
|
852
858
|
if null_constant
|
|
853
|
-
|
|
854
|
-
return Token.new(:PP_TOKEN, null_constant,
|
|
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(
|
|
861
|
-
|
|
866
|
+
def tokenize_identifier(lexer_ctxt)
|
|
867
|
+
loc = lexer_ctxt.location
|
|
862
868
|
|
|
863
|
-
identifier = Language::C.scan_identifier(
|
|
869
|
+
identifier = Language::C.scan_identifier(lexer_ctxt.content)
|
|
864
870
|
|
|
865
871
|
if identifier
|
|
866
|
-
|
|
867
|
-
return Token.new(:PP_TOKEN, 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(
|
|
874
|
-
|
|
879
|
+
def tokenize_punctuator(lexer_ctxt)
|
|
880
|
+
loc = lexer_ctxt.location
|
|
875
881
|
|
|
876
|
-
punctuator = Language::Cpp.scan_punctuator(
|
|
882
|
+
punctuator = Language::Cpp.scan_punctuator(lexer_ctxt.content)
|
|
877
883
|
|
|
878
884
|
if punctuator
|
|
879
|
-
|
|
880
|
-
return Token.new(:PP_TOKEN, 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(
|
|
887
|
-
|
|
892
|
+
def tokenize_backslash(lexer_ctxt)
|
|
893
|
+
loc = lexer_ctxt.location
|
|
888
894
|
|
|
889
|
-
backslash =
|
|
895
|
+
backslash = lexer_ctxt.content.scan(/\\/)
|
|
890
896
|
|
|
891
897
|
if backslash
|
|
892
|
-
|
|
893
|
-
return Token.new(:PP_TOKEN, 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
|
|