adlint 2.6.14 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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.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-
|
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
|
#
|
data/lib/adlint/cpp/asm.rb
CHANGED
@@ -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-
|
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
|
#
|
@@ -35,20 +35,19 @@ module AdLint #:nodoc:
|
|
35
35
|
module Cpp #:nodoc:
|
36
36
|
|
37
37
|
module InlineAssemblyDefinition
|
38
|
-
def create_inline_assembly_substitutions(
|
39
|
-
[create_cxx_asm_definition(
|
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(
|
44
|
-
CodeSubstitution.new("asm(__adlint__any);", "").tap do |
|
45
|
-
|
46
|
-
|
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(
|
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 |
|
63
|
-
CodeSubstitution.new(
|
64
|
-
|
65
|
-
|
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
|
data/lib/adlint/cpp/constexpr.rb
CHANGED
@@ -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(
|
23
|
-
@
|
24
|
-
@
|
25
|
-
@
|
26
|
-
@fpath
|
27
|
-
@
|
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
|
-
@
|
37
|
-
if
|
38
|
-
|
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(
|
46
|
-
|
47
|
-
|
48
|
-
case
|
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
|
-
|
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
|
-
|
52
|
+
tok_queue.push(Token.new(:CONSTANT, tok.value, tok.location))
|
53
53
|
when /\AL?'.*'\z/i
|
54
|
-
|
54
|
+
tok_queue.push(Token.new(:CONSTANT, tok.value, tok.location))
|
55
55
|
when /\AL?".*"\z/i
|
56
|
-
|
56
|
+
tok_queue.push(Token.new(:CONSTANT, tok.value, tok.location))
|
57
57
|
when "(", ")", "+", "-", "~", "!", "*", "/", "%", "<<", ">>", "<", ">",
|
58
58
|
"<=", ">=", "==", "!=", "&", "^", "|", "&&", "||", "?", ":"
|
59
|
-
|
59
|
+
tok_queue.push(Token.new(tok.value, tok.value, tok.location))
|
60
60
|
when "defined"
|
61
|
-
|
61
|
+
tok_queue.push(Token.new(:DEFINED, tok.value, tok.location))
|
62
62
|
else
|
63
|
-
|
63
|
+
tok_queue.push(Token.new(:IDENTIFIER, tok.value, tok.location))
|
64
64
|
end
|
65
65
|
end
|
66
|
-
|
66
|
+
tok_queue
|
67
67
|
end
|
68
68
|
|
69
69
|
def next_token
|
70
|
-
(
|
70
|
+
(tok = @tok_queue.shift) ? [tok.type, tok] : nil
|
71
71
|
end
|
72
72
|
|
73
|
-
def on_error(
|
74
|
-
E(:E0007,
|
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
|
78
|
-
|
77
|
+
def loc_of(tok)
|
78
|
+
tok == "$" ? Location.new(@fpath, @lst_line_no) : tok.location
|
79
79
|
end
|
80
80
|
|
81
|
-
def
|
82
|
-
|
81
|
+
def val_of(tok)
|
82
|
+
tok == "$" ? "EOF" : tok.value
|
83
83
|
end
|
84
84
|
|
85
|
-
def notify_illformed_defined_operator(
|
86
|
-
on_illformed_defined_op_found.invoke(
|
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(
|
90
|
-
on_undefined_macro_referred.invoke(
|
89
|
+
def notify_undefined_macro_referred(id)
|
90
|
+
on_undefined_macro_referred.invoke(id)
|
91
91
|
end
|
92
92
|
|
93
|
-
|
94
|
-
|
95
|
-
|
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 = @
|
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 = @
|
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(
|
491
|
+
notify_illformed_defined_operator(loc_of(val[0]), val[1] == "$")
|
488
492
|
result = ErrorExpression.new(val[1])
|
489
493
|
|
490
494
|
result
|
data/lib/adlint/cpp/constexpr.y
CHANGED
@@ -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-
|
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
|
#
|
@@ -107,7 +107,7 @@ unary_expression
|
|
107
107
|
}
|
108
108
|
| DEFINED "(" IDENTIFIER ")"
|
109
109
|
{
|
110
|
-
if macro = @
|
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 = @
|
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(
|
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(
|
315
|
-
@
|
316
|
-
@
|
317
|
-
@
|
318
|
-
@fpath
|
319
|
-
@
|
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
|
-
@
|
329
|
-
if
|
330
|
-
|
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(
|
338
|
-
|
339
|
-
|
340
|
-
case
|
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
|
-
|
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
|
-
|
344
|
+
tok_queue.push(Token.new(:CONSTANT, tok.value, tok.location))
|
345
345
|
when /\AL?'.*'\z/i
|
346
|
-
|
346
|
+
tok_queue.push(Token.new(:CONSTANT, tok.value, tok.location))
|
347
347
|
when /\AL?".*"\z/i
|
348
|
-
|
348
|
+
tok_queue.push(Token.new(:CONSTANT, tok.value, tok.location))
|
349
349
|
when "(", ")", "+", "-", "~", "!", "*", "/", "%", "<<", ">>", "<", ">",
|
350
350
|
"<=", ">=", "==", "!=", "&", "^", "|", "&&", "||", "?", ":"
|
351
|
-
|
351
|
+
tok_queue.push(Token.new(tok.value, tok.value, tok.location))
|
352
352
|
when "defined"
|
353
|
-
|
353
|
+
tok_queue.push(Token.new(:DEFINED, tok.value, tok.location))
|
354
354
|
else
|
355
|
-
|
355
|
+
tok_queue.push(Token.new(:IDENTIFIER, tok.value, tok.location))
|
356
356
|
end
|
357
357
|
end
|
358
|
-
|
358
|
+
tok_queue
|
359
359
|
end
|
360
360
|
|
361
361
|
def next_token
|
362
|
-
(
|
362
|
+
(tok = @tok_queue.shift) ? [tok.type, tok] : nil
|
363
363
|
end
|
364
364
|
|
365
|
-
def on_error(
|
366
|
-
E(:E0007,
|
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
|
370
|
-
|
369
|
+
def loc_of(tok)
|
370
|
+
tok == "$" ? Location.new(@fpath, @lst_line_no) : tok.location
|
371
371
|
end
|
372
372
|
|
373
|
-
def
|
374
|
-
|
373
|
+
def val_of(tok)
|
374
|
+
tok == "$" ? "EOF" : tok.value
|
375
375
|
end
|
376
376
|
|
377
|
-
def notify_illformed_defined_operator(
|
378
|
-
on_illformed_defined_op_found.invoke(
|
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(
|
382
|
-
on_undefined_macro_referred.invoke(
|
381
|
+
def notify_undefined_macro_referred(id)
|
382
|
+
on_undefined_macro_referred.invoke(id)
|
383
383
|
end
|
384
384
|
|
385
|
-
|
386
|
-
|
387
|
-
|
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:
|
data/lib/adlint/cpp/eval.rb
CHANGED
@@ -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-
|
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
|
#
|
@@ -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(
|
52
|
-
@
|
53
|
-
|
54
|
-
preprocessing_file(
|
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(
|
82
|
-
PreprocessingFile.new(
|
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(
|
86
|
-
if group_part = group_part(
|
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(
|
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(
|
97
|
-
if
|
98
|
-
case
|
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(
|
102
|
+
return if_section(pp_ctxt)
|
101
103
|
when :INCLUDE, :INCLUDE_NEXT, :DEFINE, :UNDEF, :LINE, :ERROR, :PRAGMA
|
102
|
-
return control_line(
|
104
|
+
return control_line(pp_ctxt)
|
103
105
|
when :ASM
|
104
|
-
return asm_section(
|
106
|
+
return asm_section(pp_ctxt)
|
105
107
|
when :NULL_DIRECTIVE
|
106
|
-
return NullDirective.new(
|
108
|
+
return NullDirective.new(pp_ctxt.next_token)
|
107
109
|
when :UNKNOWN_DIRECTIVE
|
108
|
-
return UnknownDirective.new(
|
110
|
+
return UnknownDirective.new(pp_ctxt.next_token)
|
109
111
|
when :TEXT_LINE
|
110
|
-
text_line = TextLine.new(
|
111
|
-
|
112
|
-
if
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
notify_pp_token_extracted(
|
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
|
-
|
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(
|
128
|
-
|
129
|
-
if_group = if_group(
|
129
|
+
def if_section(pp_ctxt)
|
130
|
+
pp_ctxt.push_branch
|
131
|
+
if_group = if_group(pp_ctxt)
|
130
132
|
|
131
|
-
while
|
132
|
-
case
|
133
|
+
while top_tok = pp_ctxt.top_token
|
134
|
+
case top_tok.type
|
133
135
|
when :ELIF
|
134
|
-
elif_groups = elif_groups(
|
136
|
+
elif_groups = elif_groups(pp_ctxt)
|
135
137
|
when :ELSE
|
136
|
-
else_group = else_group(
|
138
|
+
else_group = else_group(pp_ctxt)
|
137
139
|
when :ENDIF
|
138
|
-
endif_line = endif_line(
|
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
|
-
|
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(
|
150
|
-
if keyword =
|
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(
|
155
|
+
return if_statement(pp_ctxt)
|
154
156
|
when :IFDEF
|
155
|
-
return ifdef_statement(
|
157
|
+
return ifdef_statement(pp_ctxt)
|
156
158
|
when :IFNDEF
|
157
|
-
return ifndef_statement(
|
159
|
+
return ifndef_statement(pp_ctxt)
|
158
160
|
end
|
159
161
|
end
|
160
162
|
nil
|
161
163
|
end
|
162
164
|
|
163
|
-
def if_statement(
|
164
|
-
keyword =
|
165
|
-
unless
|
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(
|
169
|
-
|
170
|
-
if
|
171
|
-
|
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(
|
174
|
-
|
175
|
+
group = group(pp_ctxt)
|
176
|
+
pp_ctxt.branch_evaluated = true
|
175
177
|
end
|
176
|
-
IfStatement.new(keyword,
|
178
|
+
IfStatement.new(keyword, expr, group)
|
177
179
|
end
|
178
180
|
|
179
|
-
def ifdef_statement(
|
180
|
-
keyword =
|
181
|
-
unless
|
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(
|
185
|
-
if macro_defined?(
|
186
|
-
group = group(
|
187
|
-
|
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
|
-
|
191
|
+
pp_ctxt.skip_group
|
190
192
|
end
|
191
|
-
IfdefStatement.new(keyword,
|
193
|
+
IfdefStatement.new(keyword, id, group)
|
192
194
|
end
|
193
195
|
|
194
|
-
def ifndef_statement(
|
195
|
-
keyword =
|
196
|
-
unless
|
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(
|
200
|
-
if macro_defined?(
|
201
|
-
|
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(
|
204
|
-
|
205
|
+
group = group(pp_ctxt)
|
206
|
+
pp_ctxt.branch_evaluated = true
|
205
207
|
end
|
206
|
-
IfndefStatement.new(keyword,
|
208
|
+
IfndefStatement.new(keyword, id, group)
|
207
209
|
end
|
208
210
|
|
209
|
-
def elif_groups(
|
210
|
-
if elif_group = elif_group(
|
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(
|
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(
|
221
|
-
unless
|
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 =
|
227
|
+
if keyword = pp_ctxt.next_token
|
226
228
|
if keyword.type == :ELIF
|
227
|
-
unless
|
229
|
+
unless pp_toks = pp_tokens(pp_ctxt)
|
228
230
|
return nil
|
229
231
|
end
|
230
|
-
discard_extra_tokens_until_newline(
|
231
|
-
|
232
|
-
if
|
233
|
-
|
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(
|
236
|
-
|
237
|
+
group = group(pp_ctxt)
|
238
|
+
pp_ctxt.branch_evaluated = true
|
237
239
|
end
|
238
|
-
return ElifStatement.new(keyword,
|
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(
|
245
|
-
if keyword =
|
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(
|
248
|
-
if
|
249
|
-
|
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(
|
252
|
-
|
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(
|
261
|
-
if keyword =
|
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(
|
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(
|
271
|
-
if keyword =
|
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(
|
276
|
+
return include_line(pp_ctxt)
|
275
277
|
when :INCLUDE_NEXT
|
276
|
-
return include_next_line(
|
278
|
+
return include_next_line(pp_ctxt)
|
277
279
|
when :DEFINE
|
278
|
-
return define_line(
|
280
|
+
return define_line(pp_ctxt)
|
279
281
|
when :UNDEF
|
280
|
-
return undef_line(
|
282
|
+
return undef_line(pp_ctxt)
|
281
283
|
when :LINE
|
282
|
-
return line_line(
|
284
|
+
return line_line(pp_ctxt)
|
283
285
|
when :ERROR
|
284
|
-
return error_line(
|
286
|
+
return error_line(pp_ctxt)
|
285
287
|
when :PRAGMA
|
286
|
-
return pragma_line(
|
288
|
+
return pragma_line(pp_ctxt)
|
287
289
|
end
|
288
290
|
end
|
289
291
|
nil
|
290
292
|
end
|
291
293
|
|
292
|
-
def include_line(
|
293
|
-
keyword =
|
294
|
-
if header_name =
|
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(
|
299
|
+
return user_include_line(pp_ctxt, keyword)
|
298
300
|
when :SYS_HEADER_NAME
|
299
|
-
return system_include_line(
|
301
|
+
return system_include_line(pp_ctxt, keyword)
|
300
302
|
else
|
301
|
-
return macro_include_line(
|
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(
|
308
|
-
keyword =
|
309
|
-
if header_name =
|
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(
|
314
|
+
return user_include_next_line(pp_ctxt, keyword)
|
313
315
|
when :SYS_HEADER_NAME
|
314
|
-
return system_include_next_line(
|
316
|
+
return system_include_next_line(pp_ctxt, keyword)
|
315
317
|
else
|
316
|
-
return macro_include_next_line(
|
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(
|
323
|
-
header_name =
|
324
|
-
discard_extra_tokens_until_newline(
|
325
|
-
|
326
|
-
UserIncludeLine.new(keyword, header_name,
|
327
|
-
include_first_user_header(
|
328
|
-
|
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(
|
332
|
-
header_name =
|
333
|
-
discard_extra_tokens_until_newline(
|
334
|
-
|
335
|
-
UserIncludeNextLine.new(keyword, header_name,
|
336
|
-
include_next_user_header(
|
337
|
-
|
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(
|
341
|
-
header_name =
|
342
|
-
discard_extra_tokens_until_newline(
|
343
|
-
|
344
|
-
SystemIncludeLine.new(keyword, header_name,
|
345
|
-
include_first_system_header(
|
346
|
-
|
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(
|
350
|
-
header_name =
|
351
|
-
discard_extra_tokens_until_newline(
|
352
|
-
|
353
|
-
SystemIncludeNextLine.new(keyword, header_name,
|
354
|
-
include_next_system_header(
|
355
|
-
|
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(
|
359
|
-
unless
|
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(
|
363
|
-
PPTokensNormalizer.normalize(
|
364
|
-
return nil if
|
365
|
-
case
|
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
|
-
|
368
|
-
keyword, Token.new(:USR_HEADER_NAME,
|
369
|
-
|
370
|
-
|
371
|
-
include_first_user_header(
|
372
|
-
return
|
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
|
-
|
375
|
-
keyword, Token.new(:SYS_HEADER_NAME,
|
376
|
-
|
377
|
-
|
378
|
-
include_first_system_header(
|
379
|
-
return
|
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(
|
385
|
-
unless
|
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(
|
389
|
-
PPTokensNormalizer.normalize(
|
390
|
-
return nil if
|
391
|
-
case
|
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
|
-
|
394
|
-
keyword, Token.new(:USR_HEADER_NAME,
|
395
|
-
|
396
|
-
|
397
|
-
include_next_user_header(
|
398
|
-
return
|
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
|
-
|
401
|
-
keyword, Token.new(:SYS_HEADER_NAME,
|
402
|
-
|
403
|
-
|
404
|
-
include_next_system_header(
|
405
|
-
return
|
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(
|
411
|
-
keyword =
|
412
|
-
unless
|
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
|
-
|
417
|
+
sym = pp_ctxt.symbol_table.create_new_symbol(MacroName, id)
|
416
418
|
|
417
|
-
if paren =
|
418
|
-
|
419
|
-
|
420
|
-
unless paren_or_ellipsis =
|
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 =
|
427
|
-
|
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
|
-
|
437
|
-
discard_extra_tokens_until_newline(
|
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,
|
440
|
-
|
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,
|
446
|
-
|
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
|
-
|
453
|
-
discard_extra_tokens_until_newline(
|
454
|
-
define_line = ObjectLikeDefineLine.new(keyword,
|
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
|
-
|
459
|
+
pp_ctxt.macro_table.define(macro)
|
461
460
|
define_line
|
462
461
|
end
|
463
462
|
|
464
|
-
def undef_line(
|
465
|
-
keyword =
|
466
|
-
unless
|
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(
|
468
|
+
discard_extra_tokens_until_newline(pp_ctxt)
|
470
469
|
|
471
|
-
undef_line = UndefLine.new(keyword,
|
472
|
-
macro =
|
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
|
-
|
475
|
+
pp_ctxt.macro_table.undef(id.value)
|
477
476
|
undef_line
|
478
477
|
end
|
479
478
|
|
480
|
-
def line_line(
|
481
|
-
keyword =
|
482
|
-
|
483
|
-
discard_extra_tokens_until_newline(
|
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(
|
498
|
+
PPTokensNormalizer.normalize(pp_toks, pp_ctxt) if pp_toks
|
500
499
|
|
501
|
-
LineLine.new(keyword,
|
500
|
+
LineLine.new(keyword, pp_toks)
|
502
501
|
end
|
503
502
|
|
504
|
-
def error_line(
|
505
|
-
keyword =
|
506
|
-
|
507
|
-
discard_extra_tokens_until_newline(
|
508
|
-
ErrorLine.new(keyword,
|
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(
|
512
|
-
keyword =
|
513
|
-
|
514
|
-
discard_extra_tokens_until_newline(
|
515
|
-
pragma_line = PragmaLine.new(keyword,
|
516
|
-
if
|
517
|
-
|
518
|
-
|
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(
|
526
|
-
unless
|
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
|
-
|
530
|
-
while
|
531
|
-
if
|
532
|
-
|
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 =
|
535
|
-
|
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
|
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
|
-
|
542
|
+
id_list
|
545
543
|
end
|
546
544
|
|
547
|
-
def replacement_list(
|
548
|
-
pp_tokens(
|
545
|
+
def replacement_list(pp_ctxt)
|
546
|
+
pp_tokens(pp_ctxt)
|
549
547
|
end
|
550
548
|
|
551
|
-
def pp_tokens(
|
552
|
-
unless
|
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
|
-
|
556
|
-
while
|
557
|
-
if
|
558
|
-
|
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
|
-
|
561
|
+
pp_toks
|
564
562
|
end
|
565
563
|
|
566
|
-
def asm_section(
|
567
|
-
asm_line = asm_line(
|
568
|
-
|
569
|
-
endasm_line = endasm_line(
|
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(
|
576
|
-
if keyword =
|
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(
|
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(
|
586
|
-
if keyword =
|
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(
|
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(
|
596
|
-
basename =
|
597
|
-
|
598
|
-
|
599
|
-
|
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,
|
603
|
-
raise MissingUserHeaderError.new(
|
604
|
-
|
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(
|
609
|
-
basename =
|
610
|
-
|
611
|
-
|
612
|
-
|
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,
|
616
|
-
raise MissingUserHeaderError.new(
|
617
|
-
|
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,
|
623
|
-
unless
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
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(
|
635
|
-
basename =
|
636
|
-
|
637
|
-
|
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,
|
641
|
-
raise MissingSystemHeaderError.new(
|
642
|
-
|
643
|
-
|
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(
|
649
|
-
basename =
|
650
|
-
|
651
|
-
|
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,
|
655
|
-
raise MissingSystemHeaderError.new(
|
656
|
-
|
657
|
-
|
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,
|
663
|
-
unless
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
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,
|
675
|
-
resolve_user_headers(basename,
|
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,
|
679
|
-
resolve_user_headers(basename,
|
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,
|
683
|
-
|
684
|
-
|
685
|
-
|
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
|
-
|
692
|
-
|
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
|
-
|
696
|
-
break if
|
690
|
+
resolved.push(fpath) if fpath.readable?
|
691
|
+
break if resolved.size == max_num
|
697
692
|
end
|
698
|
-
|
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
|
-
|
712
|
-
|
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
|
-
|
719
|
-
|
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
|
-
|
723
|
-
break if
|
717
|
+
resolved.push(fpath) if fpath.readable?
|
718
|
+
break if resolved.size == max_num
|
724
719
|
end
|
725
|
-
|
720
|
+
resolved
|
726
721
|
end
|
727
722
|
end
|
728
723
|
|
729
|
-
def macro_defined?(
|
730
|
-
if macro =
|
731
|
-
macro.define_line.mark_as_referred_by(
|
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(
|
739
|
-
|
740
|
-
while
|
741
|
-
if
|
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
|
-
|
739
|
+
extra_toks.push(tok)
|
745
740
|
end
|
746
741
|
end
|
747
|
-
notify_extra_tokens_found(
|
742
|
+
notify_extra_tokens_found(extra_toks) unless extra_toks.empty?
|
748
743
|
end
|
749
744
|
|
750
|
-
def create_lexer(
|
751
|
-
Lexer.new(
|
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
|
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(
|
776
|
-
on_user_header_included.invoke(
|
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(
|
780
|
-
on_system_header_included.invoke(
|
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(
|
808
|
-
on_pp_token_extracted.invoke(
|
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(
|
812
|
-
on_illformed_defined_op_found.invoke(
|
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(
|
816
|
-
on_undefined_macro_referred.invoke(
|
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(
|
820
|
-
on_extra_tokens_found.invoke(
|
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(
|
824
|
-
E(:E0016,
|
825
|
-
raise UnterminatedCommentError.new(
|
826
|
-
|
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
|
-
|
830
|
-
|
831
|
-
|
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(
|
836
|
-
@
|
837
|
+
def initialize(phase_ctxt)
|
838
|
+
@phase_ctxt = phase_ctxt
|
837
839
|
@deferred_text_lines = []
|
838
|
-
@lexer_stack
|
839
|
-
@branch_stack
|
840
|
-
@once_set
|
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
|
-
|
847
|
-
|
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
|
-
@
|
862
|
+
@phase_ctxt[:cc1_source]
|
852
863
|
end
|
853
864
|
|
854
865
|
def sources
|
855
|
-
@
|
866
|
+
@phase_ctxt[:sources]
|
856
867
|
end
|
857
868
|
|
858
869
|
def symbol_table
|
859
|
-
@
|
870
|
+
@phase_ctxt[:symbol_table]
|
860
871
|
end
|
861
872
|
|
862
873
|
def macro_table
|
863
|
-
@
|
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
|
883
|
+
unless tok = @lexer_stack.last.top_token
|
885
884
|
@lexer_stack.pop
|
886
885
|
top_token
|
887
886
|
else
|
888
|
-
|
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(
|
927
|
-
|
928
|
-
|
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(
|
935
|
-
PPTokensNormalizer.normalize(
|
936
|
-
const_expr = ConstantExpression.new(
|
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,
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
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
|
-
|
958
|
+
lexer = TextLineToPPTokensLexer.new(text_line, tab_width)
|
959
|
+
pp_toks += lexer.execute.to_a
|
960
960
|
|
961
|
-
|
962
|
-
(macro =
|
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
|
967
|
-
return nil unless complete_macro_reference?(
|
966
|
+
if fun_like_macro_referred
|
967
|
+
return nil unless complete_macro_reference?(pp_toks, pp_ctxt)
|
968
968
|
end
|
969
969
|
|
970
|
-
|
971
|
-
|
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?(
|
976
|
-
|
977
|
-
while
|
978
|
-
|
979
|
-
macro =
|
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?(
|
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
|
988
|
+
return false unless pp_toks[idx..-1].any? { |t| t.value == "(" }
|
989
989
|
|
990
|
-
|
991
|
-
while
|
992
|
-
case
|
990
|
+
paren_cnt = 0
|
991
|
+
while tok = pp_toks[idx]
|
992
|
+
case tok.value
|
993
993
|
when "("
|
994
|
-
|
994
|
+
paren_cnt += 1
|
995
995
|
when ")"
|
996
|
-
|
997
|
-
break if
|
996
|
+
paren_cnt -= 1
|
997
|
+
break if paren_cnt == 0
|
998
998
|
end
|
999
|
-
|
999
|
+
idx += 1
|
1000
1000
|
end
|
1001
1001
|
|
1002
|
-
return false if
|
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?(
|
1009
|
-
while
|
1008
|
+
def not_calling_function_like_macro?(pp_toks, idx)
|
1009
|
+
while pp_tok = pp_toks[idx]
|
1010
1010
|
case
|
1011
|
-
when
|
1011
|
+
when pp_tok.value == "("
|
1012
1012
|
return false
|
1013
|
-
when
|
1014
|
-
|
1013
|
+
when pp_tok.type == :NEW_LINE
|
1014
|
+
idx += 1
|
1015
1015
|
else
|
1016
1016
|
return true
|
1017
1017
|
end
|