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
@@ -1,7 +1,7 @@
|
|
1
1
|
# C runtime object model.
|
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
|
#
|
@@ -30,14 +30,14 @@
|
|
30
30
|
#++
|
31
31
|
|
32
32
|
require "adlint/util"
|
33
|
-
require "adlint/
|
34
|
-
require "adlint/
|
35
|
-
require "adlint/
|
36
|
-
require "adlint/
|
37
|
-
require "adlint/
|
33
|
+
require "adlint/cc1/syntax"
|
34
|
+
require "adlint/cc1/value"
|
35
|
+
require "adlint/cc1/scope"
|
36
|
+
require "adlint/cc1/seqp"
|
37
|
+
require "adlint/cc1/operator"
|
38
38
|
|
39
39
|
module AdLint #:nodoc:
|
40
|
-
module
|
40
|
+
module Cc1 #:nodoc:
|
41
41
|
|
42
42
|
module Bindable
|
43
43
|
attr_accessor :binding
|
@@ -51,10 +51,10 @@ module C #:nodoc:
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
def be_alias_to(
|
55
|
-
case
|
54
|
+
def be_alias_to(mem)
|
55
|
+
case mem
|
56
56
|
when Memory
|
57
|
-
Binding.create_alias(self,
|
57
|
+
Binding.create_alias(self, mem)
|
58
58
|
else
|
59
59
|
raise TypeError, "an object cannot be an alias to other objects."
|
60
60
|
end
|
@@ -62,22 +62,22 @@ module C #:nodoc:
|
|
62
62
|
end
|
63
63
|
|
64
64
|
class Binding
|
65
|
-
def self.bind(
|
66
|
-
binding = new(
|
67
|
-
|
68
|
-
|
65
|
+
def self.bind(obj, mem)
|
66
|
+
binding = new(obj, mem)
|
67
|
+
obj.binding = binding
|
68
|
+
mem.binding = binding
|
69
69
|
binding
|
70
70
|
end
|
71
71
|
|
72
|
-
def self.create_alias(
|
73
|
-
binding = new(
|
74
|
-
|
72
|
+
def self.create_alias(obj, mem)
|
73
|
+
binding = new(obj, mem)
|
74
|
+
obj.binding = binding
|
75
75
|
binding
|
76
76
|
end
|
77
77
|
|
78
|
-
def initialize(
|
79
|
-
@object =
|
80
|
-
@memory =
|
78
|
+
def initialize(obj, mem)
|
79
|
+
@object = obj
|
80
|
+
@memory = mem
|
81
81
|
end
|
82
82
|
private_class_method :new
|
83
83
|
|
@@ -88,36 +88,33 @@ module C #:nodoc:
|
|
88
88
|
class Object
|
89
89
|
include Bindable
|
90
90
|
|
91
|
-
def initialize(
|
92
|
-
@declarations_and_definitions = [
|
91
|
+
def initialize(dcl_or_def = nil)
|
92
|
+
@declarations_and_definitions = [dcl_or_def].compact
|
93
93
|
end
|
94
94
|
|
95
95
|
attr_reader :declarations_and_definitions
|
96
96
|
|
97
97
|
def storage_class_specifiers
|
98
|
-
@declarations_and_definitions.map { |
|
99
|
-
|
98
|
+
@declarations_and_definitions.map { |dcl_or_def|
|
99
|
+
dcl_or_def.storage_class_specifier
|
100
100
|
}.compact
|
101
101
|
end
|
102
102
|
|
103
103
|
def declared_as_extern?
|
104
|
-
|
105
|
-
|
104
|
+
sc_spec = first_storage_class_specifier
|
105
|
+
sc_spec.nil? || sc_spec.type == :EXTERN
|
106
106
|
end
|
107
107
|
|
108
108
|
def declared_as_static?
|
109
|
-
|
110
|
-
first_sc_spec.type == :STATIC
|
109
|
+
sc_spec = first_storage_class_specifier and sc_spec.type == :STATIC
|
111
110
|
end
|
112
111
|
|
113
112
|
def declared_as_auto?
|
114
|
-
|
115
|
-
first_sc_spec.type == :AUTO
|
113
|
+
sc_spec = first_storage_class_specifier and sc_spec.type == :AUTO
|
116
114
|
end
|
117
115
|
|
118
116
|
def declared_as_register?
|
119
|
-
|
120
|
-
first_sc_spec.type == :REGISTER
|
117
|
+
sc_spec = first_storage_class_specifier and sc_spec.type == :REGISTER
|
121
118
|
end
|
122
119
|
|
123
120
|
def designated_by_lvalue?
|
@@ -151,8 +148,8 @@ module C #:nodoc:
|
|
151
148
|
end
|
152
149
|
|
153
150
|
class TypedObject < Object
|
154
|
-
def initialize(type,
|
155
|
-
super(
|
151
|
+
def initialize(type, dcl_or_def = nil)
|
152
|
+
super(dcl_or_def)
|
156
153
|
@type = type
|
157
154
|
end
|
158
155
|
|
@@ -162,19 +159,18 @@ module C #:nodoc:
|
|
162
159
|
# == DESCRIPTION
|
163
160
|
# === Variable class hierarchy
|
164
161
|
# Variable
|
165
|
-
#
|
166
|
-
#
|
167
|
-
#
|
168
|
-
#
|
169
|
-
#
|
170
|
-
#
|
171
|
-
#
|
172
|
-
#
|
162
|
+
# <-- ScopedVariable
|
163
|
+
# <-- OuterVariable
|
164
|
+
# <-- NamedVariable --------> Nameable <<module>>
|
165
|
+
# <-- AliasVariable ^
|
166
|
+
# <-- TemporaryVariable |
|
167
|
+
# <-- InnerVariable -------------+
|
168
|
+
# <-- ArrayElementVariable
|
169
|
+
# <-- CompositeMemberVariable
|
173
170
|
class Variable < TypedObject
|
174
|
-
def initialize(
|
175
|
-
super(type,
|
176
|
-
|
177
|
-
relate_to_memory(memory)
|
171
|
+
def initialize(mem, dcl_or_def, type)
|
172
|
+
super(type, dcl_or_def)
|
173
|
+
relate_to_memory(mem)
|
178
174
|
end
|
179
175
|
|
180
176
|
def function?
|
@@ -205,28 +201,28 @@ module C #:nodoc:
|
|
205
201
|
binding.memory.read
|
206
202
|
end
|
207
203
|
|
208
|
-
def assign!(
|
204
|
+
def assign!(val)
|
209
205
|
# NOTE: Length of the incomplete array type should be deducted while
|
210
206
|
# initializer evaluation. So, adjustment of the assigning value
|
211
207
|
# can be done at this point by Value#coerce_to(type).
|
212
208
|
# NOTE: Domain of the assigning value must be narrowed before writing to
|
213
209
|
# the memory by Value#coerce_to(type).
|
214
|
-
binding.memory.write(
|
210
|
+
binding.memory.write(val.coerce_to(type))
|
215
211
|
end
|
216
212
|
|
217
213
|
def uninitialize!
|
218
214
|
assign!(self.type.undefined_value)
|
219
215
|
end
|
220
216
|
|
221
|
-
def narrow_value_domain!(
|
217
|
+
def narrow_value_domain!(op, val)
|
222
218
|
assign!(type.arbitrary_value) unless self.value
|
223
|
-
self.value.narrow_domain!(
|
219
|
+
self.value.narrow_domain!(op, val.coerce_to(type))
|
224
220
|
self.value.exist?
|
225
221
|
end
|
226
222
|
|
227
|
-
def widen_value_domain!(
|
223
|
+
def widen_value_domain!(op, val)
|
228
224
|
assign!(type.nil_value) unless self.value
|
229
|
-
self.value.widen_domain!(
|
225
|
+
self.value.widen_domain!(op, val.coerce_to(type))
|
230
226
|
self.value.exist?
|
231
227
|
end
|
232
228
|
|
@@ -255,14 +251,14 @@ module C #:nodoc:
|
|
255
251
|
end
|
256
252
|
|
257
253
|
private
|
258
|
-
def relate_to_memory(
|
259
|
-
bind_to(
|
254
|
+
def relate_to_memory(mem)
|
255
|
+
bind_to(mem)
|
260
256
|
end
|
261
257
|
end
|
262
258
|
|
263
259
|
class ScopedVariable < Variable
|
264
|
-
def initialize(
|
265
|
-
super(
|
260
|
+
def initialize(mem, dcl_or_def, type, scope)
|
261
|
+
super(mem, dcl_or_def, type)
|
266
262
|
@scope = scope
|
267
263
|
end
|
268
264
|
|
@@ -272,8 +268,7 @@ module C #:nodoc:
|
|
272
268
|
if @scope.global?
|
273
269
|
super
|
274
270
|
else
|
275
|
-
|
276
|
-
first_sc_spec.type == :EXTERN
|
271
|
+
sc_spec = first_storage_class_specifier and sc_spec.type == :EXTERN
|
277
272
|
end
|
278
273
|
end
|
279
274
|
|
@@ -281,16 +276,15 @@ module C #:nodoc:
|
|
281
276
|
if @scope.global?
|
282
277
|
super
|
283
278
|
else
|
284
|
-
|
285
|
-
|
279
|
+
sc_spec = first_storage_class_specifier
|
280
|
+
sc_spec.nil? || sc_spec.type == :AUTO
|
286
281
|
end
|
287
282
|
end
|
288
283
|
end
|
289
284
|
|
290
285
|
class OuterVariable < ScopedVariable
|
291
|
-
def initialize(
|
292
|
-
super(
|
293
|
-
|
286
|
+
def initialize(mem, dcl_or_def, type, scope)
|
287
|
+
super(mem, dcl_or_def, type, scope)
|
294
288
|
# TODO: If too slow, make an index of inner variables.
|
295
289
|
@inner_variables = create_inner_variables(type.unqualify, scope)
|
296
290
|
end
|
@@ -353,12 +347,12 @@ module C #:nodoc:
|
|
353
347
|
false
|
354
348
|
end
|
355
349
|
|
356
|
-
def inner_variable_at(
|
350
|
+
def inner_variable_at(idx)
|
357
351
|
if @type.array?
|
358
352
|
# TODO: If linear searching is too slow, use an index of inner
|
359
353
|
# variables.
|
360
|
-
target_name = ArrayElementVariable.component_name_of(
|
361
|
-
@inner_variables.find { |
|
354
|
+
target_name = ArrayElementVariable.component_name_of(idx)
|
355
|
+
@inner_variables.find { |inner| inner.component_name == target_name }
|
362
356
|
else
|
363
357
|
nil
|
364
358
|
end
|
@@ -369,7 +363,7 @@ module C #:nodoc:
|
|
369
363
|
# TODO: If linear searching is too slow, use an index of inner
|
370
364
|
# variables.
|
371
365
|
target_name = CompositeMemberVariable.component_name_of(name)
|
372
|
-
@inner_variables.find { |
|
366
|
+
@inner_variables.find { |inner| inner.component_name == target_name }
|
373
367
|
else
|
374
368
|
nil
|
375
369
|
end
|
@@ -387,21 +381,21 @@ module C #:nodoc:
|
|
387
381
|
end
|
388
382
|
end
|
389
383
|
|
390
|
-
def create_array_elements(type, scope,
|
384
|
+
def create_array_elements(type, scope, mem)
|
391
385
|
offset = 0
|
392
|
-
type.impl_length.times.map do |
|
393
|
-
|
394
|
-
offset +=
|
395
|
-
ArrayElementVariable.new(
|
386
|
+
type.impl_length.times.map do |idx|
|
387
|
+
win = mem.create_window(offset, type.base_type.aligned_byte_size)
|
388
|
+
offset += win.byte_size
|
389
|
+
ArrayElementVariable.new(win, self, type.base_type, idx)
|
396
390
|
end
|
397
391
|
end
|
398
392
|
|
399
|
-
def create_composite_members(type, scope,
|
393
|
+
def create_composite_members(type, scope, mem)
|
400
394
|
offset = 0
|
401
|
-
type.members.map do |
|
402
|
-
|
403
|
-
offset +=
|
404
|
-
CompositeMemberVariable.new(
|
395
|
+
type.members.map do |memb|
|
396
|
+
win = mem.create_window(offset, memb.type.aligned_byte_size)
|
397
|
+
offset += win.byte_size
|
398
|
+
CompositeMemberVariable.new(win, self, memb.type, memb.name)
|
405
399
|
end
|
406
400
|
end
|
407
401
|
end
|
@@ -423,11 +417,9 @@ module C #:nodoc:
|
|
423
417
|
class NamedVariable < OuterVariable
|
424
418
|
include Nameable
|
425
419
|
|
426
|
-
def initialize(
|
427
|
-
self.name =
|
428
|
-
|
429
|
-
super(memory, declaration_or_definition, declaration_or_definition.type,
|
430
|
-
scope)
|
420
|
+
def initialize(mem, dcl_or_def, scope)
|
421
|
+
self.name = dcl_or_def.identifier.value
|
422
|
+
super(mem, dcl_or_def, dcl_or_def.type, scope)
|
431
423
|
end
|
432
424
|
|
433
425
|
def temporary?
|
@@ -451,8 +443,8 @@ module C #:nodoc:
|
|
451
443
|
end
|
452
444
|
|
453
445
|
class TemporaryVariable < OuterVariable
|
454
|
-
def initialize(
|
455
|
-
super(
|
446
|
+
def initialize(mem, type, scope)
|
447
|
+
super(mem, nil, type, scope)
|
456
448
|
end
|
457
449
|
|
458
450
|
def temporary?
|
@@ -477,12 +469,11 @@ module C #:nodoc:
|
|
477
469
|
class InnerVariable < OuterVariable
|
478
470
|
include Nameable
|
479
471
|
|
480
|
-
def initialize(
|
481
|
-
@owner =
|
472
|
+
def initialize(mem, outer_var, type, component_name)
|
473
|
+
@owner = outer_var
|
482
474
|
@component_name = component_name
|
483
|
-
self.name = create_qualified_name(
|
484
|
-
|
485
|
-
super(memory, nil, type, outer_variable.scope)
|
475
|
+
self.name = create_qualified_name(outer_var, component_name)
|
476
|
+
super(mem, nil, type, outer_var.scope)
|
486
477
|
end
|
487
478
|
|
488
479
|
attr_reader :owner
|
@@ -529,9 +520,9 @@ module C #:nodoc:
|
|
529
520
|
end
|
530
521
|
|
531
522
|
private
|
532
|
-
def create_qualified_name(
|
533
|
-
if
|
534
|
-
"#{
|
523
|
+
def create_qualified_name(outer_var, component_name)
|
524
|
+
if outer_var.named?
|
525
|
+
"#{outer_var.name}#{component_name}"
|
535
526
|
else
|
536
527
|
"__adlint__tempvar#{component_name}"
|
537
528
|
end
|
@@ -539,12 +530,12 @@ module C #:nodoc:
|
|
539
530
|
end
|
540
531
|
|
541
532
|
class ArrayElementVariable < InnerVariable
|
542
|
-
def self.component_name_of(
|
543
|
-
"[#{
|
533
|
+
def self.component_name_of(idx)
|
534
|
+
"[#{idx}]"
|
544
535
|
end
|
545
536
|
|
546
|
-
def initialize(
|
547
|
-
super(
|
537
|
+
def initialize(mem, outer_var, type, idx)
|
538
|
+
super(mem, outer_var, type, self.class.component_name_of(idx))
|
548
539
|
end
|
549
540
|
end
|
550
541
|
|
@@ -553,29 +544,29 @@ module C #:nodoc:
|
|
553
544
|
".#{name}"
|
554
545
|
end
|
555
546
|
|
556
|
-
def initialize(
|
557
|
-
super(
|
547
|
+
def initialize(mem, outer_var, type, name)
|
548
|
+
super(mem, outer_var, type, self.class.component_name_of(name))
|
558
549
|
end
|
559
550
|
end
|
560
551
|
|
561
552
|
class AliasVariable < NamedVariable
|
562
|
-
def initialize(
|
563
|
-
super(
|
564
|
-
|
553
|
+
def initialize(var)
|
554
|
+
super(var.binding.memory,
|
555
|
+
var.declarations_and_definitions.first, var.scope)
|
565
556
|
end
|
566
557
|
|
567
558
|
private
|
568
|
-
def relate_to_memory(
|
569
|
-
be_alias_to(
|
559
|
+
def relate_to_memory(mem)
|
560
|
+
be_alias_to(mem)
|
570
561
|
end
|
571
562
|
end
|
572
563
|
|
573
564
|
class VariableTable
|
574
|
-
def initialize(
|
575
|
-
@memory_pool
|
565
|
+
def initialize(mem_pool)
|
566
|
+
@memory_pool = mem_pool
|
576
567
|
@named_variables = [{}]
|
577
|
-
@
|
578
|
-
@scope_stack
|
568
|
+
@temp_variables = [[]]
|
569
|
+
@scope_stack = [GlobalScope.new]
|
579
570
|
end
|
580
571
|
|
581
572
|
def all_named_variables
|
@@ -584,69 +575,69 @@ module C #:nodoc:
|
|
584
575
|
|
585
576
|
def enter_scope
|
586
577
|
@named_variables.push({})
|
587
|
-
@
|
578
|
+
@temp_variables.push([])
|
588
579
|
@scope_stack.push(Scope.new(@scope_stack.size))
|
589
580
|
end
|
590
581
|
|
591
582
|
def leave_scope
|
592
|
-
@named_variables.pop.each_value do |
|
593
|
-
@memory_pool.free(
|
583
|
+
@named_variables.pop.each_value do |var|
|
584
|
+
@memory_pool.free(var.binding.memory)
|
594
585
|
end
|
595
|
-
@
|
596
|
-
@memory_pool.free(
|
586
|
+
@temp_variables.pop.each do |var|
|
587
|
+
@memory_pool.free(var.binding.memory)
|
597
588
|
end
|
589
|
+
|
598
590
|
@scope_stack.pop
|
599
591
|
rollback_all_global_variables_value! if current_scope.global?
|
600
592
|
end
|
601
593
|
|
602
|
-
def declare(
|
603
|
-
if
|
604
|
-
|
605
|
-
return
|
594
|
+
def declare(dcl)
|
595
|
+
if var = lookup(dcl.identifier.value)
|
596
|
+
var.declarations_and_definitions.push(dcl)
|
597
|
+
return var
|
606
598
|
end
|
607
599
|
|
608
600
|
# NOTE: External variable may have undefined values.
|
609
|
-
define_variable(
|
610
|
-
|
611
|
-
declaration.type.undefined_value)
|
601
|
+
define_variable(dcl, dcl.type, allocate_memory(dcl),
|
602
|
+
dcl.type.undefined_value)
|
612
603
|
end
|
613
604
|
|
614
|
-
def define(
|
615
|
-
if storage_duration_of(
|
605
|
+
def define(dcl_or_def, init_val = nil)
|
606
|
+
if storage_duration_of(dcl_or_def) == :static
|
616
607
|
# NOTE: Value of the static duration object should be arbitrary because
|
617
608
|
# execution of its accessors are out of order.
|
618
609
|
# So, a value of the initializer should be ignored.
|
619
|
-
|
610
|
+
init_val = dcl_or_def.type.arbitrary_value
|
620
611
|
else
|
621
|
-
|
612
|
+
init_val ||= dcl_or_def.type.undefined_value
|
622
613
|
end
|
623
614
|
|
624
|
-
if
|
625
|
-
if
|
626
|
-
|
627
|
-
|
628
|
-
return
|
615
|
+
if var = lookup(dcl_or_def.identifier.value)
|
616
|
+
if var.scope == current_scope
|
617
|
+
var.declarations_and_definitions.push(dcl_or_def)
|
618
|
+
var.assign!(init_val)
|
619
|
+
return var
|
629
620
|
end
|
630
621
|
end
|
631
622
|
|
632
623
|
# NOTE: Domain of the init-value will be restricted by type's min-max in
|
633
624
|
# define_variable.
|
634
|
-
define_variable(
|
635
|
-
allocate_memory(
|
625
|
+
define_variable(dcl_or_def, dcl_or_def.type,
|
626
|
+
allocate_memory(dcl_or_def), init_val)
|
636
627
|
end
|
637
628
|
|
638
|
-
def define_temporary(type,
|
639
|
-
|
629
|
+
def define_temporary(type, init_val)
|
630
|
+
mem = @memory_pool.allocate_dynamic(type.aligned_byte_size)
|
640
631
|
|
641
632
|
# NOTE: Domain of the init-value will be restricted by type's min-max in
|
642
633
|
# define_variable.
|
643
|
-
define_variable(nil, type,
|
634
|
+
define_variable(nil, type, mem, init_val)
|
644
635
|
end
|
645
636
|
|
646
637
|
def lookup(name_str)
|
647
638
|
@named_variables.reverse_each do |hash|
|
648
|
-
if
|
649
|
-
return
|
639
|
+
if var = hash[name_str]
|
640
|
+
return var
|
650
641
|
end
|
651
642
|
end
|
652
643
|
nil
|
@@ -654,39 +645,37 @@ module C #:nodoc:
|
|
654
645
|
|
655
646
|
def enter_variables_value_versioning_group
|
656
647
|
@named_variables.each do |hash|
|
657
|
-
hash.each_value { |
|
648
|
+
hash.each_value { |var| var.enter_value_versioning_group }
|
658
649
|
end
|
659
650
|
end
|
660
651
|
|
661
652
|
def leave_variables_value_versioning_group(raise_complement)
|
662
653
|
@named_variables.each do |hash|
|
663
|
-
hash.each_value do |
|
664
|
-
|
654
|
+
hash.each_value do |var|
|
655
|
+
var.leave_value_versioning_group(raise_complement)
|
665
656
|
end
|
666
657
|
end
|
667
658
|
end
|
668
659
|
|
669
660
|
def begin_variables_value_versioning
|
670
661
|
@named_variables.each do |hash|
|
671
|
-
hash.each_value { |
|
662
|
+
hash.each_value { |var| var.begin_value_versioning }
|
672
663
|
end
|
673
664
|
end
|
674
665
|
|
675
666
|
def end_variables_value_versioning
|
676
667
|
@named_variables.each do |hash|
|
677
|
-
hash.each_value { |
|
668
|
+
hash.each_value { |var| var.end_value_versioning }
|
678
669
|
end
|
679
670
|
end
|
680
671
|
|
681
672
|
def thin_latest_variables_value_version!(with_rollback)
|
682
673
|
@named_variables.each do |hash|
|
683
|
-
hash.each_value
|
684
|
-
variable.thin_latest_value_version!(with_rollback)
|
685
|
-
end
|
674
|
+
hash.each_value { |var| var.thin_latest_value_version!(with_rollback) }
|
686
675
|
end
|
687
676
|
end
|
688
677
|
|
689
|
-
def storage_duration_of(
|
678
|
+
def storage_duration_of(dcl_or_def)
|
690
679
|
# NOTE: The ISO C99 standard says;
|
691
680
|
#
|
692
681
|
# 6.2.2 Linkages of identifiers
|
@@ -734,9 +723,8 @@ module C #:nodoc:
|
|
734
723
|
# 4 An object whose identifier is declared with no linkage and without
|
735
724
|
# the storage-class specifier static has automatic storage duration.
|
736
725
|
|
737
|
-
|
738
|
-
|
739
|
-
(sc_specifier.type == :EXTERN || sc_specifier.type == :STATIC)
|
726
|
+
if sc_spec = dcl_or_def.storage_class_specifier and
|
727
|
+
sc_spec.type == :EXTERN || sc_spec.type == :STATIC
|
740
728
|
:static
|
741
729
|
else
|
742
730
|
current_scope.global? ? :static : :automatic
|
@@ -744,33 +732,33 @@ module C #:nodoc:
|
|
744
732
|
end
|
745
733
|
|
746
734
|
private
|
747
|
-
def define_variable(
|
748
|
-
|
749
|
-
|
735
|
+
def define_variable(dcl_or_def, type, mem, init_val)
|
736
|
+
var = create_variable(dcl_or_def, type, mem)
|
737
|
+
var.assign!(init_val)
|
750
738
|
|
751
|
-
if
|
752
|
-
@named_variables.last[
|
739
|
+
if var.named?
|
740
|
+
@named_variables.last[var.name] = var
|
753
741
|
else
|
754
|
-
@
|
742
|
+
@temp_variables.last.push(var)
|
755
743
|
end
|
756
744
|
|
757
|
-
|
745
|
+
var
|
758
746
|
end
|
759
747
|
|
760
|
-
def allocate_memory(
|
761
|
-
byte_size =
|
762
|
-
if storage_duration_of(
|
748
|
+
def allocate_memory(dcl_or_def)
|
749
|
+
byte_size = dcl_or_def.type.aligned_byte_size
|
750
|
+
if storage_duration_of(dcl_or_def) == :static
|
763
751
|
@memory_pool.allocate_static(byte_size)
|
764
752
|
else
|
765
753
|
@memory_pool.allocate_dynamic(byte_size)
|
766
754
|
end
|
767
755
|
end
|
768
756
|
|
769
|
-
def create_variable(
|
770
|
-
if
|
771
|
-
NamedVariable.new(
|
757
|
+
def create_variable(dcl_or_def, type, mem)
|
758
|
+
if dcl_or_def
|
759
|
+
NamedVariable.new(mem, dcl_or_def, current_scope)
|
772
760
|
else
|
773
|
-
TemporaryVariable.new(
|
761
|
+
TemporaryVariable.new(mem, type, current_scope)
|
774
762
|
end
|
775
763
|
end
|
776
764
|
|
@@ -779,8 +767,8 @@ module C #:nodoc:
|
|
779
767
|
end
|
780
768
|
|
781
769
|
def rollback_all_global_variables_value!
|
782
|
-
@named_variables.first.each_value do |
|
783
|
-
|
770
|
+
@named_variables.first.each_value do |var|
|
771
|
+
var.rollback_all_value_versions!
|
784
772
|
end
|
785
773
|
end
|
786
774
|
end
|
@@ -788,14 +776,14 @@ module C #:nodoc:
|
|
788
776
|
# == DESCRIPTION
|
789
777
|
# === Function class hierarchy
|
790
778
|
# Function
|
791
|
-
#
|
792
|
-
#
|
793
|
-
#
|
794
|
-
#
|
795
|
-
#
|
779
|
+
# <-- NamedFunction ------> Nameable <<module>>
|
780
|
+
# <-- ExplicitFunction
|
781
|
+
# <-- ImplicitFunction
|
782
|
+
# <-- BuiltinFunction
|
783
|
+
# <-- AnonymousFunction
|
796
784
|
class Function < TypedObject
|
797
|
-
def initialize(
|
798
|
-
super(type,
|
785
|
+
def initialize(dcl_or_def, type)
|
786
|
+
super(type, dcl_or_def)
|
799
787
|
end
|
800
788
|
|
801
789
|
def name
|
@@ -830,15 +818,15 @@ module C #:nodoc:
|
|
830
818
|
subclass_responsibility
|
831
819
|
end
|
832
820
|
|
833
|
-
def call(
|
834
|
-
assign_arguments_to_parameters(
|
835
|
-
return_values_via_pointer_arguments(
|
821
|
+
def call(interp, funcall_expr, args)
|
822
|
+
assign_arguments_to_parameters(interp, args)
|
823
|
+
return_values_via_pointer_arguments(interp, funcall_expr, args)
|
836
824
|
|
837
825
|
if type.return_type.function?
|
838
|
-
|
826
|
+
interp.create_tmpvar
|
839
827
|
else
|
840
|
-
|
841
|
-
|
828
|
+
retn_type = type.return_type
|
829
|
+
interp.create_tmpvar(retn_type, retn_type.return_value)
|
842
830
|
end
|
843
831
|
end
|
844
832
|
|
@@ -847,44 +835,44 @@ module C #:nodoc:
|
|
847
835
|
end
|
848
836
|
|
849
837
|
private
|
850
|
-
def assign_arguments_to_parameters(
|
838
|
+
def assign_arguments_to_parameters(interp, args)
|
851
839
|
args.zip(type.parameter_types).each do |(arg, expr), param_type|
|
852
840
|
if param_type
|
853
841
|
case
|
854
842
|
when arg.type.array? && param_type.pointer?
|
855
|
-
|
856
|
-
|
843
|
+
conved = interp.create_tmpvar(param_type,
|
844
|
+
interp.pointer_value_of(arg))
|
857
845
|
when arg.type.pointer? && param_type.array?
|
858
|
-
|
846
|
+
conved = interp.pointee_of(arg)
|
859
847
|
when arg.type.function? && param_type.pointer?
|
860
|
-
|
861
|
-
|
848
|
+
conved = interp.create_tmpvar(param_type,
|
849
|
+
interp.pointer_value_of(arg))
|
862
850
|
when arg.variable? && !arg.type.same_as?(param_type)
|
863
|
-
|
864
|
-
|
851
|
+
conved = interp.do_conversion(arg, param_type) ||
|
852
|
+
interp.create_tmpvar(param_type)
|
865
853
|
else
|
866
|
-
|
854
|
+
conved = arg
|
867
855
|
end
|
868
856
|
else
|
869
|
-
|
857
|
+
conved = interp.do_default_argument_promotion(arg)
|
870
858
|
end
|
871
859
|
|
872
860
|
# NOTE: Value of the argument is referred when the assignment to the
|
873
861
|
# parameter is performed.
|
874
862
|
if arg.variable? && !arg.type.array?
|
875
|
-
|
863
|
+
interp.notify_variable_value_referred(expr, arg)
|
876
864
|
end
|
877
865
|
|
878
|
-
if
|
879
|
-
|
866
|
+
if conved && arg != conved
|
867
|
+
interp.notify_implicit_conv_performed(expr, arg, conved)
|
880
868
|
end
|
881
869
|
end
|
882
870
|
end
|
883
871
|
|
884
|
-
def return_values_via_pointer_arguments(
|
872
|
+
def return_values_via_pointer_arguments(interp, funcall_expr, args)
|
885
873
|
args.zip(type.parameter_types).each do |(arg, expr), param_type|
|
886
874
|
next if param_type && param_type.void?
|
887
|
-
next unless arg.variable?
|
875
|
+
next unless arg.variable? and arg.type.pointer? || arg.type.array?
|
888
876
|
|
889
877
|
param_type = param_type.unqualify if param_type
|
890
878
|
|
@@ -898,7 +886,7 @@ module C #:nodoc:
|
|
898
886
|
|
899
887
|
case
|
900
888
|
when arg.type.pointer?
|
901
|
-
pointee =
|
889
|
+
pointee = interp.pointee_of(arg)
|
902
890
|
if pointee && pointee.designated_by_lvalue? && pointee.variable?
|
903
891
|
sink = pointee
|
904
892
|
else
|
@@ -909,14 +897,14 @@ module C #:nodoc:
|
|
909
897
|
end
|
910
898
|
|
911
899
|
sink.assign!(sink.type.return_value)
|
912
|
-
|
900
|
+
interp.notify_variable_value_updated(expr, sink)
|
913
901
|
|
914
902
|
# NOTE: Returning a value via a pointer parameter can be considered as
|
915
903
|
# an evaluation of a statement-expression with a
|
916
904
|
# simple-assignment-expression.
|
917
905
|
# Control will reach to a sequence-point at the end of a full
|
918
906
|
# expression.
|
919
|
-
|
907
|
+
interp.notify_sequence_point_reached(
|
920
908
|
SequencePoint.new(funcall_expr, false))
|
921
909
|
end
|
922
910
|
end
|
@@ -925,9 +913,8 @@ module C #:nodoc:
|
|
925
913
|
class NamedFunction < Function
|
926
914
|
include Nameable
|
927
915
|
|
928
|
-
def initialize(
|
929
|
-
super(
|
930
|
-
|
916
|
+
def initialize(dcl_or_def, type, name)
|
917
|
+
super(dcl_or_def, type)
|
931
918
|
self.name = name
|
932
919
|
end
|
933
920
|
|
@@ -935,7 +922,7 @@ module C #:nodoc:
|
|
935
922
|
true
|
936
923
|
end
|
937
924
|
|
938
|
-
def call(
|
925
|
+
def call(*)
|
939
926
|
case name
|
940
927
|
when "exit", "_exit", "abort"
|
941
928
|
BreakEvent.of_return.throw
|
@@ -952,9 +939,8 @@ module C #:nodoc:
|
|
952
939
|
end
|
953
940
|
|
954
941
|
class ExplicitFunction < NamedFunction
|
955
|
-
def initialize(
|
956
|
-
super(
|
957
|
-
declaration_or_definition.identifier.value)
|
942
|
+
def initialize(dcl_or_def)
|
943
|
+
super(dcl_or_def, dcl_or_def.type, dcl_or_def.identifier.value)
|
958
944
|
end
|
959
945
|
|
960
946
|
def explicit?
|
@@ -998,14 +984,14 @@ module C #:nodoc:
|
|
998
984
|
end
|
999
985
|
|
1000
986
|
def signature
|
1001
|
-
FunctionSignature.new("
|
987
|
+
FunctionSignature.new("__adlint__anon_func", type)
|
1002
988
|
end
|
1003
989
|
end
|
1004
990
|
|
1005
991
|
class FunctionTable
|
1006
|
-
def initialize(
|
1007
|
-
@memory_pool =
|
1008
|
-
@functions
|
992
|
+
def initialize(mem_pool)
|
993
|
+
@memory_pool = mem_pool
|
994
|
+
@functions = [{}]
|
1009
995
|
@scope_stack = [GlobalScope.new]
|
1010
996
|
end
|
1011
997
|
|
@@ -1015,34 +1001,46 @@ module C #:nodoc:
|
|
1015
1001
|
end
|
1016
1002
|
|
1017
1003
|
def leave_scope
|
1018
|
-
@functions.pop.each_value do |
|
1019
|
-
@memory_pool.free(
|
1004
|
+
@functions.pop.each_value do |fun|
|
1005
|
+
@memory_pool.free(fun.binding.memory)
|
1020
1006
|
end
|
1021
1007
|
@scope_stack.pop
|
1022
1008
|
end
|
1023
1009
|
|
1024
|
-
def
|
1025
|
-
if
|
1026
|
-
|
1027
|
-
return
|
1010
|
+
def declare_explicitly(dcl)
|
1011
|
+
if fun = lookup(dcl.identifier.value) and fun.explicit?
|
1012
|
+
fun.declarations_and_definitions.push(dcl)
|
1013
|
+
return fun
|
1028
1014
|
end
|
1029
1015
|
|
1030
|
-
define(ExplicitFunction.new(
|
1016
|
+
define(ExplicitFunction.new(dcl))
|
1031
1017
|
end
|
1032
1018
|
|
1033
|
-
def
|
1019
|
+
def declare_implicitly(fun)
|
1020
|
+
if fun.named? && fun.implicit?
|
1021
|
+
define(fun, true)
|
1022
|
+
end
|
1023
|
+
fun
|
1024
|
+
end
|
1025
|
+
|
1026
|
+
def define(fun, in_global_scope = false)
|
1034
1027
|
# NOTE: A function has a starting address in the TEXT segment.
|
1035
1028
|
# This is ad-hoc implementation, but it's enough for analysis.
|
1036
|
-
|
1029
|
+
fun.bind_to(@memory_pool.allocate_static(0))
|
1037
1030
|
|
1038
|
-
|
1039
|
-
|
1031
|
+
if in_global_scope
|
1032
|
+
@functions.first[fun.name] = fun
|
1033
|
+
else
|
1034
|
+
@functions.last[fun.name] = fun if fun.named?
|
1035
|
+
end
|
1036
|
+
|
1037
|
+
fun
|
1040
1038
|
end
|
1041
1039
|
|
1042
1040
|
def lookup(name_str)
|
1043
1041
|
@functions.reverse_each do |hash|
|
1044
|
-
if
|
1045
|
-
return
|
1042
|
+
if fun = hash[name_str]
|
1043
|
+
return fun
|
1046
1044
|
end
|
1047
1045
|
end
|
1048
1046
|
nil
|
@@ -1052,10 +1050,10 @@ module C #:nodoc:
|
|
1052
1050
|
class Memory
|
1053
1051
|
include Bindable
|
1054
1052
|
|
1055
|
-
def initialize(
|
1056
|
-
@address
|
1053
|
+
def initialize(addr, byte_size)
|
1054
|
+
@address = addr
|
1057
1055
|
@byte_size = byte_size
|
1058
|
-
@value
|
1056
|
+
@value = nil
|
1059
1057
|
end
|
1060
1058
|
|
1061
1059
|
attr_reader :address
|
@@ -1073,39 +1071,38 @@ module C #:nodoc:
|
|
1073
1071
|
@value
|
1074
1072
|
end
|
1075
1073
|
|
1076
|
-
def write(
|
1074
|
+
def write(val)
|
1077
1075
|
if @value
|
1078
|
-
@value.overwrite!(
|
1076
|
+
@value.overwrite!(val)
|
1079
1077
|
else
|
1080
|
-
@value = VersionedValue.new(
|
1078
|
+
@value = VersionedValue.new(val)
|
1081
1079
|
end
|
1082
1080
|
end
|
1083
1081
|
end
|
1084
1082
|
|
1085
1083
|
class MemoryBlock < Memory
|
1086
|
-
def initialize(
|
1084
|
+
def initialize(addr, byte_size)
|
1087
1085
|
super
|
1088
|
-
|
1089
1086
|
@windows = []
|
1090
1087
|
end
|
1091
1088
|
|
1092
1089
|
attr_reader :windows
|
1093
1090
|
|
1094
1091
|
def create_window(offset, byte_size)
|
1095
|
-
|
1096
|
-
|
1097
|
-
@windows.push(
|
1098
|
-
|
1092
|
+
win = MemoryWindow.new(self, @address + offset, byte_size)
|
1093
|
+
win.on_written += method(:handle_written_through_window)
|
1094
|
+
@windows.push(win)
|
1095
|
+
win
|
1099
1096
|
end
|
1100
1097
|
|
1101
|
-
def write(
|
1098
|
+
def write(val)
|
1102
1099
|
super
|
1103
1100
|
if !@windows.empty? and
|
1104
|
-
@value.array? &&
|
1105
|
-
@value.composite? &&
|
1106
|
-
|
1107
|
-
@windows.zip(
|
1108
|
-
|
1101
|
+
@value.array? && val.array? or
|
1102
|
+
@value.composite? && val.composite?
|
1103
|
+
single_val = val.to_single_value
|
1104
|
+
@windows.zip(single_val.values).each do |win, inner_val|
|
1105
|
+
win.write(inner_val, false)
|
1109
1106
|
end
|
1110
1107
|
end
|
1111
1108
|
end
|
@@ -1123,20 +1120,20 @@ module C #:nodoc:
|
|
1123
1120
|
end
|
1124
1121
|
|
1125
1122
|
private
|
1126
|
-
def handle_written_through_window(
|
1127
|
-
|
1123
|
+
def handle_written_through_window(*)
|
1124
|
+
val = create_value_from_windows
|
1128
1125
|
|
1129
1126
|
if @value
|
1130
|
-
@value.overwrite!(
|
1127
|
+
@value.overwrite!(val)
|
1131
1128
|
else
|
1132
|
-
@value = VersionedValue.new(
|
1129
|
+
@value = VersionedValue.new(val)
|
1133
1130
|
end
|
1134
1131
|
end
|
1135
1132
|
end
|
1136
1133
|
|
1137
1134
|
class MemoryWindow < MemoryBlock
|
1138
|
-
def initialize(owner,
|
1139
|
-
super(
|
1135
|
+
def initialize(owner, addr, byte_size)
|
1136
|
+
super(addr, byte_size)
|
1140
1137
|
@owner = owner
|
1141
1138
|
end
|
1142
1139
|
|
@@ -1152,13 +1149,13 @@ module C #:nodoc:
|
|
1152
1149
|
@owner.dynamic?
|
1153
1150
|
end
|
1154
1151
|
|
1155
|
-
def write(
|
1156
|
-
super(
|
1152
|
+
def write(val, cascade = true)
|
1153
|
+
super(val)
|
1157
1154
|
on_written.invoke(self) if cascade
|
1158
1155
|
end
|
1159
1156
|
|
1160
1157
|
private
|
1161
|
-
def handle_written_through_window(
|
1158
|
+
def handle_written_through_window(*)
|
1162
1159
|
super
|
1163
1160
|
on_written.invoke(self)
|
1164
1161
|
end
|
@@ -1186,40 +1183,40 @@ module C #:nodoc:
|
|
1186
1183
|
|
1187
1184
|
class MemoryPool
|
1188
1185
|
def initialize
|
1189
|
-
@memory_blocks
|
1186
|
+
@memory_blocks = {}
|
1190
1187
|
@address_ranges = []
|
1191
1188
|
# NOTE: To make room for NULL and controlling expressions.
|
1192
1189
|
@free_address = 10
|
1193
1190
|
end
|
1194
1191
|
|
1195
1192
|
def allocate_static(byte_size)
|
1196
|
-
|
1193
|
+
mem_block = StaticMemoryBlock.new(@free_address, byte_size)
|
1197
1194
|
@free_address += allocating_byte_size(byte_size)
|
1198
|
-
@memory_blocks[
|
1199
|
-
@address_ranges.push(
|
1200
|
-
|
1195
|
+
@memory_blocks[mem_block.address] = mem_block
|
1196
|
+
@address_ranges.push(mem_block.address...@free_address)
|
1197
|
+
mem_block
|
1201
1198
|
end
|
1202
1199
|
|
1203
1200
|
def allocate_dynamic(byte_size)
|
1204
|
-
|
1201
|
+
mem_block = DynamicMemoryBlock.new(@free_address, byte_size)
|
1205
1202
|
@free_address += allocating_byte_size(byte_size)
|
1206
|
-
@memory_blocks[
|
1207
|
-
@address_ranges.push(
|
1208
|
-
|
1203
|
+
@memory_blocks[mem_block.address] = mem_block
|
1204
|
+
@address_ranges.push(mem_block.address...@free_address)
|
1205
|
+
mem_block
|
1209
1206
|
end
|
1210
1207
|
|
1211
|
-
def free(
|
1212
|
-
@memory_blocks.delete(
|
1213
|
-
@address_ranges.reject! { |range| range.include?(
|
1208
|
+
def free(mem_block)
|
1209
|
+
@memory_blocks.delete(mem_block.address)
|
1210
|
+
@address_ranges.reject! { |range| range.include?(mem_block.address) }
|
1214
1211
|
end
|
1215
1212
|
|
1216
|
-
def lookup(
|
1217
|
-
if
|
1218
|
-
return
|
1213
|
+
def lookup(addr)
|
1214
|
+
if mem_block = @memory_blocks[addr]
|
1215
|
+
return mem_block
|
1219
1216
|
else
|
1220
|
-
if addr_range = @address_ranges.find { |r| r.include?(
|
1221
|
-
|
1222
|
-
return
|
1217
|
+
if addr_range = @address_ranges.find { |r| r.include?(addr) }
|
1218
|
+
mem_block = @memory_blocks[addr_range.first]
|
1219
|
+
return mem_block.windows.find { |w| w.address == addr }
|
1223
1220
|
end
|
1224
1221
|
end
|
1225
1222
|
nil
|