adlint 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/AUTHORS +27 -0
- data/COPYING +674 -0
- data/ChangeLog +820 -0
- data/INSTALL +78 -0
- data/MANIFEST +464 -0
- data/NEWS +38 -0
- data/README +74 -0
- data/Rakefile +167 -0
- data/TODO +29 -0
- data/bin/adlint +141 -0
- data/bin/adlint_chk +129 -0
- data/bin/adlint_cma +122 -0
- data/bin/adlint_sma +129 -0
- data/bin/adlintize +286 -0
- data/etc/conf.d/fallback/cinit.erb +11 -0
- data/etc/conf.d/fallback/traits.erb +216 -0
- data/etc/conf.d/i686-cygwin/cinit-gcc_4.3.4.erb +149 -0
- data/etc/conf.d/i686-cygwin/traits-gcc_4.3.4.erb +227 -0
- data/etc/conf.d/i686-devkit/cinit-gcc_4.5.2.erb +224 -0
- data/etc/conf.d/i686-devkit/traits-gcc_4.5.2.erb +226 -0
- data/etc/conf.d/i686-linux/cinit-gcc_4.5.1.erb +219 -0
- data/etc/conf.d/i686-linux/traits-gcc_4.5.1.erb +224 -0
- data/etc/conf.d/i686-mingw/cinit-gcc_4.6.1.erb +234 -0
- data/etc/conf.d/i686-mingw/traits-gcc_4.6.1.erb +226 -0
- data/etc/conf.d/noarch/GNUmakefile.erb +119 -0
- data/etc/conf.d/noarch/adlint_all_bat.erb +9 -0
- data/etc/conf.d/noarch/adlint_all_sh.erb +10 -0
- data/etc/conf.d/noarch/pinit.erb +11 -0
- data/etc/mesg.d/en_US/messages.yml +784 -0
- data/etc/mesg.d/ja_JP/messages.yml +784 -0
- data/lib/adlint/analyzer.rb +294 -0
- data/lib/adlint/c/branch.rb +251 -0
- data/lib/adlint/c/builtin.rb +92 -0
- data/lib/adlint/c/code.rb +490 -0
- data/lib/adlint/c/const.rb +465 -0
- data/lib/adlint/c/conv.rb +212 -0
- data/lib/adlint/c/ctrlexpr.rb +949 -0
- data/lib/adlint/c/domain.rb +7499 -0
- data/lib/adlint/c/environ.rb +133 -0
- data/lib/adlint/c/expr.rb +1725 -0
- data/lib/adlint/c/format.rb +3209 -0
- data/lib/adlint/c/interp.rb +1740 -0
- data/lib/adlint/c/lexer.rb +241 -0
- data/lib/adlint/c/mediator.rb +313 -0
- data/lib/adlint/c/message.rb +13597 -0
- data/lib/adlint/c/metric.rb +765 -0
- data/lib/adlint/c/object.rb +1018 -0
- data/lib/adlint/c/parser.rb +3800 -0
- data/lib/adlint/c/parser.y +2054 -0
- data/lib/adlint/c/phase.rb +712 -0
- data/lib/adlint/c/resolver.rb +270 -0
- data/lib/adlint/c/scanner.rb +248 -0
- data/lib/adlint/c/scope.rb +74 -0
- data/lib/adlint/c/syntax.rb +4279 -0
- data/lib/adlint/c/type.rb +7506 -0
- data/lib/adlint/c/util.rb +91 -0
- data/lib/adlint/c/value.rb +2310 -0
- data/lib/adlint/c.rb +56 -0
- data/lib/adlint/code.rb +500 -0
- data/lib/adlint/cpp/code.rb +189 -0
- data/lib/adlint/cpp/constexpr.rb +721 -0
- data/lib/adlint/cpp/constexpr.y +389 -0
- data/lib/adlint/cpp/eval.rb +1012 -0
- data/lib/adlint/cpp/lexer.rb +860 -0
- data/lib/adlint/cpp/macro.rb +637 -0
- data/lib/adlint/cpp/message.rb +992 -0
- data/lib/adlint/cpp/phase.rb +176 -0
- data/lib/adlint/cpp/scanner.rb +93 -0
- data/lib/adlint/cpp/source.rb +169 -0
- data/lib/adlint/cpp/subst.rb +300 -0
- data/lib/adlint/cpp/syntax.rb +1412 -0
- data/lib/adlint/cpp/util.rb +97 -0
- data/lib/adlint/cpp.rb +43 -0
- data/lib/adlint/driver.rb +147 -0
- data/lib/adlint/error.rb +179 -0
- data/lib/adlint/lang.rb +97 -0
- data/lib/adlint/ld/message.rb +259 -0
- data/lib/adlint/ld/metric.rb +57 -0
- data/lib/adlint/ld/object.rb +542 -0
- data/lib/adlint/ld/phase.rb +193 -0
- data/lib/adlint/ld/typedef.rb +109 -0
- data/lib/adlint/ld/util.rb +88 -0
- data/lib/adlint/ld.rb +37 -0
- data/lib/adlint/lexer.rb +293 -0
- data/lib/adlint/message.rb +368 -0
- data/lib/adlint/metric.rb +805 -0
- data/lib/adlint/monitor.rb +144 -0
- data/lib/adlint/phase.rb +90 -0
- data/lib/adlint/prelude.rb +314 -0
- data/lib/adlint/report.rb +617 -0
- data/lib/adlint/source.rb +155 -0
- data/lib/adlint/symbol.rb +127 -0
- data/lib/adlint/token.rb +215 -0
- data/lib/adlint/traits.rb +643 -0
- data/lib/adlint/util.rb +524 -0
- data/lib/adlint/version.rb +71 -0
- data/lib/adlint.rb +66 -0
- data/share/HEADER +45 -0
- data/share/demo/Makefile +110 -0
- data/share/demo/ambig_operator/ambig_operator.c +289 -0
- data/share/demo/arg_points_unset/arg_points_unset.c +37 -0
- data/share/demo/array_range/array_range.c +62 -0
- data/share/demo/bad_bitfields/bad_bitfields.c +74 -0
- data/share/demo/bad_brace/bad_brace.c +19 -0
- data/share/demo/bad_charset/abcde$.h +0 -0
- data/share/demo/bad_charset/bad_charset.c +22 -0
- data/share/demo/bad_comment/bad_comment.c +3 -0
- data/share/demo/bad_const/bad_const.c +19 -0
- data/share/demo/bad_conv/bad_conv.c +48 -0
- data/share/demo/bad_indent/bad_indent.c +50 -0
- data/share/demo/bad_init/bad_init.c +49 -0
- data/share/demo/bad_macro/bad_macro.c +97 -0
- data/share/demo/bitwise_expr/bitwise_expr.c +19 -0
- data/share/demo/call_by_value/call_by_value.c +26 -0
- data/share/demo/cross_ref/cross_ref.c +21 -0
- data/share/demo/dangling_else/dangling_else.c +20 -0
- data/share/demo/dead_code/dead_code.c +237 -0
- data/share/demo/deep_nest/deep_nest.c +57 -0
- data/share/demo/dense_switch/dense_switch.c +62 -0
- data/share/demo/direct_recur/direct_recur.c +15 -0
- data/share/demo/div_by_zero/div_by_zero.c +35 -0
- data/share/demo/dos_source/dos_source.c +7 -0
- data/share/demo/funptr_cast/funptr_cast.c +26 -0
- data/share/demo/goto_stmt/goto_stmt.c +19 -0
- data/share/demo/id_hiding/id_hiding.c +19 -0
- data/share/demo/ill_defined/ill_defined.c +13 -0
- data/share/demo/implicit_conv/implicit_conv.c +60 -0
- data/share/demo/implicit_int/implicit_int.c +14 -0
- data/share/demo/incomplete_type/incomplete_type.c +49 -0
- data/share/demo/indirect_recur/indirect_recur_1.c +14 -0
- data/share/demo/indirect_recur/indirect_recur_1.h +7 -0
- data/share/demo/indirect_recur/indirect_recur_2.c +12 -0
- data/share/demo/indirect_recur/indirect_recur_2.h +6 -0
- data/share/demo/indirect_recur/indirect_recur_3.c +6 -0
- data/share/demo/indirect_recur/indirect_recur_3.h +6 -0
- data/share/demo/indirect_recur/indirect_recur_4.c +25 -0
- data/share/demo/intro_demo/intro_demo.c +76 -0
- data/share/demo/intro_demo/intro_demo.h +12 -0
- data/share/demo/intro_demo/useless_header.h +5 -0
- data/share/demo/invalid_call/invalid_call.c +32 -0
- data/share/demo/kandr_fundef/kandr_fundef.c +10 -0
- data/share/demo/line_comment/line_comment.c +12 -0
- data/share/demo/local_decl/local_decl.c +9 -0
- data/share/demo/logical_trick/logical_trick.c +36 -0
- data/share/demo/long_sym/long_sym.c +5 -0
- data/share/demo/loop_var/loop_var.c +92 -0
- data/share/demo/malloc_or_die/malloc_or_die.c +43 -0
- data/share/demo/may_be_null/may_be_null.c +52 -0
- data/share/demo/may_be_null_arith/may_be_null_arith.c +15 -0
- data/share/demo/may_be_unset/may_be_unset.c +34 -0
- data/share/demo/mmapped_io/mmapped_io.c +23 -0
- data/share/demo/multi_break/multi_break.c +33 -0
- data/share/demo/multi_decl/multi_decl_1.c +17 -0
- data/share/demo/multi_decl/multi_decl_1.h +6 -0
- data/share/demo/multi_decl/multi_decl_2.c +13 -0
- data/share/demo/multi_decl/multi_decl_2.h +6 -0
- data/share/demo/multi_decl/multi_decl_3.c +22 -0
- data/share/demo/multi_def/multi_def_1.c +36 -0
- data/share/demo/multi_def/multi_def_1.h +6 -0
- data/share/demo/multi_def/multi_def_2.c +22 -0
- data/share/demo/multi_def/multi_def_2.h +6 -0
- data/share/demo/multi_def/multi_def_3.c +6 -0
- data/share/demo/multi_typedef/multi_typedef.c +11 -0
- data/share/demo/multi_typedef/multi_typedef_1.h +1 -0
- data/share/demo/multi_typedef/multi_typedef_2.h +1 -0
- data/share/demo/must_be_false/must_be_false.c +53 -0
- data/share/demo/must_be_null/must_be_null.c +13 -0
- data/share/demo/must_be_null_arith/must_be_null_arith.c +14 -0
- data/share/demo/must_be_true/must_be_true.c +21 -0
- data/share/demo/no_eof_nl/no_eof_nl.c +4 -0
- data/share/demo/no_void_arg/no_void_arg.c +14 -0
- data/share/demo/null_stmt/null_stmt.c +19 -0
- data/share/demo/octal_const/octal_const.c +20 -0
- data/share/demo/output_by_param/output_by_param.c +17 -0
- data/share/demo/overflow/overflow.c +74 -0
- data/share/demo/press_release/press_release.c +40 -0
- data/share/demo/retn_lvar_addr/retn_lvar_addr.c +47 -0
- data/share/demo/shift_expr/shift_expr.c +14 -0
- data/share/demo/should_be_typedef/should_be_typedef.c +51 -0
- data/share/demo/static_paths/static_paths.c +153 -0
- data/share/demo/static_vars/static_vars.c +39 -0
- data/share/demo/tag_hiding/tag_hiding.c +18 -0
- data/share/demo/tricky_incdec/tricky_incdec.c +12 -0
- data/share/demo/undefined_macro/undefined_macro.c +17 -0
- data/share/demo/uninit_vars/uninit_vars.c +28 -0
- data/share/demo/union_type/union_type.c +23 -0
- data/share/demo/unmatch_decl/unmatch_decl_1.c +12 -0
- data/share/demo/unmatch_decl/unmatch_decl_1.h +8 -0
- data/share/demo/unmatch_decl/unmatch_decl_2.c +10 -0
- data/share/demo/unmatch_decl/unmatch_decl_2.h +8 -0
- data/share/demo/unmatch_decl/unmatch_decl_3.c +7 -0
- data/share/demo/unmatch_paren_macro/unmatch_paren_macro.c +15 -0
- data/share/demo/unreachable/unreachable.c +34 -0
- data/share/demo/useless_exp_funs/useless_exp_funs_1.c +14 -0
- data/share/demo/useless_exp_funs/useless_exp_funs_1.h +1 -0
- data/share/demo/useless_exp_funs/useless_exp_funs_2.c +6 -0
- data/share/demo/useless_exp_vars/useless_export_1.c +8 -0
- data/share/demo/useless_exp_vars/useless_export_1.h +1 -0
- data/share/demo/useless_exp_vars/useless_export_2.c +7 -0
- data/share/demo/useless_expr/useless_expr.c +17 -0
- data/share/demo/useless_funs/useless_funs_1.c +21 -0
- data/share/demo/useless_funs/useless_funs_1.h +8 -0
- data/share/demo/useless_funs/useless_funs_2.c +6 -0
- data/share/demo/useless_header/useless_header.c +9 -0
- data/share/demo/useless_header/useless_header_1.h +12 -0
- data/share/demo/useless_header/useless_header_2.h +6 -0
- data/share/demo/useless_header/useless_header_3.h +9 -0
- data/share/demo/useless_header/useless_header_4.h +3 -0
- data/share/demo/useless_vars/useless_vars.c +17 -0
- data/share/demo/va_funcall/va_funcall.c +25 -0
- data/share/demo/various_fundef/various_fundef.c +36 -0
- data/share/demo/wchar_wstring/wchar_wstring.c +7 -0
- data/share/demo/wrap_around/wrap_around.c +38 -0
- data/share/doc/Makefile +16 -0
- data/share/doc/adlint_on_adqua.png +0 -0
- data/share/doc/adlint_on_eclipse_en.png +0 -0
- data/share/doc/adlint_on_eclipse_ja.png +0 -0
- data/share/doc/adlint_on_vim_en.png +0 -0
- data/share/doc/adlint_on_vim_ja.png +0 -0
- data/share/doc/developers_guide_ja.html +171 -0
- data/share/doc/developers_guide_ja.texi +87 -0
- data/share/doc/gen_mesg_sections.rb +39 -0
- data/share/doc/samples/GNUmakefile +162 -0
- data/share/doc/samples/adlint_traits.yml +238 -0
- data/share/doc/texinfo.css +22 -0
- data/share/doc/users_guide_en.html +39975 -0
- data/share/doc/users_guide_en.texi +32640 -0
- data/share/doc/users_guide_ja.html +40505 -0
- data/share/doc/users_guide_ja.texi +33189 -0
- data/share/logo/adlint-110.png +0 -0
- data/share/logo/adlint-524.png +0 -0
- data/share/logo/adlint.svg +4637 -0
- data/share/sample/README +6 -0
- data/share/sample/bison-2.5/adlint/GNUmakefile +170 -0
- data/share/sample/bison-2.5/adlint/adlint_traits.yml +225 -0
- data/share/sample/bison-2.5/adlint/lib/GNUmakefile +198 -0
- data/share/sample/bison-2.5/adlint/lib/adlint_cinit.h +228 -0
- data/share/sample/bison-2.5/adlint/lib/adlint_pinit.h +21 -0
- data/share/sample/bison-2.5/adlint/lib/adlint_traits.yml +238 -0
- data/share/sample/bison-2.5/adlint/src/GNUmakefile +166 -0
- data/share/sample/bison-2.5/adlint/src/adlint_cinit.h +228 -0
- data/share/sample/bison-2.5/adlint/src/adlint_pinit.h +21 -0
- data/share/sample/bison-2.5/adlint/src/adlint_traits.yml +239 -0
- data/share/sample/ctags-5.8/adlint/GNUmakefile +169 -0
- data/share/sample/ctags-5.8/adlint/adlint_cinit.h +219 -0
- data/share/sample/ctags-5.8/adlint/adlint_pinit.h +13 -0
- data/share/sample/ctags-5.8/adlint/adlint_traits.yml +225 -0
- data/share/sample/flex-2.5.35/adlint/GNUmakefile +140 -0
- data/share/sample/flex-2.5.35/adlint/adlint_cinit.h +219 -0
- data/share/sample/flex-2.5.35/adlint/adlint_pinit.h +14 -0
- data/share/sample/flex-2.5.35/adlint/adlint_traits.yml +225 -0
- data/share/sample/ruby-1.9.3-p0/adlint/GNUmakefile +314 -0
- data/share/sample/ruby-1.9.3-p0/adlint/adlint_traits.yml +225 -0
- data/share/sample/ruby-1.9.3-p0/adlint/core/GNUmakefile +204 -0
- data/share/sample/ruby-1.9.3-p0/adlint/core/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/core/adlint_pinit.h +28 -0
- data/share/sample/ruby-1.9.3-p0/adlint/core/adlint_traits.yml +240 -0
- data/share/sample/ruby-1.9.3-p0/adlint/enc/GNUmakefile +163 -0
- data/share/sample/ruby-1.9.3-p0/adlint/enc/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/enc/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/enc/adlint_traits.yml +240 -0
- data/share/sample/ruby-1.9.3-p0/adlint/enc-trans/GNUmakefile +149 -0
- data/share/sample/ruby-1.9.3-p0/adlint/enc-trans/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/enc-trans/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/enc-trans/adlint_traits.yml +240 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-bigdecimal/GNUmakefile +131 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-bigdecimal/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-bigdecimal/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-bigdecimal/adlint_traits.yml +241 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-continuation/GNUmakefile +131 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-continuation/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-continuation/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-continuation/adlint_traits.yml +241 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-coverage/GNUmakefile +131 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-coverage/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-coverage/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-coverage/adlint_traits.yml +241 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-curses/GNUmakefile +131 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-curses/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-curses/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-curses/adlint_traits.yml +241 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-date/GNUmakefile +134 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-date/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-date/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-date/adlint_traits.yml +241 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-dbm/GNUmakefile +131 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-dbm/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-dbm/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-dbm/adlint_traits.yml +241 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest/GNUmakefile +131 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest/adlint_traits.yml +241 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-bubblebabble/GNUmakefile +131 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-bubblebabble/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-bubblebabble/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-bubblebabble/adlint_traits.yml +242 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-md5/GNUmakefile +132 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-md5/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-md5/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-md5/adlint_traits.yml +242 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-rmd160/GNUmakefile +132 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-rmd160/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-rmd160/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-rmd160/adlint_traits.yml +242 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha1/GNUmakefile +132 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha1/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha1/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha1/adlint_traits.yml +242 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha2/GNUmakefile +132 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha2/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha2/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha2/adlint_traits.yml +242 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-dl/GNUmakefile +134 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-dl/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-dl/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-dl/adlint_traits.yml +241 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-dl-callback/GNUmakefile +140 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-dl-callback/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-dl-callback/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-dl-callback/adlint_traits.yml +242 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-etc/GNUmakefile +131 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-etc/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-etc/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-etc/adlint_traits.yml +241 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-fcntl/GNUmakefile +131 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-fcntl/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-fcntl/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-fcntl/adlint_traits.yml +241 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-fiber/GNUmakefile +131 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-fiber/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-fiber/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-fiber/adlint_traits.yml +241 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-fiddle/GNUmakefile +134 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-fiddle/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-fiddle/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-fiddle/adlint_traits.yml +242 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-gdbm/GNUmakefile +131 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-gdbm/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-gdbm/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-gdbm/adlint_traits.yml +241 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-iconv/GNUmakefile +131 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-iconv/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-iconv/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-iconv/adlint_traits.yml +241 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-io-console/GNUmakefile +131 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-io-console/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-io-console/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-io-console/adlint_traits.yml +241 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-io-nonblock/GNUmakefile +131 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-io-nonblock/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-io-nonblock/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-io-nonblock/adlint_traits.yml +241 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-io-wait/GNUmakefile +131 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-io-wait/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-io-wait/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-io-wait/adlint_traits.yml +241 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-json-generator/GNUmakefile +131 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-json-generator/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-json-generator/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-json-generator/adlint_traits.yml +241 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-json-parser/GNUmakefile +131 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-json-parser/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-json-parser/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-json-parser/adlint_traits.yml +241 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-complex/GNUmakefile +131 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-complex/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-complex/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-complex/adlint_traits.yml +241 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-rational/GNUmakefile +131 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-rational/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-rational/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-rational/adlint_traits.yml +241 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-nkf/GNUmakefile +131 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-nkf/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-nkf/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-nkf/adlint_traits.yml +241 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-openssl/GNUmakefile +162 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-openssl/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-openssl/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-openssl/adlint_traits.yml +241 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-pathname/GNUmakefile +131 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-pathname/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-pathname/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-pathname/adlint_traits.yml +241 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-psych/GNUmakefile +135 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-psych/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-psych/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-psych/adlint_traits.yml +241 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-pty/GNUmakefile +131 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-pty/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-pty/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-pty/adlint_traits.yml +241 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-racc-cparse/GNUmakefile +131 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-racc-cparse/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-racc-cparse/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-racc-cparse/adlint_traits.yml +241 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-readline/GNUmakefile +131 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-readline/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-readline/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-readline/adlint_traits.yml +241 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-ripper/GNUmakefile +131 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-ripper/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-ripper/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-ripper/adlint_traits.yml +241 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-sdbm/GNUmakefile +132 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-sdbm/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-sdbm/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-sdbm/adlint_traits.yml +241 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-socket/GNUmakefile +144 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-socket/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-socket/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-socket/adlint_traits.yml +241 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-stringio/GNUmakefile +131 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-stringio/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-stringio/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-stringio/adlint_traits.yml +241 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-strscan/GNUmakefile +131 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-strscan/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-strscan/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-strscan/adlint_traits.yml +241 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-syck/GNUmakefile +140 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-syck/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-syck/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-syck/adlint_traits.yml +241 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-syslog/GNUmakefile +131 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-syslog/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-syslog/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-syslog/adlint_traits.yml +241 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-zlib/GNUmakefile +131 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-zlib/adlint_cinit.h +228 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-zlib/adlint_pinit.h +24 -0
- data/share/sample/ruby-1.9.3-p0/adlint/ext-zlib/adlint_traits.yml +241 -0
- data/share/sample/screen-4.0.3/adlint/GNUmakefile +162 -0
- data/share/sample/screen-4.0.3/adlint/adlint_cinit.h +228 -0
- data/share/sample/screen-4.0.3/adlint/adlint_pinit.h +21 -0
- data/share/sample/screen-4.0.3/adlint/adlint_traits.yml +238 -0
- data/share/sample/vim-7.3/adlint/vim/GNUmakefile +185 -0
- data/share/sample/vim-7.3/adlint/vim/adlint_cinit.h +228 -0
- data/share/sample/vim-7.3/adlint/vim/adlint_pinit.h +25 -0
- data/share/sample/vim-7.3/adlint/vim/adlint_traits.yml +250 -0
- data/share/sample/vim-7.3/adlint/xxd/GNUmakefile +131 -0
- data/share/sample/vim-7.3/adlint/xxd/adlint_cinit.h +228 -0
- data/share/sample/vim-7.3/adlint/xxd/adlint_pinit.h +24 -0
- data/share/sample/vim-7.3/adlint/xxd/adlint_traits.yml +237 -0
- data/share/sample/zsh-4.3.15/adlint/GNUmakefile +146 -0
- data/share/sample/zsh-4.3.15/adlint/adlint_traits.yml +225 -0
- data/share/sample/zsh-4.3.15/adlint/builtins/GNUmakefile +132 -0
- data/share/sample/zsh-4.3.15/adlint/builtins/adlint_cinit.h +228 -0
- data/share/sample/zsh-4.3.15/adlint/builtins/adlint_pinit.h +24 -0
- data/share/sample/zsh-4.3.15/adlint/builtins/adlint_traits.yml +240 -0
- data/share/sample/zsh-4.3.15/adlint/core/GNUmakefile +153 -0
- data/share/sample/zsh-4.3.15/adlint/core/adlint_cinit.h +228 -0
- data/share/sample/zsh-4.3.15/adlint/core/adlint_pinit.h +23 -0
- data/share/sample/zsh-4.3.15/adlint/core/adlint_traits.yml +239 -0
- data/share/sample/zsh-4.3.15/adlint/modules/GNUmakefile +147 -0
- data/share/sample/zsh-4.3.15/adlint/modules/adlint_cinit.h +228 -0
- data/share/sample/zsh-4.3.15/adlint/modules/adlint_pinit.h +24 -0
- data/share/sample/zsh-4.3.15/adlint/modules/adlint_traits.yml +240 -0
- data/share/sample/zsh-4.3.15/adlint/zle/GNUmakefile +144 -0
- data/share/sample/zsh-4.3.15/adlint/zle/adlint_cinit.h +228 -0
- data/share/sample/zsh-4.3.15/adlint/zle/adlint_pinit.h +24 -0
- data/share/sample/zsh-4.3.15/adlint/zle/adlint_traits.yml +239 -0
- data/spec/MUST_WRITE_SPECS_WITH_RSPEC +0 -0
- metadata +532 -0
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
# C constant-expression evaluator.
|
|
2
|
+
#
|
|
3
|
+
# Author:: Yutaka Yanoh <mailto:yanoh@users.sourceforge.net>
|
|
4
|
+
# Copyright:: Copyright (C) 2010-2012, OGIS-RI Co.,Ltd.
|
|
5
|
+
# License:: GPLv3+: GNU General Public License version 3 or later
|
|
6
|
+
#
|
|
7
|
+
# Owner:: Yutaka Yanoh <mailto:yanoh@users.sourceforge.net>
|
|
8
|
+
|
|
9
|
+
#--
|
|
10
|
+
# ___ ____ __ ___ _________
|
|
11
|
+
# / | / _ |/ / / / | / /__ __/ Source Code Static Analyzer
|
|
12
|
+
# / /| | / / / / / / / |/ / / / AdLint - Advanced Lint
|
|
13
|
+
# / __ |/ /_/ / /___/ / /| / / /
|
|
14
|
+
# /_/ |_|_____/_____/_/_/ |_/ /_/ Copyright (C) 2010-2012, OGIS-RI Co.,Ltd.
|
|
15
|
+
#
|
|
16
|
+
# This file is part of AdLint.
|
|
17
|
+
#
|
|
18
|
+
# AdLint is free software: you can redistribute it and/or modify it under the
|
|
19
|
+
# terms of the GNU General Public License as published by the Free Software
|
|
20
|
+
# Foundation, either version 3 of the License, or (at your option) any later
|
|
21
|
+
# version.
|
|
22
|
+
#
|
|
23
|
+
# AdLint is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
24
|
+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
25
|
+
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
26
|
+
#
|
|
27
|
+
# You should have received a copy of the GNU General Public License along with
|
|
28
|
+
# AdLint. If not, see <http://www.gnu.org/licenses/>.
|
|
29
|
+
#
|
|
30
|
+
#++
|
|
31
|
+
|
|
32
|
+
module AdLint #:nodoc:
|
|
33
|
+
module C #:nodoc:
|
|
34
|
+
|
|
35
|
+
module ConstantEvaluator
|
|
36
|
+
# NOTE: Host class of this module must include InterpreterMediator.
|
|
37
|
+
|
|
38
|
+
def eval_constant(constant_specifier)
|
|
39
|
+
eval_as_integer_constant(constant_specifier.constant.value) or
|
|
40
|
+
eval_as_floating_constant(constant_specifier.constant.value) or
|
|
41
|
+
eval_as_character_constant(constant_specifier.constant.value)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
private
|
|
45
|
+
def eval_as_integer_constant(value)
|
|
46
|
+
# NOTE: The ISO C99 standard saids;
|
|
47
|
+
#
|
|
48
|
+
# 6.4.4.1 Integer constants
|
|
49
|
+
#
|
|
50
|
+
# 5 The type of an integer constant is the first of the corresponding
|
|
51
|
+
# list in which its value can be represented.
|
|
52
|
+
#
|
|
53
|
+
# | decimal | octal or hexadecimal
|
|
54
|
+
# ------------+------------------------+------------------------
|
|
55
|
+
# unsuffixed | int | int
|
|
56
|
+
# | long int | unsigned int
|
|
57
|
+
# | long long int | long int
|
|
58
|
+
# | | unsigned long int
|
|
59
|
+
# | | long long int
|
|
60
|
+
# | | unsigned long long int
|
|
61
|
+
# ------------+------------------------+------------------------
|
|
62
|
+
# u or U | unsigned int | unsigned int
|
|
63
|
+
# | unsigned long int | unsigned long int
|
|
64
|
+
# | unsigned long long int | unsigned long long int
|
|
65
|
+
# ------------+------------------------+------------------------
|
|
66
|
+
# l or L | long int | long int
|
|
67
|
+
# | long long int | unsigned long int
|
|
68
|
+
# | | long long int
|
|
69
|
+
# | | unsigned long long int
|
|
70
|
+
# ------------+------------------------+------------------------
|
|
71
|
+
# u or U and | unsigned long int | unsigned long int
|
|
72
|
+
# l or L | unsigned long long int | unsigned long long int
|
|
73
|
+
# ------------+------------------------+------------------------
|
|
74
|
+
# ll or LL | long long int | long long int
|
|
75
|
+
# | | unsigned long long int
|
|
76
|
+
# ------------+------------------------+------------------------
|
|
77
|
+
# u or U and | unsigned long long int | unsigned long long int
|
|
78
|
+
# ll or LL | |
|
|
79
|
+
|
|
80
|
+
# NOTE: For binary constants.
|
|
81
|
+
case value
|
|
82
|
+
when /\A0b([01]+)(?:ULL|LLU)\z/i
|
|
83
|
+
return eval_as_non_decimal_integer_constant_with_ull($1.to_i(2))
|
|
84
|
+
when /\A0b([01]+)LL\z/i
|
|
85
|
+
return eval_as_non_decimal_integer_constant_with_ll($1.to_i(2))
|
|
86
|
+
when /\A0b([01]+)(?:UL|LU)\z/i
|
|
87
|
+
return eval_as_non_decimal_integer_constant_with_ul($1.to_i(2))
|
|
88
|
+
when /\A0b([01]+)L\z/i
|
|
89
|
+
return eval_as_non_decimal_integer_constant_with_l($1.to_i(2))
|
|
90
|
+
when /\A0b([01]+)U\z/i
|
|
91
|
+
return eval_as_non_decimal_integer_constant_with_u($1.to_i(2))
|
|
92
|
+
when /\A0b([01]+)\z/i
|
|
93
|
+
return eval_as_non_decimal_integer_constant_unsuffixed($1.to_i(2))
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# NOTE: For octal constants.
|
|
97
|
+
case value
|
|
98
|
+
when /\A0([0-9]+)(?:ULL|LLU)\z/i
|
|
99
|
+
return eval_as_non_decimal_integer_constant_with_ull($1.to_i(8))
|
|
100
|
+
when /\A0([0-9]+)LL\z/i
|
|
101
|
+
return eval_as_non_decimal_integer_constant_with_ll($1.to_i(8))
|
|
102
|
+
when /\A0([0-9]+)(?:UL|LU)\z/i
|
|
103
|
+
return eval_as_non_decimal_integer_constant_with_ul($1.to_i(8))
|
|
104
|
+
when /\A0([0-9]+)L\z/i
|
|
105
|
+
return eval_as_non_decimal_integer_constant_with_l($1.to_i(8))
|
|
106
|
+
when /\A0([0-9]+)U\z/i
|
|
107
|
+
return eval_as_non_decimal_integer_constant_with_u($1.to_i(8))
|
|
108
|
+
when /\A0([0-9]+)\z/
|
|
109
|
+
return eval_as_non_decimal_integer_constant_unsuffixed($1.to_i(8))
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# NOTE: For decimal constants.
|
|
113
|
+
case value
|
|
114
|
+
when /\A([0-9]+)(?:ULL|LLU)\z/i
|
|
115
|
+
return eval_as_decimal_integer_constant_with_ull($1.to_i(10))
|
|
116
|
+
when /\A([0-9]+)LL\z/i
|
|
117
|
+
return eval_as_decimal_integer_constant_with_ll($1.to_i(10))
|
|
118
|
+
when /\A([0-9]+)(?:UL|LU)\z/i
|
|
119
|
+
return eval_as_decimal_integer_constant_with_ul($1.to_i(10))
|
|
120
|
+
when /\A([0-9]+)L\z/i
|
|
121
|
+
return eval_as_decimal_integer_constant_with_l($1.to_i(10))
|
|
122
|
+
when /\A([0-9]+)U\z/i
|
|
123
|
+
return eval_as_decimal_integer_constant_with_u($1.to_i(10))
|
|
124
|
+
when /\A([0-9]+)\z/
|
|
125
|
+
return eval_as_decimal_integer_constant_unsuffixed($1.to_i(10))
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# NOTE: For hexadecimal constants.
|
|
129
|
+
case value
|
|
130
|
+
when /\A0x([0-9A-F]+)(?:ULL|LLU)\z/i
|
|
131
|
+
return eval_as_non_decimal_integer_constant_with_ull($1.to_i(16))
|
|
132
|
+
when /\A0x([0-9A-F]+)LL\z/i
|
|
133
|
+
return eval_as_non_decimal_integer_constant_with_ll($1.to_i(16))
|
|
134
|
+
when /\A0x([0-9A-F]+)(?:UL|LU)\z/i
|
|
135
|
+
return eval_as_non_decimal_integer_constant_with_ul($1.to_i(16))
|
|
136
|
+
when /\A0x([0-9A-F]+)L\z/i
|
|
137
|
+
return eval_as_non_decimal_integer_constant_with_l($1.to_i(16))
|
|
138
|
+
when /\A0x([0-9A-F]+)U\z/i
|
|
139
|
+
return eval_as_non_decimal_integer_constant_with_u($1.to_i(16))
|
|
140
|
+
when /\A0x([0-9A-F]+)\z/i
|
|
141
|
+
return eval_as_non_decimal_integer_constant_unsuffixed($1.to_i(16))
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
nil
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def eval_as_floating_constant(value)
|
|
148
|
+
# TODO: Must implement hexadecimal-floating-constant evaluation.
|
|
149
|
+
case value
|
|
150
|
+
when /\A([0-9]*\.[0-9]*E[+-]?[0-9]+)\z/i,
|
|
151
|
+
/\A([0-9]+\.?E[+-]?[0-9]+)\z/i,
|
|
152
|
+
/\A([0-9]*\.[0-9]+|[0-9]+\.)\z/
|
|
153
|
+
return temporary_variable(double_type, ScalarValue.of($1.to_f))
|
|
154
|
+
when /\A([0-9]*\.[0-9]*E[+-]?[0-9]+)F\z/i,
|
|
155
|
+
/\A([0-9]+\.?E[+-]?[0-9]+)F\z/i,
|
|
156
|
+
/\A([0-9]*\.[0-9]+|[0-9]+\.)F\z/i
|
|
157
|
+
return temporary_variable(float_type, ScalarValue.of($1.to_f))
|
|
158
|
+
when /\A([0-9]*\.[0-9]*E[+-]?[0-9]+)L\z/i,
|
|
159
|
+
/\A([0-9]+\.?E[+-]?[0-9]+)L\z/i,
|
|
160
|
+
/\A([0-9]*\.[0-9]+|[0-9]+\.)L\z/i
|
|
161
|
+
return temporary_variable(long_double_type, ScalarValue.of($1.to_f))
|
|
162
|
+
end
|
|
163
|
+
nil
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def eval_as_character_constant(value)
|
|
167
|
+
if value =~ /\A(L?)'(.*)'\z/i
|
|
168
|
+
case $2.length
|
|
169
|
+
when 0
|
|
170
|
+
char_code = 0
|
|
171
|
+
when 1
|
|
172
|
+
char_code = $2[0].ord
|
|
173
|
+
else
|
|
174
|
+
char_code = $2[0] == "\\" ? EscapeSequence.new($2).value : $2[0].ord
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
if $1 == "L"
|
|
178
|
+
temporary_variable(wchar_type, ScalarValue.of(char_code))
|
|
179
|
+
else
|
|
180
|
+
temporary_variable(int_type, ScalarValue.of(char_code))
|
|
181
|
+
end
|
|
182
|
+
else
|
|
183
|
+
nil
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
def eval_as_decimal_integer_constant_unsuffixed(value)
|
|
188
|
+
case
|
|
189
|
+
when int_value_range.include?(value)
|
|
190
|
+
temporary_variable(int_type, ScalarValue.of(value))
|
|
191
|
+
when long_int_value_range.include?(value)
|
|
192
|
+
temporary_variable(long_int_type, ScalarValue.of(value))
|
|
193
|
+
when long_long_int_value_range.include?(value)
|
|
194
|
+
temporary_variable(long_long_int_type, ScalarValue.of(value))
|
|
195
|
+
else
|
|
196
|
+
# NOTE: The ISO C99 standard saids;
|
|
197
|
+
#
|
|
198
|
+
# 6.4.4.1 Integer constants
|
|
199
|
+
#
|
|
200
|
+
# 6 If an integer constant cannot be represented by any type in its
|
|
201
|
+
# list and has no extended integer type, then the integer constant
|
|
202
|
+
# has no type.
|
|
203
|
+
#
|
|
204
|
+
# NOTE: Use ExtendedBigIntType for unrepresentable integer constants.
|
|
205
|
+
temporary_variable(extended_big_int_type, ScalarValue.of(value))
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
def eval_as_decimal_integer_constant_with_u(value)
|
|
210
|
+
case
|
|
211
|
+
when unsigned_int_value_range.include?(value)
|
|
212
|
+
temporary_variable(unsigned_int_type, ScalarValue.of(value))
|
|
213
|
+
when unsigned_long_int_value_range.include?(value)
|
|
214
|
+
temporary_variable(unsigned_long_int_type, ScalarValue.of(value))
|
|
215
|
+
when unsigned_long_long_int_value_range.include?(value)
|
|
216
|
+
temporary_variable(unsigned_long_long_int_type, ScalarValue.of(value))
|
|
217
|
+
else
|
|
218
|
+
# NOTE: The ISO C99 standard saids;
|
|
219
|
+
#
|
|
220
|
+
# 6.4.4.1 Integer constants
|
|
221
|
+
#
|
|
222
|
+
# 6 If an integer constant cannot be represented by any type in its
|
|
223
|
+
# list and has no extended integer type, then the integer constant
|
|
224
|
+
# has no type.
|
|
225
|
+
#
|
|
226
|
+
# NOTE: Use ExtendedBigIntType for unrepresentable integer constants.
|
|
227
|
+
temporary_variable(extended_big_int_type, ScalarValue.of(value))
|
|
228
|
+
end
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
def eval_as_decimal_integer_constant_with_l(value)
|
|
232
|
+
case
|
|
233
|
+
when long_int_value_range.include?(value)
|
|
234
|
+
temporary_variable(long_int_type, ScalarValue.of(value))
|
|
235
|
+
when long_long_int_value_range.include?(value)
|
|
236
|
+
temporary_variable(long_long_int_type, ScalarValue.of(value))
|
|
237
|
+
else
|
|
238
|
+
# NOTE: The ISO C99 standard saids;
|
|
239
|
+
#
|
|
240
|
+
# 6.4.4.1 Integer constants
|
|
241
|
+
#
|
|
242
|
+
# 6 If an integer constant cannot be represented by any type in its
|
|
243
|
+
# list and has no extended integer type, then the integer constant
|
|
244
|
+
# has no type.
|
|
245
|
+
#
|
|
246
|
+
# NOTE: Use ExtendedBigIntType for unrepresentable integer constants.
|
|
247
|
+
temporary_variable(extended_big_int_type, ScalarValue.of(value))
|
|
248
|
+
end
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
def eval_as_decimal_integer_constant_with_ul(value)
|
|
252
|
+
case
|
|
253
|
+
when unsigned_long_int_value_range.include?(value)
|
|
254
|
+
temporary_variable(unsigned_long_int_type, ScalarValue.of(value))
|
|
255
|
+
when unsigned_long_long_int_value_range.include?(value)
|
|
256
|
+
temporary_variable(unsigned_long_long_int_type, ScalarValue.of(value))
|
|
257
|
+
else
|
|
258
|
+
# NOTE: The ISO C99 standard saids;
|
|
259
|
+
#
|
|
260
|
+
# 6.4.4.1 Integer constants
|
|
261
|
+
#
|
|
262
|
+
# 6 If an integer constant cannot be represented by any type in its
|
|
263
|
+
# list and has no extended integer type, then the integer constant
|
|
264
|
+
# has no type.
|
|
265
|
+
#
|
|
266
|
+
# NOTE: Use ExtendedBigIntType for unrepresentable integer constants.
|
|
267
|
+
temporary_variable(extended_big_int_type, ScalarValue.of(value))
|
|
268
|
+
end
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
def eval_as_decimal_integer_constant_with_ll(value)
|
|
272
|
+
case
|
|
273
|
+
when long_long_int_value_range.include?(value)
|
|
274
|
+
temporary_variable(long_long_int_type, ScalarValue.of(value))
|
|
275
|
+
else
|
|
276
|
+
# NOTE: The ISO C99 standard saids;
|
|
277
|
+
#
|
|
278
|
+
# 6.4.4.1 Integer constants
|
|
279
|
+
#
|
|
280
|
+
# 6 If an integer constant cannot be represented by any type in its
|
|
281
|
+
# list and has no extended integer type, then the integer constant
|
|
282
|
+
# has no type.
|
|
283
|
+
#
|
|
284
|
+
# NOTE: Use ExtendedBigIntType for unrepresentable integer constants.
|
|
285
|
+
temporary_variable(extended_big_int_type, ScalarValue.of(value))
|
|
286
|
+
end
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
def eval_as_decimal_integer_constant_with_ull(value)
|
|
290
|
+
case
|
|
291
|
+
when unsigned_long_long_int_value_range.include?(value)
|
|
292
|
+
temporary_variable(unsigned_long_long_int_type, ScalarValue.of(value))
|
|
293
|
+
else
|
|
294
|
+
# NOTE: The ISO C99 standard saids;
|
|
295
|
+
#
|
|
296
|
+
# 6.4.4.1 Integer constants
|
|
297
|
+
#
|
|
298
|
+
# 6 If an integer constant cannot be represented by any type in its
|
|
299
|
+
# list and has no extended integer type, then the integer constant
|
|
300
|
+
# has no type.
|
|
301
|
+
#
|
|
302
|
+
# NOTE: Use ExtendedBigIntType for unrepresentable integer constants.
|
|
303
|
+
temporary_variable(extended_big_int_type, ScalarValue.of(value))
|
|
304
|
+
end
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
def eval_as_non_decimal_integer_constant_unsuffixed(value)
|
|
308
|
+
case
|
|
309
|
+
when int_value_range.include?(value)
|
|
310
|
+
temporary_variable(int_type, ScalarValue.of(value))
|
|
311
|
+
when unsigned_int_value_range.include?(value)
|
|
312
|
+
temporary_variable(unsigned_int_type, ScalarValue.of(value))
|
|
313
|
+
when long_int_value_range.include?(value)
|
|
314
|
+
temporary_variable(long_int_type, ScalarValue.of(value))
|
|
315
|
+
when unsigned_long_int_value_range.include?(value)
|
|
316
|
+
temporary_variable(unsigned_long_int_type, ScalarValue.of(value))
|
|
317
|
+
when long_long_int_value_range.include?(value)
|
|
318
|
+
temporary_variable(long_long_int_type, ScalarValue.of(value))
|
|
319
|
+
when unsigned_long_long_int_value_range.include?(value)
|
|
320
|
+
temporary_variable(unsigned_long_long_int_type, ScalarValue.of(value))
|
|
321
|
+
else
|
|
322
|
+
# NOTE: The ISO C99 standard saids;
|
|
323
|
+
#
|
|
324
|
+
# 6.4.4.1 Integer constants
|
|
325
|
+
#
|
|
326
|
+
# 6 If an integer constant cannot be represented by any type in its
|
|
327
|
+
# list and has no extended integer type, then the integer constant
|
|
328
|
+
# has no type.
|
|
329
|
+
#
|
|
330
|
+
# NOTE: Use ExtendedBigIntType for unrepresentable integer constants.
|
|
331
|
+
temporary_variable(extended_big_int_type, ScalarValue.of(value))
|
|
332
|
+
end
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
def eval_as_non_decimal_integer_constant_with_u(value)
|
|
336
|
+
case
|
|
337
|
+
when unsigned_int_value_range.include?(value)
|
|
338
|
+
temporary_variable(unsigned_int_type, ScalarValue.of(value))
|
|
339
|
+
when unsigned_long_int_value_range.include?(value)
|
|
340
|
+
temporary_variable(unsigned_long_int_type, ScalarValue.of(value))
|
|
341
|
+
when unsigned_long_long_int_value_range.include?(value)
|
|
342
|
+
temporary_variable(unsigned_long_long_int_type, ScalarValue.of(value))
|
|
343
|
+
else
|
|
344
|
+
# NOTE: The ISO C99 standard saids;
|
|
345
|
+
#
|
|
346
|
+
# 6.4.4.1 Integer constants
|
|
347
|
+
#
|
|
348
|
+
# 6 If an integer constant cannot be represented by any type in its
|
|
349
|
+
# list and has no extended integer type, then the integer constant
|
|
350
|
+
# has no type.
|
|
351
|
+
#
|
|
352
|
+
# NOTE: Use ExtendedBigIntType for unrepresentable integer constants.
|
|
353
|
+
temporary_variable(extended_big_int_type, ScalarValue.of(value))
|
|
354
|
+
end
|
|
355
|
+
end
|
|
356
|
+
|
|
357
|
+
def eval_as_non_decimal_integer_constant_with_l(value)
|
|
358
|
+
case
|
|
359
|
+
when long_int_value_range.include?(value)
|
|
360
|
+
temporary_variable(long_int_type, ScalarValue.of(value))
|
|
361
|
+
when unsigned_long_int_value_range.include?(value)
|
|
362
|
+
temporary_variable(unsigned_long_int_type, ScalarValue.of(value))
|
|
363
|
+
when long_long_int_value_range.include?(value)
|
|
364
|
+
temporary_variable(long_long_int_type, ScalarValue.of(value))
|
|
365
|
+
when unsigned_long_long_int_value_range.include?(value)
|
|
366
|
+
temporary_variable(unsigned_long_long_int_type, ScalarValue.of(value))
|
|
367
|
+
else
|
|
368
|
+
# NOTE: The ISO C99 standard saids;
|
|
369
|
+
#
|
|
370
|
+
# 6.4.4.1 Integer constants
|
|
371
|
+
#
|
|
372
|
+
# 6 If an integer constant cannot be represented by any type in its
|
|
373
|
+
# list and has no extended integer type, then the integer constant
|
|
374
|
+
# has no type.
|
|
375
|
+
#
|
|
376
|
+
# NOTE: Use ExtendedBigIntType for unrepresentable integer constants.
|
|
377
|
+
temporary_variable(extended_big_int_type, ScalarValue.of(value))
|
|
378
|
+
end
|
|
379
|
+
end
|
|
380
|
+
|
|
381
|
+
def eval_as_non_decimal_integer_constant_with_ul(value)
|
|
382
|
+
case
|
|
383
|
+
when unsigned_long_int_value_range.include?(value)
|
|
384
|
+
temporary_variable(unsigned_long_int_type, ScalarValue.of(value))
|
|
385
|
+
when unsigned_long_long_int_value_range.include?(value)
|
|
386
|
+
temporary_variable(unsigned_long_long_int_type, ScalarValue.of(value))
|
|
387
|
+
else
|
|
388
|
+
# NOTE: The ISO C99 standard saids;
|
|
389
|
+
#
|
|
390
|
+
# 6.4.4.1 Integer constants
|
|
391
|
+
#
|
|
392
|
+
# 6 If an integer constant cannot be represented by any type in its
|
|
393
|
+
# list and has no extended integer type, then the integer constant
|
|
394
|
+
# has no type.
|
|
395
|
+
#
|
|
396
|
+
# NOTE: Use ExtendedBigIntType for unrepresentable integer constants.
|
|
397
|
+
temporary_variable(extended_big_int_type, ScalarValue.of(value))
|
|
398
|
+
end
|
|
399
|
+
end
|
|
400
|
+
|
|
401
|
+
def eval_as_non_decimal_integer_constant_with_ll(value)
|
|
402
|
+
case
|
|
403
|
+
when long_long_int_value_range.include?(value)
|
|
404
|
+
temporary_variable(long_long_int_type, ScalarValue.of(value))
|
|
405
|
+
when unsigned_long_long_int_value_range.include?(value)
|
|
406
|
+
temporary_variable(unsigned_long_long_int_type, ScalarValue.of(value))
|
|
407
|
+
else
|
|
408
|
+
# NOTE: The ISO C99 standard saids;
|
|
409
|
+
#
|
|
410
|
+
# 6.4.4.1 Integer constants
|
|
411
|
+
#
|
|
412
|
+
# 6 If an integer constant cannot be represented by any type in its
|
|
413
|
+
# list and has no extended integer type, then the integer constant
|
|
414
|
+
# has no type.
|
|
415
|
+
#
|
|
416
|
+
# NOTE: Use ExtendedBigIntType for unrepresentable integer constants.
|
|
417
|
+
temporary_variable(extended_big_int_type, ScalarValue.of(value))
|
|
418
|
+
end
|
|
419
|
+
end
|
|
420
|
+
|
|
421
|
+
def eval_as_non_decimal_integer_constant_with_ull(value)
|
|
422
|
+
case
|
|
423
|
+
when unsigned_long_long_int_value_range.include?(value)
|
|
424
|
+
temporary_variable(unsigned_long_long_int_type, ScalarValue.of(value))
|
|
425
|
+
else
|
|
426
|
+
# NOTE: The ISO C99 standard saids;
|
|
427
|
+
#
|
|
428
|
+
# 6.4.4.1 Integer constants
|
|
429
|
+
#
|
|
430
|
+
# 6 If an integer constant cannot be represented by any type in its
|
|
431
|
+
# list and has no extended integer type, then the integer constant
|
|
432
|
+
# has no type.
|
|
433
|
+
#
|
|
434
|
+
# NOTE: Use ExtendedBigIntType for unrepresentable integer constants.
|
|
435
|
+
temporary_variable(extended_big_int_type, ScalarValue.of(value))
|
|
436
|
+
end
|
|
437
|
+
end
|
|
438
|
+
|
|
439
|
+
def int_value_range
|
|
440
|
+
int_type.min_value..int_type.max_value
|
|
441
|
+
end
|
|
442
|
+
|
|
443
|
+
def long_int_value_range
|
|
444
|
+
long_int_type.min_value..long_int_type.max_value
|
|
445
|
+
end
|
|
446
|
+
|
|
447
|
+
def long_long_int_value_range
|
|
448
|
+
long_long_int_type.min_value..long_long_int_type.max_value
|
|
449
|
+
end
|
|
450
|
+
|
|
451
|
+
def unsigned_int_value_range
|
|
452
|
+
unsigned_int_type.min_value..unsigned_int_type.max_value
|
|
453
|
+
end
|
|
454
|
+
|
|
455
|
+
def unsigned_long_int_value_range
|
|
456
|
+
unsigned_long_int_type.min_value..unsigned_long_int_type.max_value
|
|
457
|
+
end
|
|
458
|
+
|
|
459
|
+
def unsigned_long_long_int_value_range
|
|
460
|
+
unsigned_long_long_type.min_value..unsigned_long_long_type.max_value
|
|
461
|
+
end
|
|
462
|
+
end
|
|
463
|
+
|
|
464
|
+
end
|
|
465
|
+
end
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
# C conversion semantics.
|
|
2
|
+
#
|
|
3
|
+
# Author:: Yutaka Yanoh <mailto:yanoh@users.sourceforge.net>
|
|
4
|
+
# Copyright:: Copyright (C) 2010-2012, OGIS-RI Co.,Ltd.
|
|
5
|
+
# License:: GPLv3+: GNU General Public License version 3 or later
|
|
6
|
+
#
|
|
7
|
+
# Owner:: Yutaka Yanoh <mailto:yanoh@users.sourceforge.net>
|
|
8
|
+
|
|
9
|
+
#--
|
|
10
|
+
# ___ ____ __ ___ _________
|
|
11
|
+
# / | / _ |/ / / / | / /__ __/ Source Code Static Analyzer
|
|
12
|
+
# / /| | / / / / / / / |/ / / / AdLint - Advanced Lint
|
|
13
|
+
# / __ |/ /_/ / /___/ / /| / / /
|
|
14
|
+
# /_/ |_|_____/_____/_/_/ |_/ /_/ Copyright (C) 2010-2012, OGIS-RI Co.,Ltd.
|
|
15
|
+
#
|
|
16
|
+
# This file is part of AdLint.
|
|
17
|
+
#
|
|
18
|
+
# AdLint is free software: you can redistribute it and/or modify it under the
|
|
19
|
+
# terms of the GNU General Public License as published by the Free Software
|
|
20
|
+
# Foundation, either version 3 of the License, or (at your option) any later
|
|
21
|
+
# version.
|
|
22
|
+
#
|
|
23
|
+
# AdLint is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
24
|
+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
25
|
+
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
26
|
+
#
|
|
27
|
+
# You should have received a copy of the GNU General Public License along with
|
|
28
|
+
# AdLint. If not, see <http://www.gnu.org/licenses/>.
|
|
29
|
+
#
|
|
30
|
+
#++
|
|
31
|
+
|
|
32
|
+
module AdLint #:nodoc:
|
|
33
|
+
module C #:nodoc:
|
|
34
|
+
|
|
35
|
+
# Host class of this module must include InterpreterMediator.
|
|
36
|
+
module Conversion
|
|
37
|
+
def do_conversion(original, to_type)
|
|
38
|
+
if original.type.coercible?(to_type)
|
|
39
|
+
# NOTE: Value will be coerced into the destination type in
|
|
40
|
+
# VariableTableMediator#temporary_variable.
|
|
41
|
+
temporary_variable(to_type, wrap_around_value(original, to_type))
|
|
42
|
+
else
|
|
43
|
+
nil
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def do_integer_promotion(original)
|
|
48
|
+
return original unless original.type.integer?
|
|
49
|
+
|
|
50
|
+
promoted_type = original.type.integer_promoted_type
|
|
51
|
+
if original.type.same_as?(promoted_type)
|
|
52
|
+
original
|
|
53
|
+
else
|
|
54
|
+
do_conversion(original, promoted_type) || original
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def do_usual_arithmetic_conversion(lhs_original, rhs_original)
|
|
59
|
+
if lhs_original.type.pointer? && rhs_original.type.pointer?
|
|
60
|
+
return lhs_original, rhs_original
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
arith_type = lhs_original.type.arithmetic_type_with(rhs_original.type)
|
|
64
|
+
|
|
65
|
+
if lhs_original.type.same_as?(arith_type)
|
|
66
|
+
lhs_converted = lhs_original
|
|
67
|
+
else
|
|
68
|
+
lhs_converted = do_conversion(lhs_original, arith_type) || lhs_original
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
if rhs_original.type.same_as?(arith_type)
|
|
72
|
+
rhs_converted = rhs_original
|
|
73
|
+
else
|
|
74
|
+
rhs_converted = do_conversion(rhs_original, arith_type) || rhs_original
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
return lhs_converted, rhs_converted
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def do_default_argument_promotion(original)
|
|
81
|
+
promoted_type = original.type.argument_promoted_type
|
|
82
|
+
if original.type.same_as?(promoted_type)
|
|
83
|
+
original
|
|
84
|
+
else
|
|
85
|
+
do_conversion(original, promoted_type) || original
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
private
|
|
90
|
+
def wrap_around_value(original, to_type)
|
|
91
|
+
return original.value unless original.type.scalar? && to_type.scalar?
|
|
92
|
+
|
|
93
|
+
case
|
|
94
|
+
when original.type.signed? && to_type.unsigned?
|
|
95
|
+
min = ScalarValue.of(to_type.min_value)
|
|
96
|
+
if (original.value < min).may_be_true?
|
|
97
|
+
return min - original.value + ScalarValue.of(1)
|
|
98
|
+
end
|
|
99
|
+
when original.type.unsigned? && to_type.signed?
|
|
100
|
+
max = ScalarValue.of(to_type.max_value)
|
|
101
|
+
if (original.value > max).may_be_true?
|
|
102
|
+
return max - original.value + ScalarValue.of(1)
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
original.value
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Host class of this module must include StandardTypeCatalogAccessor.
|
|
111
|
+
module UsualArithmeticTypeConversion
|
|
112
|
+
def do_usual_arithmetic_type_conversion(lhs_type, rhs_type)
|
|
113
|
+
# NOTE: The ISO C99 standard saids;
|
|
114
|
+
#
|
|
115
|
+
# 6.3.1.8 Usual arithmetic conversions
|
|
116
|
+
#
|
|
117
|
+
# 1 Many operators that except operands of arithmetic type cause
|
|
118
|
+
# conversions and yield result types in a similar way. The purpose is
|
|
119
|
+
# to determine a common real type for the operands and result. For the
|
|
120
|
+
# specified operands, each operand is converted, without change of type
|
|
121
|
+
# domain, to a type whose corresponding real type is the common real
|
|
122
|
+
# type. Unless explicitly stated otherwise, the common real type is
|
|
123
|
+
# also the corresponding real type of the result, whose type domain is
|
|
124
|
+
# the type domain of the operands if they are the same, and complex
|
|
125
|
+
# otherwise. This pattern is called the usual arithmetic conversions:
|
|
126
|
+
#
|
|
127
|
+
# First, if the corresponding real type of either operand is long
|
|
128
|
+
# double, the other operand is converted, without change of type
|
|
129
|
+
# domain, to a type whose corresponding real type is long double.
|
|
130
|
+
#
|
|
131
|
+
# Otherwise, if the corresponding real type of either operand is
|
|
132
|
+
# double, the other operand is converted, without change of type
|
|
133
|
+
# domain, to a type whose corresponding real type is double.
|
|
134
|
+
#
|
|
135
|
+
# Otherwise, if the corresponding real type of either operand is
|
|
136
|
+
# float, the other operand is converted, without change of type
|
|
137
|
+
# domain, to a type whose corresponding real type is float.
|
|
138
|
+
#
|
|
139
|
+
# Otherwise, the integer promotions are performed on both operands.
|
|
140
|
+
# Then the following rules are applied to the promoted operands:
|
|
141
|
+
#
|
|
142
|
+
# If both operands have the same type, then no further conversion
|
|
143
|
+
# is needed.
|
|
144
|
+
#
|
|
145
|
+
# Otherwise, if both operands have signed integer types or both
|
|
146
|
+
# have unsigned integer types, the operand with the type of lesser
|
|
147
|
+
# integer conversion rank is converted to the type of the operand
|
|
148
|
+
# with greater rank.
|
|
149
|
+
#
|
|
150
|
+
# Otherwise, if the operand that has unsigned integer type has rank
|
|
151
|
+
# greater or equal to the rank of the type of the other operand,
|
|
152
|
+
# then the operand with signed integer type is converted to the
|
|
153
|
+
# type of the operand with unsigned integer type.
|
|
154
|
+
#
|
|
155
|
+
# Otherwise, if the type of the operand with signed integer type
|
|
156
|
+
# can represent all of the values of the type of the operand with
|
|
157
|
+
# unsigned integer type, then the operand with unsigned integer
|
|
158
|
+
# type is converted to the type of the operand with signed integer
|
|
159
|
+
# type.
|
|
160
|
+
#
|
|
161
|
+
# Otherwise, both operands are converted to the unsigned integer
|
|
162
|
+
# type corresponding to the type of the operand with signed integer
|
|
163
|
+
# type.
|
|
164
|
+
|
|
165
|
+
if lhs_type.same_as?(long_double_type) ||
|
|
166
|
+
rhs_type.same_as?(long_double_type)
|
|
167
|
+
return long_double_type
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
if lhs_type.same_as?(double_type) || rhs_type.same_as?(double_type)
|
|
171
|
+
return double_type
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
if lhs_type.same_as?(float_type) || rhs_type.same_as?(float_type)
|
|
175
|
+
return float_type
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
lhs_promoted_type = lhs_type.integer_promoted_type
|
|
179
|
+
rhs_promoted_type = rhs_type.integer_promoted_type
|
|
180
|
+
|
|
181
|
+
return lhs_promoted_type if lhs_promoted_type.same_as?(rhs_promoted_type)
|
|
182
|
+
|
|
183
|
+
lhs_rank = lhs_promoted_type.integer_conversion_rank
|
|
184
|
+
rhs_rank = rhs_promoted_type.integer_conversion_rank
|
|
185
|
+
|
|
186
|
+
case
|
|
187
|
+
when lhs_promoted_type.signed? && rhs_promoted_type.signed?
|
|
188
|
+
return lhs_rank < rhs_rank ? rhs_promoted_type : lhs_promoted_type
|
|
189
|
+
when lhs_promoted_type.unsigned? && rhs_promoted_type.unsigned?
|
|
190
|
+
return lhs_rank < rhs_rank ? rhs_promoted_type : lhs_promoted_type
|
|
191
|
+
when lhs_promoted_type.unsigned? && lhs_rank >= rhs_rank
|
|
192
|
+
return lhs_promoted_type
|
|
193
|
+
when rhs_promoted_type.unsigned? && lhs_rank <= rhs_rank
|
|
194
|
+
return rhs_promoted_type
|
|
195
|
+
when lhs_promoted_type.signed? &&
|
|
196
|
+
rhs_promoted_type.compatible?(lhs_promoted_type)
|
|
197
|
+
return lhs_promoted_type
|
|
198
|
+
when rhs_promoted_type.signed? &&
|
|
199
|
+
lhs_promoted_type.compatible?(rhs_promoted_type)
|
|
200
|
+
return rhs_promoted_type
|
|
201
|
+
when lhs_promoted_type.signed?
|
|
202
|
+
return lhs_promoted_type.corresponding_unsigned_type
|
|
203
|
+
when rhs_promoted_type.signed?
|
|
204
|
+
return rhs_promoted_type.corresponding_unsigned_type
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
raise TypeError, "cannot do usual arithmetic conversion."
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
end
|
|
212
|
+
end
|